Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3143)

Unified Diff: cc/quads/draw_polygon_unittest.cc

Issue 1497153002: Replace inverse transform with Cross-product computation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/quads/draw_polygon.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/quads/draw_polygon_unittest.cc
diff --git a/cc/quads/draw_polygon_unittest.cc b/cc/quads/draw_polygon_unittest.cc
index 0fc25e340721c1c15b7096405e895800096fb116..4dc2883ba4548bd37273cfe961407a7c4fedab27 100644
--- a/cc/quads/draw_polygon_unittest.cc
+++ b/cc/quads/draw_polygon_unittest.cc
@@ -11,11 +11,20 @@
#include "ui/gfx/transform.h"
namespace cc {
+
+void DrawPolygon::RecomputeNormalForTesting() {
+ ConstructNormal();
+}
+
namespace {
#define CREATE_NEW_DRAW_POLYGON(name, points_vector, normal, polygon_id) \
DrawPolygon name(NULL, points_vector, normal, polygon_id)
+#define CREATE_TEST_DRAW_POLYGON(name, points_vector, polygon_id) \
+ DrawPolygon name(NULL, points_vector, gfx::Vector3dF(1, 2, 3), polygon_id); \
+ name.RecomputeNormalForTesting()
+
#define EXPECT_FLOAT_WITHIN_EPSILON_OF(a, b) \
EXPECT_TRUE(std::abs(a - b) < std::numeric_limits<float>::epsilon());
@@ -24,6 +33,11 @@ namespace {
EXPECT_FLOAT_EQ(point_a.y(), point_b.y()); \
EXPECT_FLOAT_EQ(point_a.z(), point_b.z());
+#define EXPECT_NORMAL(poly, n_x, n_y, n_z) \
+ EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().x(), n_x); \
+ EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().y(), n_y); \
+ EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().z(), n_z);
+
static void ValidatePoints(const DrawPolygon& polygon,
const std::vector<gfx::Point3F>& points) {
EXPECT_EQ(polygon.points().size(), points.size());
@@ -32,6 +46,96 @@ static void ValidatePoints(const DrawPolygon& polygon,
}
}
+// A simple square in a plane.
+TEST(DrawPolygonConstructionTest, NormalNormal) {
+ std::vector<gfx::Point3F> vertices;
+ vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
+
+ gfx::Transform Identity;
+ DrawPolygon polygon(NULL, gfx::RectF(10.0, 10.0), Identity, 1);
+ EXPECT_NORMAL(polygon, 0.0, 0.0, 1.0);
+}
+
+// More complicated shapes.
+TEST(DrawPolygonConstructionTest, TestNormal) {
+ std::vector<gfx::Point3F> vertices;
+ vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
+
+ CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
+ EXPECT_NORMAL(polygon, 0.0, 0.0, 1.0);
+}
+
+TEST(DrawPolygonConstructionTest, ClippedNormal) {
+ std::vector<gfx::Point3F> vertices;
+ vertices.push_back(gfx::Point3F(0.1f, 10.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(0.0f, 9.9f, 0.0f));
+ vertices.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f));
+
+ CREATE_TEST_DRAW_POLYGON(polygon, vertices, 1);
+ EXPECT_NORMAL(polygon, 0.0, 0.0, 1.0);
+}
+
+TEST(DrawPolygonConstructionTest, SlimTriangleNormal) {
+ std::vector<gfx::Point3F> vertices;
+ vertices.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(5000.0f, 0.0f, 0.0f));
+ vertices.push_back(gfx::Point3F(10000.0f, 1.0f, 0.0f));
+
+ CREATE_TEST_DRAW_POLYGON(polygon, vertices, 2);
+ EXPECT_NORMAL(polygon, 0.0, 0.0, 1.0);
Peter Mayo 2015/12/04 04:33:56 Perhaps one that isn't axis-aligned?
Peter Mayo 2015/12/04 05:21:34 Added in the transform test.
+}
+
+TEST(DrawPolygonConstructionTest, ManyVertexNormal) {
+ std::vector<gfx::Point3F> vertices_c;
+ std::vector<gfx::Point3F> vertices_d;
+ for (int i = 0; i < 100; i++) {
+ vertices_c.push_back(
+ gfx::Point3F(cos(i * M_PI / 50), sin(i * M_PI / 50), 0.0f));
+ vertices_d.push_back(gfx::Point3F(cos(i * M_PI / 50) + 99.0,
+ sin(i * M_PI / 50) + 99.0, 100.0f));
+ }
+ CREATE_TEST_DRAW_POLYGON(polygon_c, vertices_c, 3);
+ EXPECT_NORMAL(polygon_c, 0.0, 0.0, 1.0);
+
+ CREATE_TEST_DRAW_POLYGON(polygon_d, vertices_d, 4);
+ EXPECT_NORMAL(polygon_c, 0.0, 0.0, 1.0);
+}
+
+// A simple rect being transformed.
+TEST(DrawPolygonConstructionTest, DizzyNormal) {
+ gfx::RectF src(-0.1, -10.0, 0.2, 20.0);
+
+ gfx::Transform transform_i(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
+ DrawPolygon polygon_i(NULL, src, transform_i, 1);
+
+ EXPECT_NORMAL(polygon_i, 0.0, 0.0, 1.0);
+
+ gfx::Transform tranform_a(0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
+ DrawPolygon polygon_a(NULL, src, tranform_a, 2);
+ EXPECT_NORMAL(polygon_a, 0.0, 0.0, -1.0);
+
+ gfx::Transform tranform_b(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
+ DrawPolygon polygon_b(NULL, src, tranform_b, 3);
+ EXPECT_NORMAL(polygon_b, -1.0, 0.0, 0.0);
+
+ gfx::Transform tranform_c(1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1);
+ DrawPolygon polygon_c(NULL, src, tranform_c, 4);
+ EXPECT_NORMAL(polygon_c, 0.0, -1.0, 0.0);
+
+ gfx::Transform tranform_d(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
+ DrawPolygon polygon_d(NULL, src, tranform_d, 5);
+ EXPECT_NORMAL(polygon_d, 0.0, 0.0, -1.0);
+}
+
// Two quads are nearly touching but definitely ordered. Second one should
// compare in front.
TEST(DrawPolygonSplitTest, NearlyTouchingOrder) {
@@ -228,9 +332,7 @@ TEST(DrawPolygonTransformTest, TransformNormal) {
// because some architectures (e.g., Arm64) employ a fused multiply-add
// instruction which causes rounding asymmetry and reduces precision.
// http://crbug.com/401117.
- EXPECT_FLOAT_WITHIN_EPSILON_OF(polygon_a.normal().x(), 0);
- EXPECT_FLOAT_WITHIN_EPSILON_OF(polygon_a.normal().y(), 0);
- EXPECT_FLOAT_WITHIN_EPSILON_OF(polygon_a.normal().z(), -1);
+ EXPECT_NORMAL(polygon_a, 0.0, 0.0, -1.0);
}
} // namespace
« no previous file with comments | « cc/quads/draw_polygon.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698