Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2012 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | #include "SkOpContour.h" |
michael@0 | 8 | #include "SkPath.h" |
michael@0 | 9 | |
michael@0 | 10 | #ifdef SK_DEBUG |
michael@0 | 11 | #include "SkPathOpsPoint.h" |
michael@0 | 12 | #endif |
michael@0 | 13 | |
michael@0 | 14 | class SkIntersectionHelper { |
michael@0 | 15 | public: |
michael@0 | 16 | enum SegmentType { |
michael@0 | 17 | kHorizontalLine_Segment = -1, |
michael@0 | 18 | kVerticalLine_Segment = 0, |
michael@0 | 19 | kLine_Segment = SkPath::kLine_Verb, |
michael@0 | 20 | kQuad_Segment = SkPath::kQuad_Verb, |
michael@0 | 21 | kCubic_Segment = SkPath::kCubic_Verb, |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | bool addCoincident(SkIntersectionHelper& other, const SkIntersections& ts, bool swap) { |
michael@0 | 25 | return fContour->addCoincident(fIndex, other.fContour, other.fIndex, ts, swap); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | // FIXME: does it make sense to write otherIndex now if we're going to |
michael@0 | 29 | // fix it up later? |
michael@0 | 30 | void addOtherT(int index, double otherT, int otherIndex) { |
michael@0 | 31 | fContour->addOtherT(fIndex, index, otherT, otherIndex); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | bool addPartialCoincident(SkIntersectionHelper& other, const SkIntersections& ts, int index, |
michael@0 | 35 | bool swap) { |
michael@0 | 36 | return fContour->addPartialCoincident(fIndex, other.fContour, other.fIndex, ts, index, |
michael@0 | 37 | swap); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | // Avoid collapsing t values that are close to the same since |
michael@0 | 41 | // we walk ts to describe consecutive intersections. Since a pair of ts can |
michael@0 | 42 | // be nearly equal, any problems caused by this should be taken care |
michael@0 | 43 | // of later. |
michael@0 | 44 | // On the edge or out of range values are negative; add 2 to get end |
michael@0 | 45 | int addT(const SkIntersectionHelper& other, const SkPoint& pt, double newT) { |
michael@0 | 46 | return fContour->addT(fIndex, other.fContour, other.fIndex, pt, newT); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | int addSelfT(const SkIntersectionHelper& other, const SkPoint& pt, double newT) { |
michael@0 | 50 | return fContour->addSelfT(fIndex, other.fContour, other.fIndex, pt, newT); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | bool advance() { |
michael@0 | 54 | return ++fIndex < fLast; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | SkScalar bottom() const { |
michael@0 | 58 | return bounds().fBottom; |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | const SkPathOpsBounds& bounds() const { |
michael@0 | 62 | return fContour->segments()[fIndex].bounds(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | void init(SkOpContour* contour) { |
michael@0 | 66 | fContour = contour; |
michael@0 | 67 | fIndex = 0; |
michael@0 | 68 | fLast = contour->segments().count(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | bool isAdjacent(const SkIntersectionHelper& next) { |
michael@0 | 72 | return fContour == next.fContour && fIndex + 1 == next.fIndex; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | bool isFirstLast(const SkIntersectionHelper& next) { |
michael@0 | 76 | return fContour == next.fContour && fIndex == 0 |
michael@0 | 77 | && next.fIndex == fLast - 1; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | bool isPartial(double t1, double t2, const SkDPoint& pt1, const SkDPoint& pt2) const { |
michael@0 | 81 | const SkOpSegment& segment = fContour->segments()[fIndex]; |
michael@0 | 82 | double mid = (t1 + t2) / 2; |
michael@0 | 83 | SkDPoint midPtByT = segment.dPtAtT(mid); |
michael@0 | 84 | SkDPoint midPtByAvg = SkDPoint::Mid(pt1, pt2); |
michael@0 | 85 | return midPtByT.approximatelyPEqual(midPtByAvg); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | SkScalar left() const { |
michael@0 | 89 | return bounds().fLeft; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | const SkPoint* pts() const { |
michael@0 | 93 | return fContour->segments()[fIndex].pts(); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | SkScalar right() const { |
michael@0 | 97 | return bounds().fRight; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | SegmentType segmentType() const { |
michael@0 | 101 | const SkOpSegment& segment = fContour->segments()[fIndex]; |
michael@0 | 102 | SegmentType type = (SegmentType) segment.verb(); |
michael@0 | 103 | if (type != kLine_Segment) { |
michael@0 | 104 | return type; |
michael@0 | 105 | } |
michael@0 | 106 | if (segment.isHorizontal()) { |
michael@0 | 107 | return kHorizontalLine_Segment; |
michael@0 | 108 | } |
michael@0 | 109 | if (segment.isVertical()) { |
michael@0 | 110 | return kVerticalLine_Segment; |
michael@0 | 111 | } |
michael@0 | 112 | return kLine_Segment; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | bool startAfter(const SkIntersectionHelper& after) { |
michael@0 | 116 | fIndex = after.fIndex; |
michael@0 | 117 | return advance(); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | SkScalar top() const { |
michael@0 | 121 | return bounds().fTop; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | SkPath::Verb verb() const { |
michael@0 | 125 | return fContour->segments()[fIndex].verb(); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | SkScalar x() const { |
michael@0 | 129 | return bounds().fLeft; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | bool xFlipped() const { |
michael@0 | 133 | return x() != pts()[0].fX; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | SkScalar y() const { |
michael@0 | 137 | return bounds().fTop; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | bool yFlipped() const { |
michael@0 | 141 | return y() != pts()[0].fY; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | #ifdef SK_DEBUG |
michael@0 | 145 | void dump() { |
michael@0 | 146 | SkDPoint::dump(pts()[0]); |
michael@0 | 147 | SkDPoint::dump(pts()[1]); |
michael@0 | 148 | if (verb() >= SkPath::kQuad_Verb) { |
michael@0 | 149 | SkDPoint::dump(pts()[2]); |
michael@0 | 150 | } |
michael@0 | 151 | if (verb() >= SkPath::kCubic_Verb) { |
michael@0 | 152 | SkDPoint::dump(pts()[3]); |
michael@0 | 153 | } |
michael@0 | 154 | } |
michael@0 | 155 | #endif |
michael@0 | 156 | |
michael@0 | 157 | private: |
michael@0 | 158 | SkOpContour* fContour; |
michael@0 | 159 | int fIndex; |
michael@0 | 160 | int fLast; |
michael@0 | 161 | }; |