17void SkIntersections::cleanUpParallelLines(
bool parallel) {
21 if (fUsed == 2 && !parallel) {
22 bool startMatch = fT[0][0] == 0 ||
zero_or_one(fT[1][0]);
23 bool endMatch = fT[0][1] == 1 ||
zero_or_one(fT[1][1]);
26 if (startMatch && endMatch && (fT[0][0] != 0 || !
zero_or_one(fT[1][0]))
35 fIsCoincident[0] = fIsCoincident[1] = 0x03;
39void SkIntersections::computePoints(
const SkDLine&
line,
int used) {
40 fPt[0] =
line.ptAtT(fT[0][0]);
41 if ((fUsed =
used) == 2) {
42 fPt[1] =
line.ptAtT(fT[0][1]);
56 double denom = bLen.
fY * aLen.
fX - aLen.
fY * bLen.
fX;
60 double numerA = ab0.
fY * bLen.
fX - bLen.
fY * ab0.
fX;
61 double numerB = ab0.
fY * aLen.
fX - aLen.
fY * ab0.
fX;
74 aLen.
fX *
b[0].fY - aLen.
fY *
b[0].fX)) {
78 fT[0][0] = fT[1][0] = 0;
79 fT[1][0] = fT[1][1] = 1;
82 computePoints(
a,
used);
91 for (
int iA = 0; iA < 2; ++iA) {
92 if ((t =
b.exactPoint(
a[iA])) >= 0) {
96 for (
int iB = 0; iB < 2; ++iB) {
97 if ((t =
a.exactPoint(
b[iB])) >= 0) {
104 double axLen =
a[1].fX -
a[0].fX;
105 double ayLen =
a[1].fY -
a[0].fY;
106 double bxLen =
b[1].fX -
b[0].fX;
107 double byLen =
b[1].fY -
b[0].fY;
114 double axByLen = axLen * byLen;
115 double ayBxLen = ayLen * bxLen;
120 if (unparallel && fUsed == 0) {
121 double ab0y =
a[0].fY -
b[0].fY;
122 double ab0x =
a[0].fX -
b[0].fX;
123 double numerA = ab0y * bxLen - byLen * ab0x;
124 double numerB = ab0y * axLen - ayLen * ab0x;
125 double denom = axByLen - ayBxLen;
127 fT[0][0] = numerA / denom;
128 fT[1][0] = numerB / denom;
138 if (fAllowNear || !unparallel) {
141 bool aNotB[2] = {
false,
false};
142 bool bNotA[2] = {
false,
false};
144 for (
int index = 0; index < 2; ++index) {
145 aNearB[index] = t =
b.nearPoint(
a[index], &aNotB[index]);
147 bNearA[index] = t =
a.nearPoint(
b[index], &bNotA[index]);
152 if (nearCount != 2 || aNotB[0] == aNotB[1]) {
153 for (
int iA = 0; iA < 2; ++iA) {
157 int nearer = aNearB[iA] > 0.5;
158 if (!bNotA[nearer]) {
170 for (
int iA = 0; iA < 2; ++iA) {
171 if (aNearB[iA] >= 0) {
175 for (
int iB = 0; iB < 2; ++iB) {
176 if (bNearA[iB] >= 0) {
183 cleanUpParallelLines(!unparallel);
210 double y,
bool flipped) {
215 if ((t =
line.exactPoint(leftPt)) >= 0) {
216 insert(t, (
double) flipped, leftPt);
220 if ((t =
line.exactPoint(rightPt)) >= 0) {
221 insert(t, (
double) !flipped, rightPt);
223 for (
int index = 0; index < 2; ++index) {
225 insert((
double) index, flipped ? 1 - t : t,
line[index]);
230 if (
result == 1 && fUsed == 0) {
232 double xIntercept =
line[0].fX + fT[0][0] * (
line[1].fX -
line[0].fX);
237 for (
int index = 0; index <
result; ++index) {
238 fT[1][index] = 1 - fT[1][index];
241 fPt[0].
fX = xIntercept;
246 if (fAllowNear ||
result == 2) {
247 if ((t =
line.nearPoint(leftPt,
nullptr)) >= 0) {
248 insert(t, (
double) flipped, leftPt);
252 if ((t =
line.nearPoint(rightPt,
nullptr)) >= 0) {
253 insert(t, (
double) !flipped, rightPt);
255 for (
int index = 0; index < 2; ++index) {
257 insert((
double) index, flipped ? 1 - t : t,
line[index]);
262 cleanUpParallelLines(
result == 2);
288 double x,
bool flipped) {
293 if ((t =
line.exactPoint(topPt)) >= 0) {
294 insert(t, (
double) flipped, topPt);
298 if ((t =
line.exactPoint(bottomPt)) >= 0) {
299 insert(t, (
double) !flipped, bottomPt);
301 for (
int index = 0; index < 2; ++index) {
303 insert((
double) index, flipped ? 1 - t : t,
line[index]);
308 if (
result == 1 && fUsed == 0) {
310 double yIntercept =
line[0].fY + fT[0][0] * (
line[1].fY -
line[0].fY);
311 if (
between(top, yIntercept, bottom)) {
312 fT[1][0] = (yIntercept - top) / (bottom - top);
315 for (
int index = 0; index <
result; ++index) {
316 fT[1][index] = 1 - fT[1][index];
320 fPt[0].
fY = yIntercept;
324 if (fAllowNear ||
result == 2) {
325 if ((t =
line.nearPoint(topPt,
nullptr)) >= 0) {
326 insert(t, (
double) flipped, topPt);
330 if ((t =
line.nearPoint(bottomPt,
nullptr)) >= 0) {
331 insert(t, (
double) !flipped, bottomPt);
333 for (
int index = 0; index < 2; ++index) {
335 insert((
double) index, flipped ? 1 - t : t,
line[index]);
340 cleanUpParallelLines(
result == 2);
static bool approximately_zero(double x)
static int horizontal_coincident(const SkDLine &line, double y)
static int vertical_coincident(const SkDLine &line, double x)
bool AlmostEqualUlps(const SkPoint &pt1, const SkPoint &pt2)
bool NotAlmostEqualUlps_Pin(float a, float b)
bool NotAlmostDequalUlps(float a, float b)
bool approximately_equal(double x, double y)
bool between(double a, double b, double c)
bool precisely_between(double a, double b, double c)
bool zero_or_one(double x)
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
void swap(sk_sp< T > &a, sk_sp< T > &b)
int intersectRay(const SkDLine &, const SkDLine &)
int insert(double one, double two, const SkDPoint &pt)
int intersect(const SkDLine &, const SkDLine &)
void removeOne(int index)
void insertNear(double one, double two, const SkDPoint &pt1, const SkDPoint &pt2)
static double VerticalIntercept(const SkDLine &line, double x)
int vertical(const SkDLine &, double top, double bottom, double x, bool flipped)
static double HorizontalIntercept(const SkDLine &line, double y)
int horizontal(const SkDLine &, double left, double right, double y, bool flipped)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
static double ExactPointV(const SkDPoint &xy, double top, double bottom, double x)
static double NearPointH(const SkDPoint &xy, double left, double right, double y)
static double NearPointV(const SkDPoint &xy, double top, double bottom, double x)
static double ExactPointH(const SkDPoint &xy, double left, double right, double y)