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