/* * Copyright 2015 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/ #include"src/pathops/SkPathOpsCurve.h"
// this cheats and assumes that the perpendicular to the point is the closest ray to the curve // this case (where the line and the curve are nearly coincident) may be the only case that counts double SkDCurve::nearPoint(SkPath::Verb verb, const SkDPoint& xy, const SkDPoint& opp) const { int count = SkPathOpsVerbToPoints(verb); double minX = fCubic.fPts[0].fX; double maxX = minX; for (int index = 1; index <= count; ++index) {
minX = std::min(minX, fCubic.fPts[index].fX);
maxX = std::max(maxX, fCubic.fPts[index].fX);
} if (!AlmostBetweenUlps(minX, xy.fX, maxX)) { return -1;
} double minY = fCubic.fPts[0].fY; double maxY = minY; for (int index = 1; index <= count; ++index) {
minY = std::min(minY, fCubic.fPts[index].fY);
maxY = std::max(maxY, fCubic.fPts[index].fY);
} if (!AlmostBetweenUlps(minY, xy.fY, maxY)) { return -1;
}
SkIntersections i;
SkDLine perp = {{ xy, { xy.fX + opp.fY - xy.fY, xy.fY + xy.fX - opp.fX }}};
(*CurveDIntersectRay[verb])(*this, perp, &i); int minIndex = -1; double minDist = FLT_MAX; for (int index = 0; index < i.used(); ++index) { double dist = xy.distance(i.pt(index)); if (minDist > dist) {
minDist = dist;
minIndex = index;
}
} if (minIndex < 0) { return -1;
} double largest = std::max(std::max(maxX, maxY), -std::min(minX, minY)); if (!AlmostEqualUlps_Pin(largest, largest + minDist)) { // is distance within ULPS tolerance? return -1;
} return SkPinT(i[0][minIndex]);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.