DEF_TEST(PathOpsDPoint, reporter) { for (size_t index = 0; index < tests_count; ++index) { const SkDPoint& pt = tests[index]; SkASSERT(ValidPoint(pt)); SkDPoint p = pt; REPORTER_ASSERT(reporter, p == pt); REPORTER_ASSERT(reporter, !(pt != pt)); SkDVector v = p - pt; p += v; REPORTER_ASSERT(reporter, p == pt); p -= v; REPORTER_ASSERT(reporter, p == pt); REPORTER_ASSERT(reporter, p.approximatelyEqual(pt)); SkPoint sPt = pt.asSkPoint(); p.set(sPt); REPORTER_ASSERT(reporter, p == pt); REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt)); REPORTER_ASSERT(reporter, p.roughlyEqual(pt)); p.fX = p.fY = 0; REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0); REPORTER_ASSERT(reporter, p.approximatelyZero()); REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY * pt.fY); REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p), sqrt(pt.fX * pt.fX + pt.fY * pt.fY))); } }
int SkIntersections::insert(double one, double two, const SkDPoint& pt) { if (fIsCoincident[0] == 3 && between(fT[0][0], one, fT[0][1])) { // For now, don't allow a mix of coincident and non-coincident intersections return -1; } SkASSERT(fUsed <= 1 || fT[0][0] <= fT[0][1]); int index; for (index = 0; index < fUsed; ++index) { double oldOne = fT[0][index]; double oldTwo = fT[1][index]; if (one == oldOne && two == oldTwo) { return -1; } if (more_roughly_equal(oldOne, one) && more_roughly_equal(oldTwo, two)) { if ((precisely_zero(one) && !precisely_zero(oldOne)) || (precisely_equal(one, 1) && !precisely_equal(oldOne, 1)) || (precisely_zero(two) && !precisely_zero(oldTwo)) || (precisely_equal(two, 1) && !precisely_equal(oldTwo, 1))) { SkASSERT(one >= 0 && one <= 1); SkASSERT(two >= 0 && two <= 1); fT[0][index] = one; fT[1][index] = two; fPt[index] = pt; } return -1; } #if ONE_OFF_DEBUG if (pt.roughlyEqual(fPt[index])) { SkDebugf("%s t=%1.9g pts roughly equal\n", __FUNCTION__, one); } #endif if (fT[0][index] > one) { break; } } if (fUsed >= fMax) { SkASSERT(0); // FIXME : this error, if it is to be handled at runtime in release, must // be propagated all the way back down to the caller, and return failure. fUsed = 0; return 0; } int remaining = fUsed - index; if (remaining > 0) { memmove(&fPt[index + 1], &fPt[index], sizeof(fPt[0]) * remaining); memmove(&fT[0][index + 1], &fT[0][index], sizeof(fT[0][0]) * remaining); memmove(&fT[1][index + 1], &fT[1][index], sizeof(fT[1][0]) * remaining); int clearMask = ~((1 << index) - 1); fIsCoincident[0] += fIsCoincident[0] & clearMask; fIsCoincident[1] += fIsCoincident[1] & clearMask; } fPt[index] = pt; SkASSERT(one >= 0 && one <= 1); SkASSERT(two >= 0 && two <= 1); fT[0][index] = one; fT[1][index] = two; ++fUsed; return index; }