зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1351426 - Part 2: Only use 4D points in gfx::Polygon r=kip
MozReview-Commit-ID: 1osQrpwH0WZ --HG-- extra : rebase_source : 02d9116c0992a4013a9f9b03542c37c2c18a6a28
This commit is contained in:
Родитель
10fab5cf18
Коммит
c17d5105ae
|
@ -77,32 +77,22 @@ class PolygonTyped {
|
|||
public:
|
||||
PolygonTyped() {}
|
||||
|
||||
explicit PolygonTyped(const std::initializer_list<Point3DType>& aPoints)
|
||||
: mNormal(DefaultNormal()),
|
||||
mPoints(ToPoints4D(nsTArray<Point3DType>(aPoints)))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
EnsurePlanarPolygon();
|
||||
#endif
|
||||
}
|
||||
|
||||
explicit PolygonTyped(const nsTArray<Point3DType>& aPoints)
|
||||
: mNormal(DefaultNormal()), mPoints(ToPoints4D(aPoints))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
EnsurePlanarPolygon();
|
||||
#endif
|
||||
}
|
||||
|
||||
explicit PolygonTyped(const nsTArray<Point4DType>& aPoints,
|
||||
const Point4DType& aNormal = DefaultNormal())
|
||||
: mNormal(aNormal), mPoints(aPoints)
|
||||
{}
|
||||
: mNormal(aNormal), mPoints(aPoints) {}
|
||||
|
||||
explicit PolygonTyped(nsTArray<Point4DType>&& aPoints,
|
||||
const Point4DType& aNormal = DefaultNormal())
|
||||
: mNormal(aNormal), mPoints(Move(aPoints))
|
||||
{}
|
||||
: mNormal(aNormal), mPoints(Move(aPoints)) {}
|
||||
|
||||
explicit PolygonTyped(const std::initializer_list<Point4DType>& aPoints,
|
||||
const Point4DType& aNormal = DefaultNormal())
|
||||
: mNormal(aNormal), mPoints(aPoints)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
EnsurePlanarPolygon();
|
||||
#endif
|
||||
}
|
||||
|
||||
RectTyped<Units> BoundingBox() const
|
||||
{
|
||||
|
@ -199,12 +189,14 @@ public:
|
|||
|
||||
static PolygonTyped<Units> FromRect(const RectTyped<Units>& aRect)
|
||||
{
|
||||
return PolygonTyped<Units> {
|
||||
Point3DType(aRect.x, aRect.y, 0.0f),
|
||||
Point3DType(aRect.x, aRect.y + aRect.height, 0.0f),
|
||||
Point3DType(aRect.x + aRect.width, aRect.y + aRect.height, 0.0f),
|
||||
Point3DType(aRect.x + aRect.width, aRect.y, 0.0f)
|
||||
nsTArray<Point4DType> points {
|
||||
Point4DType(aRect.x, aRect.y, 0.0f, 1.0f),
|
||||
Point4DType(aRect.x, aRect.YMost(), 0.0f, 1.0f),
|
||||
Point4DType(aRect.XMost(), aRect.YMost(), 0.0f, 1.0f),
|
||||
Point4DType(aRect.XMost(), aRect.y, 0.0f, 1.0f)
|
||||
};
|
||||
|
||||
return PolygonTyped<Units>(Move(points));
|
||||
}
|
||||
|
||||
const Point4DType& GetNormal() const
|
||||
|
|
|
@ -96,48 +96,48 @@ bool operator==(const MozPolygon& lhs, const MozPolygon& rhs)
|
|||
|
||||
TEST(PolygonTestUtils, TestSanity)
|
||||
{
|
||||
EXPECT_TRUE(FuzzyEquals(Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 0.0f, 0.0f)));
|
||||
EXPECT_TRUE(FuzzyEquals(Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f)));
|
||||
|
||||
EXPECT_TRUE(FuzzyEquals(Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.00001f, 0.00001f, 0.00001f)));
|
||||
EXPECT_TRUE(FuzzyEquals(Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.00001f, 0.00001f, 0.00001f, 1.0f)));
|
||||
|
||||
EXPECT_TRUE(FuzzyEquals(Point3D(0.00001f, 0.00001f, 0.00001f),
|
||||
Point3D(0.0f, 0.0f, 0.0f)));
|
||||
EXPECT_TRUE(FuzzyEquals(Point4D(0.00001f, 0.00001f, 0.00001f, 1.0f),
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f)));
|
||||
|
||||
EXPECT_FALSE(FuzzyEquals(Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.01f, 0.01f, 0.01f)));
|
||||
EXPECT_FALSE(FuzzyEquals(Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.01f, 0.01f, 0.01f, 1.0f)));
|
||||
|
||||
EXPECT_FALSE(FuzzyEquals(Point3D(0.01f, 0.01f, 0.01f),
|
||||
Point3D(0.0f, 0.0f, 0.0f)));
|
||||
EXPECT_FALSE(FuzzyEquals(Point4D(0.01f, 0.01f, 0.01f, 1.0f),
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f)));
|
||||
|
||||
MozPolygon p1 {
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f)
|
||||
Point4D(0.0f, 0.0f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 0.0f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
Point4D(0.0f, 1.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
// Same points as above shifted forward by one position.
|
||||
MozPolygon shifted {
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f)
|
||||
Point4D(0.0f, 1.0f, 1.0f, 1.0f),
|
||||
Point4D(0.0f, 0.0f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 0.0f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
MozPolygon p2 {
|
||||
Point3D(0.00001f, 0.00001f, 1.00001f),
|
||||
Point3D(1.00001f, 0.00001f, 1.00001f),
|
||||
Point3D(1.00001f, 1.00001f, 1.00001f),
|
||||
Point3D(0.00001f, 1.00001f, 1.00001f)
|
||||
Point4D(0.00001f, 0.00001f, 1.00001f, 1.0f),
|
||||
Point4D(1.00001f, 0.00001f, 1.00001f, 1.0f),
|
||||
Point4D(1.00001f, 1.00001f, 1.00001f, 1.0f),
|
||||
Point4D(0.00001f, 1.00001f, 1.00001f, 1.0f)
|
||||
};
|
||||
|
||||
MozPolygon p3 {
|
||||
Point3D(0.01f, 0.01f, 1.01f),
|
||||
Point3D(1.01f, 0.01f, 1.01f),
|
||||
Point3D(1.01f, 1.01f, 1.01f),
|
||||
Point3D(0.01f, 1.01f, 1.01f)
|
||||
Point4D(0.01f, 0.01f, 1.01f, 1.0f),
|
||||
Point4D(1.01f, 0.01f, 1.01f, 1.0f),
|
||||
Point4D(1.01f, 1.01f, 1.01f, 1.0f),
|
||||
Point4D(0.01f, 1.01f, 1.01f, 1.0f)
|
||||
};
|
||||
|
||||
// Trivial equals
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -18,10 +18,10 @@ typedef mozilla::gfx::Polygon MozPolygon;
|
|||
TEST(MozPolygon, TriangulateRectangle)
|
||||
{
|
||||
const MozPolygon p {
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 0.0f, 1.0f)
|
||||
Point4D(0.0f, 0.0f, 1.0f, 1.0f),
|
||||
Point4D(0.0f, 1.0f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 0.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
const nsTArray<Triangle> triangles = p.ToTriangles();
|
||||
|
@ -36,11 +36,11 @@ TEST(MozPolygon, TriangulateRectangle)
|
|||
TEST(MozPolygon, TriangulatePentagon)
|
||||
{
|
||||
const MozPolygon p {
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(0.5f, 1.5f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 0.0f, 1.0f)
|
||||
Point4D(0.0f, 0.0f, 1.0f, 1.0f),
|
||||
Point4D(0.0f, 1.0f, 1.0f, 1.0f),
|
||||
Point4D(0.5f, 1.5f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
Point4D(1.0f, 0.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
const nsTArray<Triangle> triangles = p.ToTriangles();
|
||||
|
@ -65,34 +65,34 @@ TestClipRect(const MozPolygon& aPolygon,
|
|||
TEST(MozPolygon, ClipRectangle)
|
||||
{
|
||||
MozPolygon polygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 0.0f, 0.0f)
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.0f, 1.0f, 0.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 0.0f, 1.0f),
|
||||
Point4D(1.0f, 0.0f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, polygon, Rect(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
|
||||
MozPolygon expected = MozPolygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.0f, 0.0f)
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.0f, 0.8f, 0.0f, 1.0f),
|
||||
Point4D(0.8f, 0.8f, 0.0f, 1.0f),
|
||||
Point4D(0.8f, 0.0f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, expected, Rect(0.0f, 0.0f, 0.8f, 0.8f));
|
||||
|
||||
expected = MozPolygon {
|
||||
Point3D(0.2f, 0.2f, 0.0f),
|
||||
Point3D(0.2f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 0.2f, 0.0f)
|
||||
Point4D(0.2f, 0.2f, 0.0f, 1.0f),
|
||||
Point4D(0.2f, 1.0f, 0.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 0.0f, 1.0f),
|
||||
Point4D(1.0f, 0.2f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.8f, 0.8f));
|
||||
|
||||
expected = MozPolygon {
|
||||
Point3D(0.2f, 0.2f, 0.0f),
|
||||
Point3D(0.2f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.2f, 0.0f)
|
||||
Point4D(0.2f, 0.2f, 0.0f, 1.0f),
|
||||
Point4D(0.2f, 0.8f, 0.0f, 1.0f),
|
||||
Point4D(0.8f, 0.8f, 0.0f, 1.0f),
|
||||
Point4D(0.8f, 0.2f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.6f, 0.6f));
|
||||
}
|
||||
|
@ -101,36 +101,36 @@ TEST(MozPolygon, ClipTriangle)
|
|||
{
|
||||
MozPolygon clipped, expected;
|
||||
const MozPolygon polygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f)
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.0f, 1.0f, 0.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 0.0f, 1.0f)
|
||||
};
|
||||
|
||||
expected = MozPolygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f)
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.0f, 1.0f, 0.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, expected, Rect(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
|
||||
expected = MozPolygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.8f, 0.0f)
|
||||
Point4D(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
Point4D(0.0f, 0.8f, 0.0f, 1.0f),
|
||||
Point4D(0.8f, 0.8f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, expected, Rect(0.0f, 0.0f, 0.8f, 0.8f));
|
||||
|
||||
expected = MozPolygon {
|
||||
Point3D(0.2f, 0.2f, 0.0f),
|
||||
Point3D(0.2f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f)
|
||||
Point4D(0.2f, 0.2f, 0.0f, 1.0f),
|
||||
Point4D(0.2f, 1.0f, 0.0f, 1.0f),
|
||||
Point4D(1.0f, 1.0f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.8f, 0.8f));
|
||||
|
||||
expected = MozPolygon {
|
||||
Point3D(0.2f, 0.2f, 0.0f),
|
||||
Point3D(0.2f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.8f, 0.0f)
|
||||
Point4D(0.2f, 0.2f, 0.0f, 1.0f),
|
||||
Point4D(0.2f, 0.8f, 0.0f, 1.0f),
|
||||
Point4D(0.8f, 0.8f, 0.0f, 1.0f)
|
||||
};
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.6f, 0.6f));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче