| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // We would like to use M_PI on windows too. | 5 // We would like to use M_PI on windows too. |
| 6 #ifdef _WIN32 | 6 #ifdef _WIN32 |
| 7 #define _USE_MATH_DEFINES | 7 #define _USE_MATH_DEFINES |
| 8 #endif | 8 #endif |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <limits> | 12 #include <limits> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "cc/output/bsp_compare_result.h" | 16 #include "cc/output/bsp_compare_result.h" |
| 16 #include "cc/quads/draw_polygon.h" | 17 #include "cc/quads/draw_polygon.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 19 | 20 |
| 20 namespace cc { | 21 namespace cc { |
| 21 | 22 |
| 22 #if !defined(OS_WIN) | 23 #if !defined(OS_WIN) |
| 23 void DrawPolygon::RecomputeNormalForTesting() { | 24 void DrawPolygon::RecomputeNormalForTesting() { |
| 24 ConstructNormal(); | 25 ConstructNormal(); |
| 25 } | 26 } |
| 26 #endif | 27 #endif |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 #define CREATE_NEW_DRAW_POLYGON(name, points_vector, normal, polygon_id) \ | 31 #define CREATE_NEW_DRAW_POLYGON(name, points_vector, normal, polygon_id) \ |
| 31 DrawPolygon name(NULL, points_vector, normal, polygon_id) | 32 DrawPolygon name(NULL, points_vector, normal, polygon_id) |
| 32 | 33 |
| 34 #define CREATE_NEW_DRAW_POLYGON_PTR(name, points_vector, normal, polygon_id) \ |
| 35 std::unique_ptr<DrawPolygon> name(base::MakeUnique<DrawPolygon>( \ |
| 36 nullptr, points_vector, normal, polygon_id)) |
| 37 |
| 33 #define CREATE_TEST_DRAW_FORWARD_POLYGON(name, points_vector, id) \ | 38 #define CREATE_TEST_DRAW_FORWARD_POLYGON(name, points_vector, id) \ |
| 34 DrawPolygon name(NULL, points_vector, gfx::Vector3dF(0, 0, 1.0f), id); \ | 39 DrawPolygon name(NULL, points_vector, gfx::Vector3dF(0, 0, 1.0f), id); \ |
| 35 name.RecomputeNormalForTesting() | 40 name.RecomputeNormalForTesting() |
| 36 | 41 |
| 37 #define CREATE_TEST_DRAW_REVERSE_POLYGON(name, points_vector, id) \ | 42 #define CREATE_TEST_DRAW_REVERSE_POLYGON(name, points_vector, id) \ |
| 38 DrawPolygon name(NULL, points_vector, gfx::Vector3dF(0, 0, -1.0f), id); \ | 43 DrawPolygon name(NULL, points_vector, gfx::Vector3dF(0, 0, -1.0f), id); \ |
| 39 name.RecomputeNormalForTesting() | 44 name.RecomputeNormalForTesting() |
| 40 | 45 |
| 41 #define EXPECT_FLOAT_WITHIN_EPSILON_OF(a, b) \ | 46 #define EXPECT_FLOAT_WITHIN_EPSILON_OF(a, b) \ |
| 47 LOG(WARNING) << "a=" << a << " b= " << b << " diff=" << std::abs(a - b); \ |
| 42 EXPECT_TRUE(std::abs(a - b) < std::numeric_limits<float>::epsilon()); | 48 EXPECT_TRUE(std::abs(a - b) < std::numeric_limits<float>::epsilon()); |
| 43 | 49 |
| 44 #define EXPECT_POINT_EQ(point_a, point_b) \ | 50 #define EXPECT_POINT_EQ(point_a, point_b) \ |
| 45 EXPECT_FLOAT_EQ(point_a.x(), point_b.x()); \ | 51 EXPECT_FLOAT_EQ(point_a.x(), point_b.x()); \ |
| 46 EXPECT_FLOAT_EQ(point_a.y(), point_b.y()); \ | 52 EXPECT_FLOAT_EQ(point_a.y(), point_b.y()); \ |
| 47 EXPECT_FLOAT_EQ(point_a.z(), point_b.z()); | 53 EXPECT_FLOAT_EQ(point_a.z(), point_b.z()); |
| 48 | 54 |
| 49 #define EXPECT_NORMAL(poly, n_x, n_y, n_z) \ | 55 #define EXPECT_NORMAL(poly, n_x, n_y, n_z) \ |
| 50 EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().x(), n_x); \ | 56 EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().x(), n_x); \ |
| 51 EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().y(), n_y); \ | 57 EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().y(), n_y); \ |
| 52 EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().z(), n_z); | 58 EXPECT_FLOAT_WITHIN_EPSILON_OF(poly.normal().z(), n_z); |
| 53 | 59 |
| 54 static void ValidatePoints(const DrawPolygon& polygon, | 60 static void ValidatePoints(const DrawPolygon& polygon, |
| 55 const std::vector<gfx::Point3F>& points) { | 61 const std::vector<gfx::Point3F>& points) { |
| 56 EXPECT_EQ(polygon.points().size(), points.size()); | 62 EXPECT_EQ(polygon.points().size(), points.size()); |
| 57 for (size_t i = 0; i < points.size(); i++) { | 63 for (size_t i = 0; i < points.size(); i++) { |
| 58 EXPECT_POINT_EQ(polygon.points()[i], points[i]); | 64 EXPECT_POINT_EQ(polygon.points()[i], points[i]); |
| 59 } | 65 } |
| 60 } | 66 } |
| 61 | 67 |
| 68 static void ValidatePointsWithinDeltaOf(const DrawPolygon& polygon, |
| 69 const std::vector<gfx::Point3F>& points, |
| 70 float delta) { |
| 71 EXPECT_EQ(polygon.points().size(), points.size()); |
| 72 for (size_t i = 0; i < points.size(); i++) { |
| 73 EXPECT_LE((polygon.points()[i] - points[i]).Length(), delta); |
| 74 } |
| 75 } |
| 76 |
| 77 std::unique_ptr<DrawPolygon> ClonePolygon(const DrawPolygon& polygon) { |
| 78 return base::MakeUnique<DrawPolygon>(polygon.original_ref(), polygon.points(), |
| 79 polygon.normal(), polygon.order_index()); |
| 80 } |
| 81 |
| 82 // Classifies polygon a with respect to b |
| 83 BspCompareResult SideCompare(const DrawPolygon& a, const DrawPolygon& b) { |
| 84 std::unique_ptr<DrawPolygon> front; |
| 85 std::unique_ptr<DrawPolygon> back; |
| 86 bool is_coplanar; |
| 87 b.SplitPolygon(ClonePolygon(a), &front, &back, &is_coplanar); |
| 88 if (is_coplanar) { |
| 89 return (front != nullptr) ? BSP_COPLANAR_FRONT : BSP_COPLANAR_BACK; |
| 90 } |
| 91 if (front == nullptr) |
| 92 return BSP_BACK; |
| 93 if (back == nullptr) |
| 94 return BSP_FRONT; |
| 95 return BSP_SPLIT; |
| 96 } |
| 97 |
| 62 // A simple square in a plane. | 98 // A simple square in a plane. |
| 63 TEST(DrawPolygonConstructionTest, NormalNormal) { | 99 TEST(DrawPolygonConstructionTest, NormalNormal) { |
| 64 gfx::Transform Identity; | 100 gfx::Transform Identity; |
| 65 DrawPolygon polygon(NULL, gfx::RectF(10.0f, 10.0f), Identity, 1); | 101 DrawPolygon polygon(NULL, gfx::RectF(10.0f, 10.0f), Identity, 1); |
| 66 EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f); | 102 EXPECT_NORMAL(polygon, 0.0f, 0.0f, 1.0f); |
| 67 } | 103 } |
| 68 | 104 |
| 69 // More complicated shapes. | 105 // More complicated shapes. |
| 70 TEST(DrawPolygonConstructionTest, TestNormal) { | 106 TEST(DrawPolygonConstructionTest, TestNormal) { |
| 71 std::vector<gfx::Point3F> vertices; | 107 std::vector<gfx::Point3F> vertices; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 std::vector<gfx::Point3F> vertices_b; | 237 std::vector<gfx::Point3F> vertices_b; |
| 202 vertices_b.push_back(gfx::Point3F(0.0f, 10.0f, -1.0f)); | 238 vertices_b.push_back(gfx::Point3F(0.0f, 10.0f, -1.0f)); |
| 203 vertices_b.push_back(gfx::Point3F(0.0f, 0.0f, -1.0f)); | 239 vertices_b.push_back(gfx::Point3F(0.0f, 0.0f, -1.0f)); |
| 204 vertices_b.push_back(gfx::Point3F(10.0f, 0.0f, -1.0f)); | 240 vertices_b.push_back(gfx::Point3F(10.0f, 0.0f, -1.0f)); |
| 205 vertices_b.push_back(gfx::Point3F(10.0f, 10.0f, -1.0f)); | 241 vertices_b.push_back(gfx::Point3F(10.0f, 10.0f, -1.0f)); |
| 206 gfx::Vector3dF normal(0.0f, 0.0f, 1.0f); | 242 gfx::Vector3dF normal(0.0f, 0.0f, 1.0f); |
| 207 | 243 |
| 208 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, normal, 0); | 244 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, normal, 0); |
| 209 CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, normal, 1); | 245 CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, normal, 1); |
| 210 | 246 |
| 211 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(polygon_b, polygon_a)); | 247 EXPECT_EQ(BSP_BACK, SideCompare(polygon_b, polygon_a)); |
| 212 } | 248 } |
| 213 | 249 |
| 214 // Two quads are definitely not touching and so no split should occur. | 250 // Two quads are definitely not touching and so no split should occur. |
| 215 TEST(DrawPolygonSplitTest, NotClearlyInFront) { | 251 TEST(DrawPolygonSplitTest, NotClearlyInFront) { |
| 216 std::vector<gfx::Point3F> vertices_a; | 252 std::vector<gfx::Point3F> vertices_a; |
| 217 vertices_a.push_back(gfx::Point3F(87.2f, 1185.0f, 0.9f)); | 253 vertices_a.push_back(gfx::Point3F(87.2f, 1185.0f, 0.9f)); |
| 218 vertices_a.push_back(gfx::Point3F(288.3f, 1185.0f, -0.7f)); | 254 vertices_a.push_back(gfx::Point3F(288.3f, 1185.0f, -0.7f)); |
| 219 vertices_a.push_back(gfx::Point3F(288.3f, 1196.0f, -0.7f)); | 255 vertices_a.push_back(gfx::Point3F(288.3f, 1196.0f, -0.7f)); |
| 220 vertices_a.push_back(gfx::Point3F(87.2f, 1196.0f, 0.9f)); | 256 vertices_a.push_back(gfx::Point3F(87.2f, 1196.0f, 0.9f)); |
| 221 gfx::Vector3dF normal_a = gfx::CrossProduct(vertices_a[1] - vertices_a[0], | 257 gfx::Vector3dF normal_a = gfx::CrossProduct(vertices_a[1] - vertices_a[0], |
| 222 vertices_a[1] - vertices_a[2]); | 258 vertices_a[1] - vertices_a[2]); |
| 223 normal_a.Scale(1.0f / normal_a.Length()); | 259 normal_a.Scale(1.0f / normal_a.Length()); |
| 224 | 260 |
| 225 std::vector<gfx::Point3F> vertices_b; | 261 std::vector<gfx::Point3F> vertices_b; |
| 226 vertices_b.push_back(gfx::Point3F(62.1f, 1034.7f, 1.0f)); | 262 vertices_b.push_back(gfx::Point3F(62.1f, 1034.7f, 1.0f)); |
| 227 vertices_b.push_back(gfx::Point3F(313.4f, 1035.3f, -1.0f)); | 263 vertices_b.push_back(gfx::Point3F(313.4f, 1035.3f, -1.0f)); |
| 228 vertices_b.push_back(gfx::Point3F(313.4f, 1196.0f, -1.0f)); | 264 vertices_b.push_back(gfx::Point3F(313.4f, 1196.0f, -1.0f)); |
| 229 vertices_b.push_back(gfx::Point3F(62.1f, 1196.0f, 1.0f)); | 265 vertices_b.push_back(gfx::Point3F(62.1f, 1196.0f, 1.0f)); |
| 230 gfx::Vector3dF normal_b = gfx::CrossProduct(vertices_b[1] - vertices_b[0], | 266 gfx::Vector3dF normal_b = gfx::CrossProduct(vertices_b[1] - vertices_b[0], |
| 231 vertices_b[1] - vertices_b[2]); | 267 vertices_b[1] - vertices_b[2]); |
| 232 normal_b.Scale(1.0f / normal_b.Length()); | 268 normal_b.Scale(1.0f / normal_b.Length()); |
| 233 | 269 |
| 234 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, normal_a, 0); | 270 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, normal_a, 0); |
| 235 CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, normal_b, 1); | 271 CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, normal_b, 1); |
| 236 | 272 |
| 237 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(polygon_b, polygon_a)); | 273 EXPECT_EQ(BSP_FRONT, SideCompare(polygon_b, polygon_a)); |
| 238 } | 274 } |
| 239 | 275 |
| 240 // Two quads are definitely not touching and so no split should occur. | 276 // Two quads are definitely not touching and so no split should occur. |
| 241 TEST(DrawPolygonSplitTest, NotTouchingNoSplit) { | 277 TEST(DrawPolygonSplitTest, NotTouchingNoSplit) { |
| 242 std::vector<gfx::Point3F> vertices_a; | 278 std::vector<gfx::Point3F> vertices_a; |
| 243 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); | 279 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); |
| 244 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); | 280 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); |
| 245 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); | 281 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); |
| 246 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); | 282 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); |
| 247 std::vector<gfx::Point3F> vertices_b; | 283 std::vector<gfx::Point3F> vertices_b; |
| 248 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); | 284 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); |
| 249 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 15.0f)); | 285 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 15.0f)); |
| 250 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f)); | 286 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 15.0f)); |
| 251 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f)); | 287 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f)); |
| 252 | 288 |
| 253 CREATE_NEW_DRAW_POLYGON( | 289 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, |
| 254 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); | 290 gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); |
| 255 CREATE_NEW_DRAW_POLYGON( | 291 CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, |
| 256 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); | 292 gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); |
| 257 | 293 |
| 258 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(polygon_b, polygon_a)); | 294 EXPECT_EQ(BSP_FRONT, SideCompare(polygon_b, polygon_a)); |
| 259 } | 295 } |
| 260 | 296 |
| 261 // One quad is resting against another, but doesn't cross its plane so no split | 297 // One quad is resting against another, but doesn't cross its plane so no |
| 298 // split |
| 262 // should occur. | 299 // should occur. |
| 263 TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) { | 300 TEST(DrawPolygonSplitTest, BarelyTouchingNoSplit) { |
| 264 std::vector<gfx::Point3F> vertices_a; | 301 std::vector<gfx::Point3F> vertices_a; |
| 265 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); | 302 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); |
| 266 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); | 303 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); |
| 267 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); | 304 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); |
| 268 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); | 305 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); |
| 269 std::vector<gfx::Point3F> vertices_b; | 306 std::vector<gfx::Point3F> vertices_b; |
| 270 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); | 307 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); |
| 271 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, -10.0f)); | 308 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, -10.0f)); |
| 272 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f)); | 309 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -10.0f)); |
| 273 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f)); | 310 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f)); |
| 274 | 311 |
| 275 CREATE_NEW_DRAW_POLYGON( | 312 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, |
| 276 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); | 313 gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); |
| 277 CREATE_NEW_DRAW_POLYGON( | 314 CREATE_NEW_DRAW_POLYGON(polygon_b, vertices_b, |
| 278 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); | 315 gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); |
| 279 | 316 |
| 280 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(polygon_b, polygon_a)); | 317 EXPECT_EQ(BSP_BACK, SideCompare(polygon_b, polygon_a)); |
| 281 } | 318 } |
| 282 | 319 |
| 283 // One quad intersects another and becomes two pieces. | 320 // One quad intersects another and becomes two pieces. |
| 284 TEST(DrawPolygonSplitTest, BasicSplit) { | 321 TEST(DrawPolygonSplitTest, BasicSplit) { |
| 285 std::vector<gfx::Point3F> vertices_a; | 322 std::vector<gfx::Point3F> vertices_a; |
| 286 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); | 323 vertices_a.push_back(gfx::Point3F(0.0f, 10.0f, 0.0f)); |
| 287 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); | 324 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); |
| 288 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); | 325 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); |
| 289 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); | 326 vertices_a.push_back(gfx::Point3F(10.0f, 10.0f, 0.0f)); |
| 290 std::vector<gfx::Point3F> vertices_b; | 327 std::vector<gfx::Point3F> vertices_b; |
| 291 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, -5.0f)); | 328 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, -5.0f)); |
| 292 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -5.0f)); | 329 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, -5.0f)); |
| 293 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f)); | 330 vertices_b.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f)); |
| 294 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); | 331 vertices_b.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); |
| 295 | 332 |
| 296 CREATE_NEW_DRAW_POLYGON( | 333 CREATE_NEW_DRAW_POLYGON_PTR(polygon_a, vertices_a, |
| 297 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); | 334 gfx::Vector3dF(0.0f, 0.0f, 1.0f), 0); |
| 298 CREATE_NEW_DRAW_POLYGON( | 335 CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b, |
| 299 polygon_b, vertices_b, gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); | 336 gfx::Vector3dF(-1.0f, 0.0f, 0.0f), 1); |
| 300 | |
| 301 EXPECT_EQ(BSP_SPLIT, DrawPolygon::SideCompare(polygon_b, polygon_a)); | |
| 302 | 337 |
| 303 std::unique_ptr<DrawPolygon> front_polygon; | 338 std::unique_ptr<DrawPolygon> front_polygon; |
| 304 std::unique_ptr<DrawPolygon> back_polygon; | 339 std::unique_ptr<DrawPolygon> back_polygon; |
| 305 polygon_b.Split(polygon_a, &front_polygon, &back_polygon); | 340 bool is_coplanar; |
| 306 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(*front_polygon, polygon_a)); | 341 |
| 307 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(*back_polygon, polygon_a)); | 342 polygon_a->SplitPolygon(std::move(polygon_b), &front_polygon, &back_polygon, |
| 343 &is_coplanar); |
| 344 EXPECT_FALSE(is_coplanar); |
| 345 EXPECT_TRUE(front_polygon != nullptr); |
| 346 EXPECT_TRUE(back_polygon != nullptr); |
| 308 | 347 |
| 309 std::vector<gfx::Point3F> test_points_a; | 348 std::vector<gfx::Point3F> test_points_a; |
| 310 test_points_a.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f)); | 349 test_points_a.push_back(gfx::Point3F(5.0f, 0.0f, 0.0f)); |
| 311 test_points_a.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f)); | 350 test_points_a.push_back(gfx::Point3F(5.0f, 0.0f, 5.0f)); |
| 312 test_points_a.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); | 351 test_points_a.push_back(gfx::Point3F(5.0f, 10.0f, 5.0f)); |
| 313 test_points_a.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); | 352 test_points_a.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); |
| 314 std::vector<gfx::Point3F> test_points_b; | 353 std::vector<gfx::Point3F> test_points_b; |
| 315 test_points_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); | 354 test_points_b.push_back(gfx::Point3F(5.0f, 10.0f, 0.0f)); |
| 316 test_points_b.push_back(gfx::Point3F(5.0f, 10.0f, -5.0f)); | 355 test_points_b.push_back(gfx::Point3F(5.0f, 10.0f, -5.0f)); |
| 317 test_points_b.push_back(gfx::Point3F(5.0f, 0.0f, -5.0f)); | 356 test_points_b.push_back(gfx::Point3F(5.0f, 0.0f, -5.0f)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 330 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); | 369 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); |
| 331 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f)); | 370 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f)); |
| 332 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f)); | 371 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f)); |
| 333 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); | 372 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); |
| 334 std::vector<gfx::Point3F> vertices_b; | 373 std::vector<gfx::Point3F> vertices_b; |
| 335 vertices_b.push_back(gfx::Point3F(2.0f, 5.0f, 1.0f)); | 374 vertices_b.push_back(gfx::Point3F(2.0f, 5.0f, 1.0f)); |
| 336 vertices_b.push_back(gfx::Point3F(2.0f, -5.0f, 1.0f)); | 375 vertices_b.push_back(gfx::Point3F(2.0f, -5.0f, 1.0f)); |
| 337 vertices_b.push_back(gfx::Point3F(-1.0f, -5.0f, -2.0f)); | 376 vertices_b.push_back(gfx::Point3F(-1.0f, -5.0f, -2.0f)); |
| 338 vertices_b.push_back(gfx::Point3F(-1.0f, 5.0f, -2.0f)); | 377 vertices_b.push_back(gfx::Point3F(-1.0f, 5.0f, -2.0f)); |
| 339 | 378 |
| 340 CREATE_NEW_DRAW_POLYGON( | 379 CREATE_NEW_DRAW_POLYGON_PTR(polygon_a, vertices_a, |
| 341 polygon_a, vertices_a, gfx::Vector3dF(0.0f, 1.0f, 0.0f), 0); | 380 gfx::Vector3dF(0.0f, 1.0f, 0.0f), 0); |
| 342 CREATE_NEW_DRAW_POLYGON( | 381 CREATE_NEW_DRAW_POLYGON_PTR(polygon_b, vertices_b, |
| 343 polygon_b, vertices_b, gfx::Vector3dF(0.707107f, 0.0f, -0.707107f), 1); | 382 gfx::Vector3dF(0.707107f, 0.0f, -0.707107f), 1); |
| 344 | |
| 345 EXPECT_EQ(BSP_SPLIT, DrawPolygon::SideCompare(polygon_a, polygon_b)); | |
| 346 | 383 |
| 347 std::unique_ptr<DrawPolygon> front_polygon; | 384 std::unique_ptr<DrawPolygon> front_polygon; |
| 348 std::unique_ptr<DrawPolygon> back_polygon; | 385 std::unique_ptr<DrawPolygon> back_polygon; |
| 349 polygon_a.Split(polygon_b, &front_polygon, &back_polygon); | 386 bool is_coplanar; |
| 350 EXPECT_EQ(BSP_FRONT, DrawPolygon::SideCompare(*front_polygon, polygon_b)); | |
| 351 EXPECT_EQ(BSP_BACK, DrawPolygon::SideCompare(*back_polygon, polygon_b)); | |
| 352 | 387 |
| 353 EXPECT_EQ(3u, front_polygon->points().size()); | 388 polygon_b->SplitPolygon(std::move(polygon_a), &front_polygon, &back_polygon, |
| 354 EXPECT_EQ(5u, back_polygon->points().size()); | 389 &is_coplanar); |
| 390 EXPECT_FALSE(is_coplanar); |
| 391 EXPECT_TRUE(front_polygon != nullptr); |
| 392 EXPECT_TRUE(back_polygon != nullptr); |
| 355 | 393 |
| 356 std::vector<gfx::Point3F> test_points_a; | 394 std::vector<gfx::Point3F> test_points_a; |
| 357 test_points_a.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f)); | 395 test_points_a.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f)); |
| 358 test_points_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); | 396 test_points_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); |
| 359 test_points_a.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f)); | 397 test_points_a.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f)); |
| 360 std::vector<gfx::Point3F> test_points_b; | 398 std::vector<gfx::Point3F> test_points_b; |
| 361 test_points_b.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f)); | 399 test_points_b.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f)); |
| 362 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); | 400 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); |
| 363 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f)); | 401 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f)); |
| 364 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f)); | 402 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f)); |
| 365 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f)); | 403 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f)); |
| 366 | 404 |
| 367 ValidatePoints(*(front_polygon.get()), test_points_a); | 405 ValidatePointsWithinDeltaOf(*(front_polygon.get()), test_points_a, 1e-6f); |
| 368 ValidatePoints(*(back_polygon.get()), test_points_b); | 406 ValidatePointsWithinDeltaOf(*(back_polygon.get()), test_points_b, 1e-6f); |
| 369 } | 407 } |
| 370 | 408 |
| 371 TEST(DrawPolygonTransformTest, TransformNormal) { | 409 TEST(DrawPolygonTransformTest, TransformNormal) { |
| 372 std::vector<gfx::Point3F> vertices_a; | 410 std::vector<gfx::Point3F> vertices_a; |
| 373 vertices_a.push_back(gfx::Point3F(1.0f, 0.0f, 1.0f)); | 411 vertices_a.push_back(gfx::Point3F(1.0f, 0.0f, 1.0f)); |
| 374 vertices_a.push_back(gfx::Point3F(-1.0f, 0.0f, -1.0f)); | 412 vertices_a.push_back(gfx::Point3F(-1.0f, 0.0f, -1.0f)); |
| 375 vertices_a.push_back(gfx::Point3F(0.0f, 1.0f, 0.0f)); | 413 vertices_a.push_back(gfx::Point3F(0.0f, 1.0f, 0.0f)); |
| 376 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, | 414 CREATE_NEW_DRAW_POLYGON(polygon_a, vertices_a, |
| 377 gfx::Vector3dF(sqrt(2) / 2, 0.0f, -sqrt(2) / 2), 0); | 415 gfx::Vector3dF(sqrt(2) / 2, 0.0f, -sqrt(2) / 2), 0); |
| 378 EXPECT_NORMAL(polygon_a, sqrt(2) / 2, 0.0f, -sqrt(2) / 2); | 416 EXPECT_NORMAL(polygon_a, sqrt(2) / 2, 0.0f, -sqrt(2) / 2); |
| 379 | 417 |
| 380 gfx::Transform transform; | 418 gfx::Transform transform; |
| 381 transform.RotateAboutYAxis(45.0f); | 419 transform.RotateAboutYAxis(45.0f); |
| 382 // This would transform the vertices as well, but we are transforming a | 420 // This would transform the vertices as well, but we are transforming a |
| 383 // DrawPolygon with 0 vertices just to make sure our normal transformation | 421 // DrawPolygon with 0 vertices just to make sure our normal transformation |
| 384 // using the inverse tranpose matrix gives us the right result. | 422 // using the inverse tranpose matrix gives us the right result. |
| 385 polygon_a.TransformToScreenSpace(transform); | 423 polygon_a.TransformToScreenSpace(transform); |
| 386 | 424 |
| 387 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here | 425 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here |
| 388 // because some architectures (e.g., Arm64) employ a fused multiply-add | 426 // because some architectures (e.g., Arm64) employ a fused multiply-add |
| 389 // instruction which causes rounding asymmetry and reduces precision. | 427 // instruction which causes rounding asymmetry and reduces precision. |
| 390 // http://crbug.com/401117. | 428 // http://crbug.com/401117. |
| 391 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f); | 429 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f); |
| 392 } | 430 } |
| 393 | 431 |
| 394 } // namespace | 432 } // namespace |
| 395 } // namespace cc | 433 } // namespace cc |
| OLD | NEW |