本文整理汇总了C++中SkPoint::equalsWithinTolerance方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPoint::equalsWithinTolerance方法的具体用法?C++ SkPoint::equalsWithinTolerance怎么用?C++ SkPoint::equalsWithinTolerance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPoint
的用法示例。
在下文中一共展示了SkPoint::equalsWithinTolerance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SkInsetConvexPolygon
// The objective here is to inset all of the edges by the given distance, and then
// remove any invalid inset edges by detecting right-hand turns. In a ccw polygon,
// we should only be making left-hand turns (for cw polygons, we use the winding
// parameter to reverse this). We detect this by checking whether the second intersection
// on an edge is closer to its tail than the first one.
//
// We might also have the case that there is no intersection between two neighboring inset edges.
// In this case, one edge will lie to the right of the other and should be discarded along with
// its previous intersection (if any).
//
// Note: the assumption is that inputPolygon is convex and has no coincident points.
//
bool SkInsetConvexPolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
std::function<SkScalar(int index)> insetDistanceFunc,
SkTDArray<SkPoint>* insetPolygon) {
if (inputPolygonSize < 3) {
return false;
}
int winding = get_winding(inputPolygonVerts, inputPolygonSize);
if (0 == winding) {
return false;
}
// set up
struct EdgeData {
InsetSegment fInset;
SkPoint fIntersection;
SkScalar fTValue;
bool fValid;
};
SkAutoSTMalloc<64, EdgeData> edgeData(inputPolygonSize);
for (int i = 0; i < inputPolygonSize; ++i) {
int j = (i + 1) % inputPolygonSize;
SkOffsetSegment(inputPolygonVerts[i], inputPolygonVerts[j],
insetDistanceFunc(i), insetDistanceFunc(j),
winding,
&edgeData[i].fInset.fP0, &edgeData[i].fInset.fP1);
edgeData[i].fIntersection = edgeData[i].fInset.fP0;
edgeData[i].fTValue = SK_ScalarMin;
edgeData[i].fValid = true;
}
int prevIndex = inputPolygonSize - 1;
int currIndex = 0;
int insetVertexCount = inputPolygonSize;
while (prevIndex != currIndex) {
if (!edgeData[prevIndex].fValid) {
prevIndex = (prevIndex + inputPolygonSize - 1) % inputPolygonSize;
continue;
}
SkScalar s, t;
SkPoint intersection;
if (compute_intersection(edgeData[prevIndex].fInset, edgeData[currIndex].fInset,
&intersection, &s, &t)) {
// if new intersection is further back on previous inset from the prior intersection
if (s < edgeData[prevIndex].fTValue) {
// no point in considering this one again
edgeData[prevIndex].fValid = false;
--insetVertexCount;
// go back one segment
prevIndex = (prevIndex + inputPolygonSize - 1) % inputPolygonSize;
// we've already considered this intersection, we're done
} else if (edgeData[currIndex].fTValue > SK_ScalarMin &&
intersection.equalsWithinTolerance(edgeData[currIndex].fIntersection,
1.0e-6f)) {
break;
} else {
// add intersection
edgeData[currIndex].fIntersection = intersection;
edgeData[currIndex].fTValue = t;
// go to next segment
prevIndex = currIndex;
currIndex = (currIndex + 1) % inputPolygonSize;
}
} else {
// if prev to right side of curr
int side = winding*compute_side(edgeData[currIndex].fInset.fP0,
edgeData[currIndex].fInset.fP1,
edgeData[prevIndex].fInset.fP1);
if (side < 0 && side == winding*compute_side(edgeData[currIndex].fInset.fP0,
edgeData[currIndex].fInset.fP1,
edgeData[prevIndex].fInset.fP0)) {
// no point in considering this one again
edgeData[prevIndex].fValid = false;
--insetVertexCount;
// go back one segment
prevIndex = (prevIndex + inputPolygonSize - 1) % inputPolygonSize;
} else {
// move to next segment
edgeData[currIndex].fValid = false;
--insetVertexCount;
currIndex = (currIndex + 1) % inputPolygonSize;
}
}
}
//.........这里部分代码省略.........