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

Side by Side Diff: cc/quads/draw_polygon_unittest.cc

Issue 2714243002: Correct polygon splitting in an almost-coplanar case. (Closed)
Patch Set: Add a unittest. Created 3 years, 9 months 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 unified diff | Download patch
« no previous file with comments | « cc/quads/draw_polygon.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/ptr_util.h"
16 #include "base/stl_util.h"
16 #include "cc/output/bsp_compare_result.h" 17 #include "cc/output/bsp_compare_result.h"
17 #include "cc/quads/draw_polygon.h" 18 #include "cc/quads/draw_polygon.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/transform.h" 20 #include "ui/gfx/transform.h"
20 21
21 namespace cc { 22 namespace cc {
22 23
23 #if !defined(OS_WIN) 24 #if !defined(OS_WIN)
24 void DrawPolygon::RecomputeNormalForTesting() { 25 void DrawPolygon::RecomputeNormalForTesting() {
25 ConstructNormal(); 26 ConstructNormal();
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 test_points_b.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f)); 480 test_points_b.push_back(gfx::Point3F(1.0f, 0.0f, 0.0f));
480 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 481 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
481 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f)); 482 test_points_b.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f));
482 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f)); 483 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f));
483 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f)); 484 test_points_b.push_back(gfx::Point3F(10.0f, 0.0f, 9.0f));
484 485
485 ValidatePointsWithinDeltaOf(*front_polygon, test_points_a, 1e-6f); 486 ValidatePointsWithinDeltaOf(*front_polygon, test_points_a, 1e-6f);
486 ValidatePointsWithinDeltaOf(*back_polygon, test_points_b, 1e-6f); 487 ValidatePointsWithinDeltaOf(*back_polygon, test_points_b, 1e-6f);
487 } 488 }
488 489
490 // This test was derived from crbug.com/693826. An almost coplanar
491 // pair of polygons are used for splitting. In this case, the
492 // splitting plane distance signs are [ 0 0 + - ]. This configuration
493 // represents a case where snapping to the splitting plane causes the
494 // polygon to become twisted. Splitting should still give a valid
enne (OOO) 2017/02/27 17:35:32 I wish more unit tests explained themselves this w
495 // result, indicated by all four of the input split polygon vertices
496 // being present in the output polygons.
497 TEST(DrawPolygonSplitTest, AlmostCoplanarSplit) {
498 std::vector<gfx::Point3F> vertices_a;
499 vertices_a.push_back(gfx::Point3F(723.814758300781250, 552.810119628906250,
500 -206.656036376953125));
501 vertices_a.push_back(gfx::Point3F(797.634155273437500, 549.095703125000000,
502 -209.802902221679688));
503 vertices_a.push_back(gfx::Point3F(799.264648437500000, 490.325805664062500,
504 -172.261627197265625));
505 vertices_a.push_back(gfx::Point3F(720.732421875000000, 493.944458007812500,
506 -168.700469970703125));
507 std::vector<gfx::Point3F> vertices_b;
508 vertices_b.push_back(gfx::Point3F(720.631286621093750, 487.595977783203125,
509 -164.681198120117188));
510 vertices_b.push_back(gfx::Point3F(799.672851562500000, 484.059020996093750,
511 -168.219161987304688));
512 vertices_b.push_back(gfx::Point3F(801.565490722656250, 416.416809082031250,
513 -125.007690429687500));
514 vertices_b.push_back(gfx::Point3F(717.096801757812500, 419.792327880859375,
515 -120.967689514160156));
516
517 CREATE_NEW_DRAW_POLYGON_PTR(
518 splitting_polygon, vertices_a,
519 gfx::Vector3dF(-0.062916249036789, -0.538499474525452,
520 -0.840273618698120),
521 0);
522 CREATE_NEW_DRAW_POLYGON_PTR(split_polygon, vertices_b,
523 gfx::Vector3dF(0.707107f, 0.0f, -0.707107f), 1);
524
525 std::unique_ptr<DrawPolygon> front_polygon;
526 std::unique_ptr<DrawPolygon> back_polygon;
527 bool is_coplanar;
528
529 splitting_polygon->SplitPolygon(std::move(split_polygon), &front_polygon,
530 &back_polygon, &is_coplanar);
531
532 EXPECT_FALSE(is_coplanar);
533 EXPECT_TRUE(front_polygon != nullptr);
534 EXPECT_TRUE(back_polygon != nullptr);
535
536 for (auto vertex : vertices_b) {
537 EXPECT_TRUE(base::ContainsValue(front_polygon->points(), vertex) ||
538 base::ContainsValue(back_polygon->points(), vertex));
539 }
540 }
541
489 // In this test we cut the corner of a quad so that it creates a triangle and 542 // In this test we cut the corner of a quad so that it creates a triangle and
490 // a pentagon as a result, and then cut the pentagon. 543 // a pentagon as a result, and then cut the pentagon.
491 TEST(DrawPolygonSplitTest, DoubleSplit) { 544 TEST(DrawPolygonSplitTest, DoubleSplit) {
492 std::vector<gfx::Point3F> vertices_a; 545 std::vector<gfx::Point3F> vertices_a;
493 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f)); 546 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 0.0f));
494 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f)); 547 vertices_a.push_back(gfx::Point3F(0.0f, 0.0f, 10.0f));
495 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f)); 548 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 10.0f));
496 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f)); 549 vertices_a.push_back(gfx::Point3F(10.0f, 0.0f, 0.0f));
497 std::vector<gfx::Point3F> vertices_b; 550 std::vector<gfx::Point3F> vertices_b;
498 vertices_b.push_back(gfx::Point3F(2.0f, 5.0f, 1.0f)); 551 vertices_b.push_back(gfx::Point3F(2.0f, 5.0f, 1.0f));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 613
561 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here 614 // Note: We use EXPECT_FLOAT_WITHIN_EPSILON instead of EXPECT_FLOAT_EQUAL here
562 // because some architectures (e.g., Arm64) employ a fused multiply-add 615 // because some architectures (e.g., Arm64) employ a fused multiply-add
563 // instruction which causes rounding asymmetry and reduces precision. 616 // instruction which causes rounding asymmetry and reduces precision.
564 // http://crbug.com/401117. 617 // http://crbug.com/401117.
565 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f); 618 EXPECT_NORMAL(polygon_a, 0.0f, 0.0f, -1.0f);
566 } 619 }
567 620
568 } // namespace 621 } // namespace
569 } // namespace cc 622 } // namespace cc
OLDNEW
« 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