/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"PolygonTestUtils.h"
#include <cmath>
#include"Point.h" #include"Triangle.h"
typedef mozilla::gfx::Polygon MozPolygon;
using mozilla::gfx::Point; using mozilla::gfx::Point4D; using mozilla::gfx::Triangle;
namespace mozilla { namespace gfx {
constfloat kEpsilon = 0.001f;
// Compares two points while allowing some numerical inaccuracy. bool FuzzyEquals(const Point4D& lhs, const Point4D& rhs) { constauto d = lhs - rhs;
// Compares the points of two polygons and ensures // that the points are in the same winding order. booloperator==(const MozPolygon& lhs, const MozPolygon& rhs) { constauto& left = lhs.GetPoints(); constauto& right = rhs.GetPoints();
// Polygons do not have the same amount of points. if (left.Length() != right.Length()) { returnfalse;
}
const size_t pointCount = left.Length();
// Find the first vertex of the first polygon from the second polygon. // This assumes that the polygons do not contain duplicate vertices. int start = -1; for (size_t i = 0; i < pointCount; ++i) { if (FuzzyEquals(left[0], right[i])) {
start = i; break;
}
}
// Found at least one different vertex. if (start == -1) { returnfalse;
}
// Verify that the polygons have the same points. for (size_t i = 0; i < pointCount; ++i) {
size_t j = (start + i) % pointCount;
if (!FuzzyEquals(left[i], right[j])) { returnfalse;
}
}
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.
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.