mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-12 18:50:08 +00:00
Bug 1274673 - Use binary space partitioning for sorting/drawing layers - Part 2: Rename Polygon3D to Polygon, and use 4D points for all calculations r=kip
MozReview-Commit-ID: I6DB8xldpjO --HG-- extra : rebase_source : c881f68722404e0d749a00424eb17d284a7383d2
This commit is contained in:
parent
93c8550e72
commit
d8d0459a98
252
gfx/2d/Polygon.h
252
gfx/2d/Polygon.h
@ -17,49 +17,101 @@
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
// Polygon3DTyped stores the points of a convex planar polygon.
|
||||
template<class Units>
|
||||
class Polygon3DTyped {
|
||||
Point4DTyped<Units>
|
||||
CalculateEdgeIntersect(const Point4DTyped<Units>& aFirst,
|
||||
const Point4DTyped<Units>& aSecond)
|
||||
{
|
||||
static const float w = 0.00001f;
|
||||
const float t = (w - aFirst.w) / (aSecond.w - aFirst.w);
|
||||
return aFirst + (aSecond - aFirst) * t;
|
||||
}
|
||||
|
||||
template<class Units>
|
||||
nsTArray<Point4DTyped<Units>>
|
||||
ClipHomogeneous(const nsTArray<Point4DTyped<Units>>& aPoints)
|
||||
{
|
||||
nsTArray<Point4DTyped<Units>> outPoints;
|
||||
|
||||
const size_t pointCount = aPoints.Length();
|
||||
for (size_t i = 0; i < pointCount; ++i) {
|
||||
const Point4DTyped<Units>& first = aPoints[i];
|
||||
const Point4DTyped<Units>& second = aPoints[(i + 1) % pointCount];
|
||||
|
||||
MOZ_ASSERT(first.w != 0.0f || second.w != 0.0f);
|
||||
|
||||
if (first.w > 0.0f) {
|
||||
outPoints.AppendElement(first);
|
||||
}
|
||||
|
||||
if ((first.w <= 0.0f) ^ (second.w <= 0.0f)) {
|
||||
outPoints.AppendElement(CalculateEdgeIntersect(first, second));
|
||||
}
|
||||
}
|
||||
|
||||
return outPoints;
|
||||
}
|
||||
|
||||
template<class Units>
|
||||
nsTArray<Point4DTyped<Units>>
|
||||
ToPoints4D(const nsTArray<Point3DTyped<Units>>& aPoints)
|
||||
{
|
||||
nsTArray<Point4DTyped<Units>> points;
|
||||
|
||||
for (const Point3DTyped<Units>& point : aPoints) {
|
||||
points.AppendElement(Point4DTyped<Units>(point));
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
// PolygonTyped stores the points of a convex planar polygon.
|
||||
template<class Units>
|
||||
class PolygonTyped {
|
||||
typedef Point3DTyped<Units> Point3DType;
|
||||
typedef Point4DTyped<Units> Point4DType;
|
||||
|
||||
public:
|
||||
Polygon3DTyped() {}
|
||||
PolygonTyped() {}
|
||||
|
||||
explicit Polygon3DTyped(const std::initializer_list<Point3DTyped<Units>>& aPoints,
|
||||
Point3DTyped<Units> aNormal =
|
||||
Point3DTyped<Units>(0.0f, 0.0f, 1.0f))
|
||||
: mNormal(aNormal), mPoints(aPoints)
|
||||
explicit PolygonTyped(const std::initializer_list<Point3DType>& aPoints)
|
||||
: mNormal(DefaultNormal()),
|
||||
mPoints(ToPoints4D(nsTArray<Point3DType>(aPoints)))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
EnsurePlanarPolygon();
|
||||
#endif
|
||||
}
|
||||
|
||||
explicit Polygon3DTyped(nsTArray<Point3DTyped<Units>>&& aPoints,
|
||||
Point3DTyped<Units> aNormal =
|
||||
Point3DTyped<Units>(0.0f, 0.0f, 1.0f))
|
||||
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)
|
||||
{}
|
||||
|
||||
explicit PolygonTyped(nsTArray<Point4DType>&& aPoints,
|
||||
const Point4DType& aNormal = DefaultNormal())
|
||||
: mNormal(aNormal), mPoints(Move(aPoints))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
EnsurePlanarPolygon();
|
||||
#endif
|
||||
}
|
||||
|
||||
explicit Polygon3DTyped(const nsTArray<Point3DTyped<Units>>& aPoints,
|
||||
Point3DTyped<Units> aNormal =
|
||||
Point3DTyped<Units>(0.0f, 0.0f, 1.0f))
|
||||
: mNormal(aNormal), mPoints(aPoints)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
EnsurePlanarPolygon();
|
||||
#endif
|
||||
}
|
||||
{}
|
||||
|
||||
RectTyped<Units> BoundingBox() const
|
||||
{
|
||||
if (mPoints.IsEmpty()) {
|
||||
return RectTyped<Units>();
|
||||
}
|
||||
|
||||
float minX, maxX, minY, maxY;
|
||||
minX = maxX = mPoints[0].x;
|
||||
minY = maxY = mPoints[0].y;
|
||||
|
||||
for (const Point3DTyped<Units>& point : mPoints) {
|
||||
for (const Point4DType& point : mPoints) {
|
||||
minX = std::min(point.x, minX);
|
||||
maxX = std::max(point.x, maxX);
|
||||
|
||||
@ -70,21 +122,21 @@ public:
|
||||
return RectTyped<Units>(minX, minY, maxX - minX, maxY - minY);
|
||||
}
|
||||
|
||||
nsTArray<float>
|
||||
CalculateDotProducts(const Polygon3DTyped<Units>& aPlane,
|
||||
size_t& aPos, size_t& aNeg) const
|
||||
nsTArray<float> CalculateDotProducts(const PolygonTyped<Units>& aPlane,
|
||||
size_t& aPos, size_t& aNeg) const
|
||||
{
|
||||
// Point classification might produce incorrect results due to numerical
|
||||
// inaccuracies. Using an epsilon value makes the splitting plane "thicker".
|
||||
const float epsilon = 0.05f;
|
||||
|
||||
MOZ_ASSERT(!aPlane.GetPoints().IsEmpty());
|
||||
const Point3DTyped<Units>& planeNormal = aPlane.GetNormal();
|
||||
const Point3DTyped<Units>& planePoint = aPlane[0];
|
||||
const Point4DType& planeNormal = aPlane.GetNormal();
|
||||
const Point4DType& planePoint = aPlane[0];
|
||||
|
||||
aPos = aNeg = 0;
|
||||
nsTArray<float> dotProducts;
|
||||
for (const Point3DTyped<Units>& point : mPoints) {
|
||||
|
||||
for (const Point4DType& point : mPoints) {
|
||||
float dot = (point - planePoint).DotProduct(planeNormal);
|
||||
|
||||
if (dot > epsilon) {
|
||||
@ -103,45 +155,74 @@ public:
|
||||
}
|
||||
|
||||
// Clips the polygon against the given 2D rectangle.
|
||||
Polygon3DTyped<Units> ClipPolygon(const RectTyped<Units>& aRect) const
|
||||
PolygonTyped<Units> ClipPolygon(const RectTyped<Units>& aRect) const
|
||||
{
|
||||
Polygon3DTyped<Units> polygon(mPoints, mNormal);
|
||||
if (aRect.IsEmpty()) {
|
||||
return PolygonTyped<Units>();
|
||||
}
|
||||
|
||||
// Left edge
|
||||
ClipPolygonWithEdge(polygon, aRect.BottomLeft(), aRect.TopLeft());
|
||||
return ClipPolygon(FromRect(aRect));
|
||||
}
|
||||
|
||||
// Bottom edge
|
||||
ClipPolygonWithEdge(polygon, aRect.BottomRight(), aRect.BottomLeft());
|
||||
// Clips the polygon against the given polygon in 2D.
|
||||
PolygonTyped<Units> ClipPolygon(const PolygonTyped<Units>& aPolygon) const
|
||||
{
|
||||
const nsTArray<Point4DType>& points = aPolygon.GetPoints();
|
||||
|
||||
// Right edge
|
||||
ClipPolygonWithEdge(polygon, aRect.TopRight(), aRect.BottomRight());
|
||||
if (mPoints.IsEmpty() || points.IsEmpty()) {
|
||||
return PolygonTyped<Units>();
|
||||
}
|
||||
|
||||
// Top edge
|
||||
ClipPolygonWithEdge(polygon, aRect.TopLeft(), aRect.TopRight());
|
||||
PolygonTyped<Units> polygon(mPoints, mNormal);
|
||||
|
||||
const size_t pointCount = points.Length();
|
||||
for (size_t i = 0; i < pointCount; ++i) {
|
||||
const Point4DType p1 = points[(i + 1) % pointCount];
|
||||
const Point4DType p2 = points[i];
|
||||
|
||||
const Point4DType normal(p2.y - p1.y, p1.x - p2.x, 0.0f, 0.0f);
|
||||
const PolygonTyped<Units> plane({p1, p2}, normal);
|
||||
|
||||
ClipPolygonWithPlane(polygon, plane);
|
||||
}
|
||||
|
||||
if (polygon.GetPoints().Length() < 3) {
|
||||
return PolygonTyped<Units>();
|
||||
}
|
||||
|
||||
return polygon;
|
||||
}
|
||||
|
||||
const Point3DTyped<Units>& GetNormal() const
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
||||
const Point4DType& GetNormal() const
|
||||
{
|
||||
return mNormal;
|
||||
}
|
||||
|
||||
const nsTArray<Point3DTyped<Units>>& GetPoints() const
|
||||
const nsTArray<Point4DType>& GetPoints() const
|
||||
{
|
||||
return mPoints;
|
||||
}
|
||||
|
||||
const Point3DTyped<Units>& operator[](size_t aIndex) const
|
||||
const Point4DType& operator[](size_t aIndex) const
|
||||
{
|
||||
MOZ_ASSERT(mPoints.Length() > aIndex);
|
||||
return mPoints[aIndex];
|
||||
}
|
||||
|
||||
void SplitPolygon(const Polygon3DTyped<Units>& aSplittingPlane,
|
||||
void SplitPolygon(const Point4DType& aNormal,
|
||||
const nsTArray<float>& aDots,
|
||||
nsTArray<Point3DTyped<Units>>& aBackPoints,
|
||||
nsTArray<Point3DTyped<Units>>& aFrontPoints) const
|
||||
nsTArray<Point4DType>& aBackPoints,
|
||||
nsTArray<Point4DType>& aFrontPoints) const
|
||||
{
|
||||
static const auto Sign = [](const float& f) {
|
||||
if (f > 0.0f) return 1;
|
||||
@ -149,14 +230,12 @@ public:
|
||||
return 0;
|
||||
};
|
||||
|
||||
const Point3DTyped<Units>& normal = aSplittingPlane.GetNormal();
|
||||
const size_t pointCount = mPoints.Length();
|
||||
|
||||
for (size_t i = 0; i < pointCount; ++i) {
|
||||
size_t j = (i + 1) % pointCount;
|
||||
|
||||
const Point3DTyped<Units>& a = mPoints[i];
|
||||
const Point3DTyped<Units>& b = mPoints[j];
|
||||
const Point4DType& a = mPoints[i];
|
||||
const Point4DType& b = mPoints[j];
|
||||
const float dotA = aDots[i];
|
||||
const float dotB = aDots[j];
|
||||
|
||||
@ -175,10 +254,10 @@ public:
|
||||
// The case where the polygon edge is within the plane is handled above.
|
||||
if (Sign(dotA) && Sign(dotB) && Sign(dotA) != Sign(dotB)) {
|
||||
// Calculate the line segment and plane intersection point.
|
||||
const Point3DTyped<Units> ab = b - a;
|
||||
const float dotAB = ab.DotProduct(normal);
|
||||
const Point4DType ab = b - a;
|
||||
const float dotAB = ab.DotProduct(aNormal);
|
||||
const float t = -dotA / dotAB;
|
||||
const Point3DTyped<Units> p = a + (ab * t);
|
||||
const Point4DType p = a + (ab * t);
|
||||
|
||||
// Add the intersection point to both polygons.
|
||||
aBackPoints.AppendElement(p);
|
||||
@ -207,36 +286,37 @@ public:
|
||||
|
||||
void TransformToLayerSpace(const Matrix4x4Typed<Units, Units>& aTransform)
|
||||
{
|
||||
TransformPoints(aTransform);
|
||||
mNormal = Point3DTyped<Units>(0.0f, 0.0f, 1.0f);
|
||||
TransformPoints(aTransform, true);
|
||||
mNormal = DefaultNormal();
|
||||
}
|
||||
|
||||
void TransformToScreenSpace(const Matrix4x4Typed<Units, Units>& aTransform)
|
||||
{
|
||||
TransformPoints(aTransform);
|
||||
TransformPoints(aTransform, false);
|
||||
mPoints = ClipHomogeneous(mPoints);
|
||||
|
||||
// Normal vectors should be transformed using inverse transpose.
|
||||
mNormal = aTransform.Inverse().Transpose().TransformPoint(mNormal);
|
||||
}
|
||||
|
||||
private:
|
||||
void ClipPolygonWithEdge(Polygon3DTyped<Units>& aPolygon,
|
||||
const PointTyped<Units>& aFirst,
|
||||
const PointTyped<Units>& aSecond) const
|
||||
void ClipPolygonWithPlane(PolygonTyped<Units>& aPolygon,
|
||||
const PolygonTyped<Units>& aPlane) const
|
||||
{
|
||||
const Point3DTyped<Units> a(aFirst.x, aFirst.y, 0.0f);
|
||||
const Point3DTyped<Units> b(aSecond.x, aSecond.y, 0.0f);
|
||||
const Point3DTyped<Units> normal(b.y - a.y, a.x - b.x, 0.0f);
|
||||
Polygon3DTyped<Units> plane({a, b}, normal);
|
||||
|
||||
size_t pos, neg;
|
||||
nsTArray<float> dots = aPolygon.CalculateDotProducts(plane, pos, neg);
|
||||
const nsTArray<float> dots =
|
||||
aPolygon.CalculateDotProducts(aPlane, pos, neg);
|
||||
|
||||
nsTArray<Point3DTyped<Units>> backPoints, frontPoints;
|
||||
aPolygon.SplitPolygon(plane, dots, backPoints, frontPoints);
|
||||
nsTArray<Point4DType> backPoints, frontPoints;
|
||||
aPolygon.SplitPolygon(aPlane.GetNormal(), dots, backPoints, frontPoints);
|
||||
|
||||
// Only use the points that are behind the clipping plane.
|
||||
aPolygon = Polygon3DTyped<Units>(Move(backPoints), aPolygon.GetNormal());
|
||||
aPolygon = PolygonTyped<Units>(Move(backPoints), aPolygon.GetNormal());
|
||||
}
|
||||
|
||||
static Point4DType DefaultNormal()
|
||||
{
|
||||
return Point4DType(0.0f, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -251,11 +331,14 @@ private:
|
||||
// The resulting normal vector will point towards the viewer when the
|
||||
// polygon has a counter-clockwise winding order from the perspective
|
||||
// of the viewer.
|
||||
Point3DTyped<Units> normal;
|
||||
Point3DType normal;
|
||||
const Point3DType p0 = mPoints[0].As3DPoint();
|
||||
|
||||
for (size_t i = 1; i < mPoints.Length() - 1; ++i) {
|
||||
normal +=
|
||||
(mPoints[i] - mPoints[0]).CrossProduct(mPoints[i + 1] - mPoints[0]);
|
||||
const Point3DType p1 = mPoints[i].As3DPoint();
|
||||
const Point3DType p2 = mPoints[i + 1].As3DPoint();
|
||||
|
||||
normal += (p1 - p0).CrossProduct(p2 - p0);
|
||||
}
|
||||
|
||||
// Ensure that at least one component is greater than zero.
|
||||
@ -263,6 +346,7 @@ private:
|
||||
bool hasNonZeroComponent = std::abs(normal.x) > 0.0f ||
|
||||
std::abs(normal.y) > 0.0f ||
|
||||
std::abs(normal.z) > 0.0f;
|
||||
|
||||
MOZ_ASSERT(hasNonZeroComponent);
|
||||
|
||||
normal.Normalize();
|
||||
@ -270,24 +354,32 @@ private:
|
||||
// Ensure that the polygon is planar.
|
||||
// http://mathworld.wolfram.com/Point-PlaneDistance.html
|
||||
const float epsilon = 0.01f;
|
||||
for (const Point3DTyped<Units>& point : mPoints) {
|
||||
float d = normal.DotProduct(point - mPoints[0]);
|
||||
for (const Point4DType& point : mPoints) {
|
||||
const Point3DType p1 = point.As3DPoint();
|
||||
const float d = normal.DotProduct(p1 - p0);
|
||||
|
||||
MOZ_ASSERT(std::abs(d) < epsilon);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void TransformPoints(const Matrix4x4Typed<Units, Units>& aTransform)
|
||||
|
||||
void TransformPoints(const Matrix4x4Typed<Units, Units>& aTransform,
|
||||
const bool aDivideByW)
|
||||
{
|
||||
for (Point3DTyped<Units>& point : mPoints) {
|
||||
for (Point4DType& point : mPoints) {
|
||||
point = aTransform.TransformPoint(point);
|
||||
|
||||
if (aDivideByW && point.w > 0.0f) {
|
||||
point = point / point.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Point3DTyped<Units> mNormal;
|
||||
nsTArray<Point3DTyped<Units>> mPoints;
|
||||
Point4DType mNormal;
|
||||
nsTArray<Point4DType> mPoints;
|
||||
};
|
||||
|
||||
typedef Polygon3DTyped<UnknownUnits> Polygon3D;
|
||||
typedef PolygonTyped<UnknownUnits> Polygon;
|
||||
|
||||
} // namespace gfx
|
||||
} // namespace mozilla
|
||||
|
@ -20,7 +20,7 @@ void
|
||||
BSPTree::BuildDrawOrder(const UniquePtr<BSPTreeNode>& aNode,
|
||||
nsTArray<LayerPolygon>& aLayers) const
|
||||
{
|
||||
const gfx::Point3D& normal = aNode->First().GetNormal();
|
||||
const gfx::Point4D& normal = aNode->First().GetNormal();
|
||||
|
||||
UniquePtr<BSPTreeNode> *front = &aNode->front;
|
||||
UniquePtr<BSPTreeNode> *back = &aNode->back;
|
||||
@ -58,11 +58,11 @@ BSPTree::BuildTree(UniquePtr<BSPTreeNode>& aRoot,
|
||||
return;
|
||||
}
|
||||
|
||||
const gfx::Polygon3D& plane = aRoot->First();
|
||||
const gfx::Polygon& plane = aRoot->First();
|
||||
std::deque<LayerPolygon> backLayers, frontLayers;
|
||||
|
||||
for (LayerPolygon& layerPolygon : aLayers) {
|
||||
const Maybe<gfx::Polygon3D>& geometry = layerPolygon.geometry;
|
||||
const Maybe<gfx::Polygon>& geometry = layerPolygon.geometry;
|
||||
|
||||
size_t pos = 0, neg = 0;
|
||||
nsTArray<float> dots = geometry->CalculateDotProducts(plane, pos, neg);
|
||||
@ -81,14 +81,19 @@ BSPTree::BuildTree(UniquePtr<BSPTreeNode>& aRoot,
|
||||
}
|
||||
// Polygon intersects with the splitting plane.
|
||||
else if (pos > 0 && neg > 0) {
|
||||
nsTArray<gfx::Point3D> backPoints, frontPoints;
|
||||
geometry->SplitPolygon(plane, dots, backPoints, frontPoints);
|
||||
nsTArray<gfx::Point4D> backPoints, frontPoints;
|
||||
geometry->SplitPolygon(plane.GetNormal(), dots, backPoints, frontPoints);
|
||||
|
||||
const gfx::Point3D& normal = geometry->GetNormal();
|
||||
const gfx::Point4D& normal = geometry->GetNormal();
|
||||
Layer *layer = layerPolygon.layer;
|
||||
|
||||
backLayers.push_back(LayerPolygon(layer, Move(backPoints), normal));
|
||||
frontLayers.push_back(LayerPolygon(layer, Move(frontPoints), normal));
|
||||
if (backPoints.Length() >= 3) {
|
||||
backLayers.push_back(LayerPolygon(layer, Move(backPoints), normal));
|
||||
}
|
||||
|
||||
if (frontPoints.Length() >= 3) {
|
||||
frontLayers.push_back(LayerPolygon(layer, Move(frontPoints), normal));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,16 @@ struct LayerPolygon {
|
||||
: layer(aLayer) {}
|
||||
|
||||
LayerPolygon(Layer *aLayer,
|
||||
gfx::Polygon3D&& aGeometry)
|
||||
gfx::Polygon&& aGeometry)
|
||||
: layer(aLayer), geometry(Some(aGeometry)) {}
|
||||
|
||||
LayerPolygon(Layer *aLayer,
|
||||
nsTArray<gfx::Point3D>&& aPoints, const gfx::Point3D& aNormal)
|
||||
: layer(aLayer), geometry(Some(gfx::Polygon3D(Move(aPoints), aNormal))) {}
|
||||
nsTArray<gfx::Point4D>&& aPoints,
|
||||
const gfx::Point4D& aNormal)
|
||||
: layer(aLayer), geometry(Some(gfx::Polygon(Move(aPoints), aNormal))) {}
|
||||
|
||||
Layer *layer;
|
||||
Maybe<gfx::Polygon3D> geometry;
|
||||
Maybe<gfx::Polygon> geometry;
|
||||
};
|
||||
|
||||
LayerPolygon PopFront(std::deque<LayerPolygon>& aLayers);
|
||||
@ -46,7 +47,7 @@ struct BSPTreeNode {
|
||||
layers.push_back(Move(layer));
|
||||
}
|
||||
|
||||
const gfx::Polygon3D& First() const
|
||||
const gfx::Polygon& First() const
|
||||
{
|
||||
MOZ_ASSERT(layers[0].geometry);
|
||||
return *layers[0].geometry;
|
||||
|
@ -227,7 +227,7 @@ static void
|
||||
UpdateTextureCoordinates(gfx::TexturedTriangle& aTriangle,
|
||||
const gfx::Rect& aRect,
|
||||
const gfx::Rect& aIntersection,
|
||||
gfx::Rect aTextureCoords)
|
||||
const gfx::Rect& aTextureCoords)
|
||||
{
|
||||
// Calculate the relative offset of the intersection within the layer.
|
||||
float dx = (aIntersection.x - aRect.x) / aRect.width;
|
||||
@ -241,10 +241,8 @@ UpdateTextureCoordinates(gfx::TexturedTriangle& aTriangle,
|
||||
float w = aTextureCoords.width * aIntersection.width / aRect.width;
|
||||
float h = aTextureCoords.height * aIntersection.height / aRect.height;
|
||||
|
||||
static const auto ValidateAndClamp = [](float& f) {
|
||||
// Allow some numerical inaccuracy.
|
||||
MOZ_ASSERT(f >= -0.0001f && f <= 1.0001f);
|
||||
|
||||
static const auto Clamp = [](float& f)
|
||||
{
|
||||
if (f >= 1.0f) f = 1.0f;
|
||||
if (f <= 0.0f) f = 0.0f;
|
||||
};
|
||||
@ -254,8 +252,8 @@ UpdateTextureCoordinates(gfx::TexturedTriangle& aTriangle,
|
||||
t.x = x + (p.x - aIntersection.x) / aIntersection.width * w;
|
||||
t.y = y + (p.y - aIntersection.y) / aIntersection.height * h;
|
||||
|
||||
ValidateAndClamp(t.x);
|
||||
ValidateAndClamp(t.y);
|
||||
Clamp(t.x);
|
||||
Clamp(t.y);
|
||||
};
|
||||
|
||||
UpdatePoint(aTriangle.p1, aTriangle.textureCoords.p1);
|
||||
@ -270,7 +268,7 @@ Compositor::DrawGeometry(const gfx::Rect& aRect,
|
||||
gfx::Float aOpacity,
|
||||
const gfx::Matrix4x4& aTransform,
|
||||
const gfx::Rect& aVisibleRect,
|
||||
const Maybe<gfx::Polygon3D>& aGeometry)
|
||||
const Maybe<gfx::Polygon>& aGeometry)
|
||||
{
|
||||
if (!aGeometry) {
|
||||
DrawQuad(aRect, aClipRect, aEffectChain,
|
||||
@ -283,11 +281,10 @@ Compositor::DrawGeometry(const gfx::Rect& aRect,
|
||||
return;
|
||||
}
|
||||
|
||||
gfx::Polygon3D clipped = aGeometry->ClipPolygon(aRect);
|
||||
nsTArray<gfx::Triangle> triangles = clipped.ToTriangles();
|
||||
const gfx::Polygon clipped = aGeometry->ClipPolygon(aRect);
|
||||
|
||||
for (gfx::Triangle& geometry : triangles) {
|
||||
const gfx::Rect intersection = aRect.Intersect(geometry.BoundingBox());
|
||||
for (gfx::Triangle& triangle : clipped.ToTriangles()) {
|
||||
const gfx::Rect intersection = aRect.Intersect(triangle.BoundingBox());
|
||||
|
||||
// Cull invisible triangles.
|
||||
if (intersection.IsEmpty()) {
|
||||
@ -297,21 +294,24 @@ Compositor::DrawGeometry(const gfx::Rect& aRect,
|
||||
MOZ_ASSERT(aRect.width > 0.0f && aRect.height > 0.0f);
|
||||
MOZ_ASSERT(intersection.width > 0.0f && intersection.height > 0.0f);
|
||||
|
||||
gfx::TexturedTriangle triangle(Move(geometry));
|
||||
triangle.width = aRect.width;
|
||||
triangle.height = aRect.height;
|
||||
gfx::TexturedTriangle texturedTriangle(Move(triangle));
|
||||
texturedTriangle.width = aRect.width;
|
||||
texturedTriangle.height = aRect.height;
|
||||
|
||||
// Since the texture was created for non-split geometry, we need to
|
||||
// update the texture coordinates to account for the split.
|
||||
if (aEffectChain.mPrimaryEffect->mType == EffectTypes::RGB) {
|
||||
const EffectTypes type = aEffectChain.mPrimaryEffect->mType;
|
||||
|
||||
if (type == EffectTypes::RGB || type == EffectTypes::YCBCR ||
|
||||
type == EffectTypes::NV12 || type == EffectTypes::RENDER_TARGET) {
|
||||
TexturedEffect* texturedEffect =
|
||||
static_cast<TexturedEffect*>(aEffectChain.mPrimaryEffect.get());
|
||||
|
||||
UpdateTextureCoordinates(triangle, aRect, intersection,
|
||||
UpdateTextureCoordinates(texturedTriangle, aRect, intersection,
|
||||
texturedEffect->mTextureCoords);
|
||||
}
|
||||
|
||||
DrawTriangle(triangle, aClipRect, aEffectChain,
|
||||
DrawTriangle(texturedTriangle, aClipRect, aEffectChain,
|
||||
aOpacity, aTransform, aVisibleRect);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "mozilla/gfx/2D.h" // for DrawTarget
|
||||
#include "mozilla/gfx/MatrixFwd.h" // for Matrix4x4
|
||||
#include "mozilla/gfx/Point.h" // for IntSize, Point
|
||||
#include "mozilla/gfx/Polygon.h" // for Polygon3D
|
||||
#include "mozilla/gfx/Polygon.h" // for Polygon
|
||||
#include "mozilla/gfx/Rect.h" // for Rect, IntRect
|
||||
#include "mozilla/gfx/Types.h" // for Float
|
||||
#include "mozilla/gfx/Triangle.h" // for Triangle, TexturedTriangle
|
||||
@ -312,14 +312,14 @@ public:
|
||||
gfx::Float aOpacity,
|
||||
const gfx::Matrix4x4& aTransform,
|
||||
const gfx::Rect& aVisibleRect,
|
||||
const Maybe<gfx::Polygon3D>& aGeometry);
|
||||
const Maybe<gfx::Polygon>& aGeometry);
|
||||
|
||||
void DrawGeometry(const gfx::Rect& aRect,
|
||||
const gfx::IntRect& aClipRect,
|
||||
const EffectChain &aEffectChain,
|
||||
gfx::Float aOpacity,
|
||||
const gfx::Matrix4x4& aTransform,
|
||||
const Maybe<gfx::Polygon3D>& aGeometry)
|
||||
const Maybe<gfx::Polygon>& aGeometry)
|
||||
{
|
||||
DrawGeometry(aRect, aClipRect, aEffectChain, aOpacity,
|
||||
aTransform, aRect, aGeometry);
|
||||
|
@ -13,9 +13,19 @@ namespace gfx {
|
||||
const float kEpsilon = 0.001f;
|
||||
|
||||
// Compares two points while allowing some numerical inaccuracy.
|
||||
bool FuzzyEquals(const Point4D& lhs, const Point4D& rhs)
|
||||
{
|
||||
const auto d = lhs - rhs;
|
||||
|
||||
return std::abs(d.x) < kEpsilon &&
|
||||
std::abs(d.y) < kEpsilon &&
|
||||
std::abs(d.z) < kEpsilon &&
|
||||
std::abs(d.w) < kEpsilon;
|
||||
}
|
||||
|
||||
bool FuzzyEquals(const Point3D& lhs, const Point3D& rhs)
|
||||
{
|
||||
const Point3D d = lhs - rhs;
|
||||
const auto d = lhs - rhs;
|
||||
|
||||
return std::abs(d.x) < kEpsilon &&
|
||||
std::abs(d.y) < kEpsilon &&
|
||||
@ -24,7 +34,7 @@ bool FuzzyEquals(const Point3D& lhs, const Point3D& rhs)
|
||||
|
||||
bool FuzzyEquals(const Point& lhs, const Point& rhs)
|
||||
{
|
||||
const Point d = lhs - rhs;
|
||||
const auto d = lhs - rhs;
|
||||
|
||||
return std::abs(d.x) < kEpsilon &&
|
||||
std::abs(d.y) < kEpsilon;
|
||||
@ -39,10 +49,10 @@ bool operator==(const Triangle& lhs, const Triangle& rhs)
|
||||
|
||||
// Compares the points of two polygons and ensures
|
||||
// that the points are in the same winding order.
|
||||
bool operator==(const Polygon3D& lhs, const Polygon3D& rhs)
|
||||
bool operator==(const Polygon& lhs, const Polygon& rhs)
|
||||
{
|
||||
const nsTArray<Point3D>& left = lhs.GetPoints();
|
||||
const nsTArray<Point3D>& right = rhs.GetPoints();
|
||||
const auto& left = lhs.GetPoints();
|
||||
const auto& right = rhs.GetPoints();
|
||||
|
||||
// Polygons do not have the same amount of points.
|
||||
if (left.Length() != right.Length()) {
|
||||
@ -99,7 +109,7 @@ TEST(PolygonTestUtils, TestSanity)
|
||||
EXPECT_FALSE(FuzzyEquals(Point3D(0.01f, 0.01f, 0.01f),
|
||||
Point3D(0.0f, 0.0f, 0.0f)));
|
||||
|
||||
Polygon3D p1 {
|
||||
Polygon p1 {
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
@ -107,21 +117,21 @@ TEST(PolygonTestUtils, TestSanity)
|
||||
};
|
||||
|
||||
// Same points as above shifted forward by one position.
|
||||
Polygon3D shifted {
|
||||
Polygon 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)
|
||||
};
|
||||
|
||||
Polygon3D p2 {
|
||||
Polygon 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)
|
||||
};
|
||||
|
||||
Polygon3D p3 {
|
||||
Polygon p3 {
|
||||
Point3D(0.01f, 0.01f, 1.01f),
|
||||
Point3D(1.01f, 0.01f, 1.01f),
|
||||
Point3D(1.01f, 1.01f, 1.01f),
|
||||
|
@ -16,11 +16,12 @@
|
||||
namespace mozilla {
|
||||
namespace gfx {
|
||||
|
||||
bool FuzzyEquals(const Point4D& lhs, const Point4D& rhs);
|
||||
bool FuzzyEquals(const Point3D& lhs, const Point3D& rhs);
|
||||
bool FuzzyEquals(const Point& lhs, const Point& rhs);
|
||||
|
||||
bool operator==(const Triangle& lhs, const Triangle& rhs);
|
||||
bool operator==(const Polygon3D& lhs, const Polygon3D& rhs);
|
||||
bool operator==(const Polygon& lhs, const Polygon& rhs);
|
||||
|
||||
// Compares two arrays with the equality operator.
|
||||
template<typename T>
|
||||
|
@ -16,11 +16,11 @@ using namespace mozilla::layers;
|
||||
|
||||
namespace {
|
||||
|
||||
static void RunTest(std::deque<Polygon3D> aPolygons,
|
||||
std::deque<Polygon3D> aExpected)
|
||||
static void RunTest(std::deque<Polygon> aPolygons,
|
||||
std::deque<Polygon> aExpected)
|
||||
{
|
||||
std::deque<LayerPolygon> layers;
|
||||
for (Polygon3D& polygon : aPolygons) {
|
||||
for (Polygon& polygon : aPolygons) {
|
||||
layers.push_back(LayerPolygon(nullptr, Move(polygon)));
|
||||
}
|
||||
|
||||
@ -39,14 +39,14 @@ static void RunTest(std::deque<Polygon3D> aPolygons,
|
||||
|
||||
TEST(BSPTree, SameNode)
|
||||
{
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(1.0f, 0.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(1.0f, 0.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
@ -59,14 +59,14 @@ TEST(BSPTree, SameNode)
|
||||
|
||||
TEST(BSPTree, OneChild)
|
||||
{
|
||||
const Polygon3D p1 {
|
||||
const Polygon p1 {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(1.0f, 0.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f)
|
||||
};
|
||||
|
||||
const Polygon3D p2 {
|
||||
const Polygon p2 {
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
@ -79,14 +79,14 @@ TEST(BSPTree, OneChild)
|
||||
|
||||
TEST(BSPTree, SharedEdge1)
|
||||
{
|
||||
Polygon3D p1 {
|
||||
Polygon p1 {
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
Polygon3D p2 {
|
||||
Polygon p2 {
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
Point3D(2.0f, 2.0f, 1.0f),
|
||||
@ -98,14 +98,14 @@ TEST(BSPTree, SharedEdge1)
|
||||
|
||||
TEST(BSPTree, SharedEdge2)
|
||||
{
|
||||
Polygon3D p1 {
|
||||
Polygon p1 {
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
Polygon3D p2 {
|
||||
Polygon p2 {
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
Point3D(2.0f, 2.0f, 0.0f),
|
||||
@ -117,34 +117,34 @@ TEST(BSPTree, SharedEdge2)
|
||||
|
||||
TEST(BSPTree, SplitSharedEdge)
|
||||
{
|
||||
Polygon3D p1 {
|
||||
Polygon p1 {
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f)
|
||||
};
|
||||
|
||||
Polygon3D p2 {
|
||||
Polygon p2 {
|
||||
Point3D(1.0f, 0.0f, 2.0f),
|
||||
Point3D(1.0f, 1.0f, 2.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 0.0f, 0.0f)
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 0.0f, 0.0f),
|
||||
Point3D(1.0f, 0.0f, 1.0f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(1.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(1.0f, 0.0f, 2.0f),
|
||||
Point3D(1.0f, 1.0f, 2.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
@ -157,29 +157,29 @@ TEST(BSPTree, SplitSharedEdge)
|
||||
|
||||
TEST(BSPTree, SplitSimple1)
|
||||
{
|
||||
Polygon3D p1 {
|
||||
Polygon 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)
|
||||
};
|
||||
|
||||
Polygon3D p2 {
|
||||
Polygon p2 {
|
||||
Point3D(0.0f, 0.0f, 2.0f),
|
||||
Point3D(1.0f, 0.0f, 2.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f)
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(0.0f, 1.0f, 0.0f),
|
||||
Point3D(0.0f, 0.5f, 1.0f),
|
||||
Point3D(1.0f, 0.5f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f)
|
||||
},
|
||||
p1,
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.0f, 0.0f, 2.0f),
|
||||
Point3D(1.0f, 0.0f, 2.0f),
|
||||
Point3D(1.0f, 0.5f, 1.0f),
|
||||
@ -191,14 +191,14 @@ TEST(BSPTree, SplitSimple1)
|
||||
}
|
||||
|
||||
TEST(BSPTree, SplitSimple2) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-5.00000f, -5.00000f, 0.00000f),
|
||||
Point3D(-5.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(5.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(5.00000f, -5.00000f, 0.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.00000f, -5.00000f, -5.00000f),
|
||||
Point3D(0.00000f, 5.00000f, -5.00000f),
|
||||
Point3D(0.00000f, 5.00000f, 5.00000f),
|
||||
@ -206,20 +206,20 @@ TEST(BSPTree, SplitSimple2) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(0.00000f, -5.00000f, 0.00000f),
|
||||
Point3D(0.00000f, -5.00000f, -5.00000f),
|
||||
Point3D(0.00000f, 5.00000f, -5.00000f),
|
||||
Point3D(0.00000f, 5.00000f, 0.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-5.00000f, -5.00000f, 0.00000f),
|
||||
Point3D(-5.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(5.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(5.00000f, -5.00000f, 0.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(0.00000f, 5.00000f, 5.00000f),
|
||||
Point3D(0.00000f, -5.00000f, 5.00000f),
|
||||
@ -230,20 +230,20 @@ TEST(BSPTree, SplitSimple2) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, NoSplit1) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 10.00000f, 0.00000f),
|
||||
Point3D(0.00000f, 0.00000f, 0.00000f),
|
||||
Point3D(10.00000f, 0.00000f, 0.00000f),
|
||||
Point3D(10.00000f, 10.00000f, 0.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 10.00000f, -5.00000f),
|
||||
Point3D(0.00000f, 0.00000f, -5.00000f),
|
||||
Point3D(10.00000f, 0.00000f, -5.00000f),
|
||||
Point3D(10.00000f, 10.00000f, -5.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 10.00000f, 5.00000f),
|
||||
Point3D(0.00000f, 0.00000f, 5.00000f),
|
||||
Point3D(10.00000f, 0.00000f, 5.00000f),
|
||||
@ -251,20 +251,20 @@ TEST(BSPTree, NoSplit1) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 10.00000f, -5.00000f),
|
||||
Point3D(0.00000f, 0.00000f, -5.00000f),
|
||||
Point3D(10.00000f, 0.00000f, -5.00000f),
|
||||
Point3D(10.00000f, 10.00000f, -5.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 10.00000f, 0.00000f),
|
||||
Point3D(0.00000f, 0.00000f, 0.00000f),
|
||||
Point3D(10.00000f, 0.00000f, 0.00000f),
|
||||
Point3D(10.00000f, 10.00000f, 0.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 10.00000f, 5.00000f),
|
||||
Point3D(0.00000f, 0.00000f, 5.00000f),
|
||||
Point3D(10.00000f, 0.00000f, 5.00000f),
|
||||
@ -275,14 +275,14 @@ TEST(BSPTree, NoSplit1) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, NoSplit2) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-5.00000f, -5.00000f, 0.00000f),
|
||||
Point3D(-5.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(5.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(5.00000f, -5.00000f, 0.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 5.00000f, -15.00000f),
|
||||
Point3D(0.00000f, -5.00000f, -15.00000f),
|
||||
Point3D(0.00000f, -5.00000f, -10.00000f),
|
||||
@ -290,14 +290,14 @@ TEST(BSPTree, NoSplit2) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(0.00000f, 5.00000f, -15.00000f),
|
||||
Point3D(0.00000f, -5.00000f, -15.00000f),
|
||||
Point3D(0.00000f, -5.00000f, -10.00000f),
|
||||
Point3D(0.00000f, 5.00000f, -10.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-5.00000f, -5.00000f, 0.00000f),
|
||||
Point3D(-5.00000f, 5.00000f, 0.00000f),
|
||||
Point3D(5.00000f, 5.00000f, 0.00000f),
|
||||
@ -308,14 +308,14 @@ TEST(BSPTree, NoSplit2) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate0degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.00000f, 2.00000f),
|
||||
Point3D(-0.00000f, -2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, -2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00000f, 2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, -2.00000f),
|
||||
Point3D(-2.00000f, 0.00000f, -2.00000f),
|
||||
@ -323,14 +323,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate0degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00000f, 2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, -2.00000f),
|
||||
Point3D(-2.00000f, 0.00000f, -2.00000f),
|
||||
Point3D(-2.00000f, 0.00010f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.00000f, 2.00000f),
|
||||
Point3D(-0.00000f, -2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, -2.00000f),
|
||||
@ -341,14 +341,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate0degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate20degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 1.19540f, 2.56350f),
|
||||
Point3D(-0.00000f, -2.56340f, 1.19540f),
|
||||
Point3D(0.00010f, -1.19530f, -2.56340f),
|
||||
Point3D(0.00010f, 2.56350f, -1.19530f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, 0.68410f, -1.87930f),
|
||||
@ -356,14 +356,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate20degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 1.19540f, 2.56350f),
|
||||
Point3D(-0.00000f, -2.56340f, 1.19540f),
|
||||
Point3D(0.00010f, -1.19530f, -2.56340f),
|
||||
@ -374,14 +374,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate20degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate40degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -0.73200f, 2.73210f),
|
||||
Point3D(-0.00000f, -2.73200f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, -2.73200f),
|
||||
Point3D(0.00010f, 2.73210f, 0.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(-2.00000f, 1.73210f, -0.99990f),
|
||||
@ -389,14 +389,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate40degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(-2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(-2.00000f, -1.73200f, 1.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -0.73200f, 2.73210f),
|
||||
Point3D(-0.00000f, -2.73200f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, -2.73200f),
|
||||
@ -407,14 +407,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate40degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate60degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.73200f, 0.73210f),
|
||||
Point3D(-0.00000f, -0.73200f, -2.73200f),
|
||||
Point3D(0.00010f, 2.73210f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, 2.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(-2.00000f, 1.73210f, 1.00010f),
|
||||
@ -422,20 +422,20 @@ TEST(BSPTree, TwoPlaneIntersectRotate60degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-2.00000f, 1.26793f, 0.73210f),
|
||||
Point3D(-2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(2.00000f, 1.26793f, 0.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.73200f, 0.73210f),
|
||||
Point3D(-0.00000f, -0.73200f, -2.73200f),
|
||||
Point3D(0.00010f, 2.73210f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, 2.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.26793f, 0.73210f),
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(-2.00000f, 1.73210f, 1.00010f),
|
||||
@ -446,14 +446,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate60degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate80degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -1.19530f, -2.56340f),
|
||||
Point3D(-0.00000f, 2.56350f, -1.19530f),
|
||||
Point3D(0.00010f, 1.19540f, 2.56350f),
|
||||
Point3D(0.00010f, -2.56340f, 1.19540f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f),
|
||||
@ -461,14 +461,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate80degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -1.19530f, -2.56340f),
|
||||
Point3D(-0.00000f, 2.56350f, -1.19530f),
|
||||
Point3D(0.00010f, 1.19540f, 2.56350f),
|
||||
Point3D(0.00010f, -2.56340f, 1.19540f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f),
|
||||
@ -479,14 +479,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate80degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate100degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.73210f, -0.73200f),
|
||||
Point3D(-0.00000f, 0.73210f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, -2.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, -1.00000f),
|
||||
@ -494,20 +494,20 @@ TEST(BSPTree, TwoPlaneIntersectRotate100degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.26783f, -0.73200f),
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(-2.00000f, -1.26783f, -0.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.73210f, -0.73200f),
|
||||
Point3D(-0.00000f, 0.73210f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, -2.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-2.00000f, -1.26783f, -0.73200f),
|
||||
Point3D(-2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
@ -518,14 +518,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate100degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate120degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -0.73200f, 2.73210f),
|
||||
Point3D(-0.00000f, -2.73200f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, -2.73200f),
|
||||
Point3D(0.00010f, 2.73210f, 0.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(-2.00000f, 1.73210f, -0.99990f),
|
||||
@ -533,14 +533,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate120degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(-2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(-2.00000f, -1.73200f, 1.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -0.73200f, 2.73210f),
|
||||
Point3D(-0.00000f, -2.73200f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, -2.73200f),
|
||||
@ -551,14 +551,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate120degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate140degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -1.19530f, -2.56340f),
|
||||
Point3D(-0.00000f, 2.56350f, -1.19530f),
|
||||
Point3D(0.00010f, 1.19540f, 2.56350f),
|
||||
Point3D(0.00010f, -2.56340f, 1.19540f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f),
|
||||
@ -566,14 +566,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate140degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -1.19530f, -2.56340f),
|
||||
Point3D(-0.00000f, 2.56350f, -1.19530f),
|
||||
Point3D(0.00010f, 1.19540f, 2.56350f),
|
||||
Point3D(0.00010f, -2.56340f, 1.19540f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f),
|
||||
@ -584,14 +584,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate140degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate160degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.00000f, 2.00000f),
|
||||
Point3D(-0.00000f, -2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, -2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(-2.00000f, 0.00010f, -2.00000f),
|
||||
@ -599,14 +599,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate160degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(-2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(-2.00000f, -0.00000f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.00000f, 2.00000f),
|
||||
Point3D(-0.00000f, -2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, -2.00000f),
|
||||
@ -617,14 +617,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate160degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate180degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.00000f, -2.00000f),
|
||||
Point3D(-0.00000f, 2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(-2.00000f, -0.00000f, 2.00000f),
|
||||
@ -632,14 +632,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate180degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.00000f, -2.00000f),
|
||||
Point3D(-0.00000f, 2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(-2.00000f, -0.00000f, 2.00000f),
|
||||
@ -650,14 +650,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate180degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate200degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 1.19540f, 2.56350f),
|
||||
Point3D(-0.00000f, -2.56340f, 1.19540f),
|
||||
Point3D(0.00010f, -1.19530f, -2.56340f),
|
||||
Point3D(0.00010f, 2.56350f, -1.19530f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, 0.68410f, -1.87930f),
|
||||
@ -665,14 +665,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate200degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 1.19540f, 2.56350f),
|
||||
Point3D(-0.00000f, -2.56340f, 1.19540f),
|
||||
Point3D(0.00010f, -1.19530f, -2.56340f),
|
||||
@ -683,14 +683,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate200degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate220degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 0.73210f, -2.73200f),
|
||||
Point3D(-0.00000f, 2.73210f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, -0.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, 1.00000f),
|
||||
@ -698,14 +698,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate220degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 0.73210f, -2.73200f),
|
||||
Point3D(-0.00000f, 2.73210f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, -0.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, 1.00000f),
|
||||
@ -716,14 +716,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate220degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate240degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.73200f, 0.73210f),
|
||||
Point3D(-0.00000f, -0.73200f, -2.73200f),
|
||||
Point3D(0.00010f, 2.73210f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, 2.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(-2.00000f, 1.73210f, 1.00010f),
|
||||
@ -731,20 +731,20 @@ TEST(BSPTree, TwoPlaneIntersectRotate240degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-2.00000f, 1.26793f, 0.73210f),
|
||||
Point3D(-2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(2.00000f, 1.26793f, 0.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.73200f, 0.73210f),
|
||||
Point3D(-0.00000f, -0.73200f, -2.73200f),
|
||||
Point3D(0.00010f, 2.73210f, -0.73200f),
|
||||
Point3D(0.00010f, 0.73210f, 2.73210f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.26793f, 0.73210f),
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(-2.00000f, 1.73210f, 1.00010f),
|
||||
@ -755,14 +755,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate240degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate260degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 1.19540f, 2.56350f),
|
||||
Point3D(-0.00000f, -2.56340f, 1.19540f),
|
||||
Point3D(0.00010f, -1.19530f, -2.56340f),
|
||||
Point3D(0.00010f, 2.56350f, -1.19530f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, 0.68410f, -1.87930f),
|
||||
@ -770,14 +770,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate260degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 1.19540f, 2.56350f),
|
||||
Point3D(-0.00000f, -2.56340f, 1.19540f),
|
||||
Point3D(0.00010f, -1.19530f, -2.56340f),
|
||||
@ -788,14 +788,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate260degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate280degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.73210f, -0.73200f),
|
||||
Point3D(-0.00000f, 0.73210f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, -2.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, -1.00000f),
|
||||
@ -803,20 +803,20 @@ TEST(BSPTree, TwoPlaneIntersectRotate280degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(2.00000f, -1.26783f, -0.73200f),
|
||||
Point3D(2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, -1.00000f),
|
||||
Point3D(-2.00000f, -1.26783f, -0.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 2.73210f, -0.73200f),
|
||||
Point3D(-0.00000f, 0.73210f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, -2.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(-2.00000f, -1.26783f, -0.73200f),
|
||||
Point3D(-2.00000f, 1.73210f, 1.00010f),
|
||||
Point3D(2.00000f, 1.73210f, 1.00010f),
|
||||
@ -827,14 +827,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate280degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate300degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 0.73210f, -2.73200f),
|
||||
Point3D(-0.00000f, 2.73210f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, -0.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, 1.00000f),
|
||||
@ -842,14 +842,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate300degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, 0.73210f, -2.73200f),
|
||||
Point3D(-0.00000f, 2.73210f, 0.73210f),
|
||||
Point3D(0.00010f, -0.73200f, 2.73210f),
|
||||
Point3D(0.00010f, -2.73200f, -0.73200f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 1.73210f, -0.99990f),
|
||||
Point3D(2.00000f, -1.73200f, 1.00000f),
|
||||
Point3D(-2.00000f, -1.73200f, 1.00000f),
|
||||
@ -860,14 +860,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate300degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate320degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -1.19530f, -2.56340f),
|
||||
Point3D(-0.00000f, 2.56350f, -1.19530f),
|
||||
Point3D(0.00010f, 1.19540f, 2.56350f),
|
||||
Point3D(0.00010f, -2.56340f, 1.19540f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f),
|
||||
@ -875,14 +875,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate320degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -1.19530f, -2.56340f),
|
||||
Point3D(-0.00000f, 2.56350f, -1.19530f),
|
||||
Point3D(0.00010f, 1.19540f, 2.56350f),
|
||||
Point3D(0.00010f, -2.56340f, 1.19540f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.68410f, -1.87930f),
|
||||
Point3D(2.00000f, -0.68400f, 1.87940f),
|
||||
Point3D(-2.00000f, -0.68400f, 1.87940f),
|
||||
@ -893,14 +893,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate320degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate340degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.00000f, -2.00000f),
|
||||
Point3D(-0.00000f, 2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(-2.00000f, -0.00000f, 2.00000f),
|
||||
@ -908,14 +908,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate340degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.00000f, -2.00000f),
|
||||
Point3D(-0.00000f, 2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(-2.00000f, -0.00000f, 2.00000f),
|
||||
@ -926,14 +926,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate340degrees) {
|
||||
}
|
||||
|
||||
TEST(BSPTree, TwoPlaneIntersectRotate360degrees) {
|
||||
const std::deque<Polygon3D> polygons {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> polygons {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.00000f, -2.00000f),
|
||||
Point3D(-0.00000f, 2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(-2.00000f, -0.00000f, 2.00000f),
|
||||
@ -941,14 +941,14 @@ TEST(BSPTree, TwoPlaneIntersectRotate360degrees) {
|
||||
}
|
||||
};
|
||||
|
||||
const std::deque<Polygon3D> expected {
|
||||
Polygon3D {
|
||||
const std::deque<Polygon> expected {
|
||||
Polygon {
|
||||
Point3D(-0.00000f, -2.00000f, -2.00000f),
|
||||
Point3D(-0.00000f, 2.00000f, -2.00000f),
|
||||
Point3D(0.00010f, 2.00000f, 2.00000f),
|
||||
Point3D(0.00010f, -2.00000f, 2.00000f)
|
||||
},
|
||||
Polygon3D {
|
||||
Polygon {
|
||||
Point3D(2.00000f, 0.00010f, -2.00000f),
|
||||
Point3D(2.00000f, -0.00000f, 2.00000f),
|
||||
Point3D(-2.00000f, -0.00000f, 2.00000f),
|
||||
|
@ -14,9 +14,9 @@
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
TEST(Polygon3D, TriangulateRectangle)
|
||||
TEST(Polygon, TriangulateRectangle)
|
||||
{
|
||||
const Polygon3D p {
|
||||
const Polygon p {
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(1.0f, 1.0f, 1.0f),
|
||||
@ -32,9 +32,9 @@ TEST(Polygon3D, TriangulateRectangle)
|
||||
AssertArrayEQ(triangles, expected);
|
||||
}
|
||||
|
||||
TEST(Polygon3D, TriangulatePentagon)
|
||||
TEST(Polygon, TriangulatePentagon)
|
||||
{
|
||||
const Polygon3D p {
|
||||
const Polygon p {
|
||||
Point3D(0.0f, 0.0f, 1.0f),
|
||||
Point3D(0.0f, 1.0f, 1.0f),
|
||||
Point3D(0.5f, 1.5f, 1.0f),
|
||||
@ -52,92 +52,84 @@ TEST(Polygon3D, TriangulatePentagon)
|
||||
AssertArrayEQ(triangles, expected);
|
||||
}
|
||||
|
||||
TEST(Polygon3D, ClipRectangle)
|
||||
void
|
||||
TestClipRect(const Polygon& aPolygon,
|
||||
const Polygon& aExpected,
|
||||
const Rect& aRect)
|
||||
{
|
||||
Polygon3D clipped, expected;
|
||||
const Polygon res = aPolygon.ClipPolygon(Polygon::FromRect(aRect));
|
||||
EXPECT_TRUE(res == aExpected);
|
||||
}
|
||||
|
||||
Polygon3D polygon {
|
||||
TEST(Polygon, ClipRectangle)
|
||||
{
|
||||
Polygon 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)
|
||||
};
|
||||
TestClipRect(polygon, polygon, Rect(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
EXPECT_TRUE(clipped == polygon);
|
||||
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.0f, 0.0f, 0.8f, 0.8f));
|
||||
expected = Polygon3D {
|
||||
Polygon expected = Polygon {
|
||||
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)
|
||||
};
|
||||
EXPECT_TRUE(clipped == expected);
|
||||
TestClipRect(polygon, expected, Rect(0.0f, 0.0f, 0.8f, 0.8f));
|
||||
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.2f, 0.2f, 0.8f, 0.8f));
|
||||
expected = Polygon3D {
|
||||
expected = Polygon {
|
||||
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)
|
||||
};
|
||||
EXPECT_TRUE(clipped == expected);
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.8f, 0.8f));
|
||||
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.2f, 0.2f, 0.6f, 0.6f));
|
||||
expected = Polygon3D {
|
||||
expected = Polygon {
|
||||
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)
|
||||
};
|
||||
EXPECT_TRUE(clipped == expected);
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.6f, 0.6f));
|
||||
}
|
||||
|
||||
TEST(Polygon3D, ClipTriangle)
|
||||
TEST(Polygon, ClipTriangle)
|
||||
{
|
||||
Polygon3D clipped, expected;
|
||||
const Polygon3D polygon {
|
||||
Polygon clipped, expected;
|
||||
const Polygon polygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f)
|
||||
};
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
expected = Polygon3D {
|
||||
expected = Polygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f)
|
||||
};
|
||||
EXPECT_TRUE(clipped == expected);
|
||||
TestClipRect(polygon, expected, Rect(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.0f, 0.0f, 0.8f, 0.8f));
|
||||
expected = Polygon3D {
|
||||
expected = Polygon {
|
||||
Point3D(0.0f, 0.0f, 0.0f),
|
||||
Point3D(0.0f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.8f, 0.0f)
|
||||
};
|
||||
EXPECT_TRUE(clipped == expected);
|
||||
TestClipRect(polygon, expected, Rect(0.0f, 0.0f, 0.8f, 0.8f));
|
||||
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.2f, 0.2f, 0.8f, 0.8f));
|
||||
expected = Polygon3D {
|
||||
expected = Polygon {
|
||||
Point3D(0.2f, 0.2f, 0.0f),
|
||||
Point3D(0.2f, 1.0f, 0.0f),
|
||||
Point3D(1.0f, 1.0f, 0.0f)
|
||||
};
|
||||
EXPECT_TRUE(clipped == expected);
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.8f, 0.8f));
|
||||
|
||||
|
||||
clipped = polygon.ClipPolygon(Rect(0.2f, 0.2f, 0.6f, 0.6f));
|
||||
expected = Polygon3D {
|
||||
expected = Polygon {
|
||||
Point3D(0.2f, 0.2f, 0.0f),
|
||||
Point3D(0.2f, 0.8f, 0.0f),
|
||||
Point3D(0.8f, 0.8f, 0.0f)
|
||||
};
|
||||
EXPECT_TRUE(clipped == expected);
|
||||
}
|
||||
TestClipRect(polygon, expected, Rect(0.2f, 0.2f, 0.6f, 0.6f));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user