@@ -149,21 +149,21 @@ TEST(GeometryTest, SimplePath) {
149
149
.AddQuadraticComponent ({100 , 100 }, {200 , 200 }, {300 , 300 })
150
150
.AddCubicComponent ({300 , 300 }, {400 , 400 }, {500 , 500 }, {600 , 600 });
151
151
152
- ASSERT_EQ (path.GetComponentCount (), 3u );
152
+ ASSERT_EQ (path.GetComponentCount (), 4u );
153
153
154
154
path.EnumerateComponents (
155
155
[](size_t index , const LinearPathComponent& linear) {
156
156
Point p1 (0 , 0 );
157
157
Point p2 (100 , 100 );
158
- ASSERT_EQ (index , 0u );
158
+ ASSERT_EQ (index , 1u );
159
159
ASSERT_EQ (linear.p1 , p1);
160
160
ASSERT_EQ (linear.p2 , p2);
161
161
},
162
162
[](size_t index , const QuadraticPathComponent& quad) {
163
163
Point p1 (100 , 100 );
164
164
Point cp (200 , 200 );
165
165
Point p2 (300 , 300 );
166
- ASSERT_EQ (index , 1u );
166
+ ASSERT_EQ (index , 2u );
167
167
ASSERT_EQ (quad.p1 , p1);
168
168
ASSERT_EQ (quad.cp , cp);
169
169
ASSERT_EQ (quad.p2 , p2);
@@ -173,13 +173,18 @@ TEST(GeometryTest, SimplePath) {
173
173
Point cp1 (400 , 400 );
174
174
Point cp2 (500 , 500 );
175
175
Point p2 (600 , 600 );
176
- ASSERT_EQ (index , 2u );
176
+ ASSERT_EQ (index , 3u );
177
177
ASSERT_EQ (cubic.p1 , p1);
178
178
ASSERT_EQ (cubic.cp1 , cp1);
179
179
ASSERT_EQ (cubic.cp2 , cp2);
180
180
ASSERT_EQ (cubic.p2 , p2);
181
181
},
182
- [](size_t index , const MovePathComponent& move) { ASSERT_TRUE (false ); });
182
+ [](size_t index , const ContourComponent& contour) {
183
+ Point p1 (0 , 0 );
184
+ ASSERT_EQ (index , 0u );
185
+ ASSERT_EQ (contour.destination , p1);
186
+ ASSERT_FALSE (contour.is_closed );
187
+ });
183
188
}
184
189
185
190
TEST (GeometryTest, BoundingBoxCubic) {
@@ -638,15 +643,15 @@ TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
638
643
639
644
TEST (GeometryTest, PathCreatePolyLineDoesNotDuplicatePoints) {
640
645
Path path;
641
- path.AddMoveComponent ({10 , 10 });
646
+ path.AddContourComponent ({10 , 10 });
642
647
path.AddLinearComponent ({10 , 10 }, {20 , 20 });
643
648
path.AddLinearComponent ({20 , 20 }, {30 , 30 });
644
- path.AddMoveComponent ({40 , 40 });
649
+ path.AddContourComponent ({40 , 40 });
645
650
path.AddLinearComponent ({40 , 40 }, {50 , 50 });
646
651
647
652
auto polyline = path.CreatePolyline ();
648
653
649
- ASSERT_EQ (polyline.breaks .size (), 2u );
654
+ ASSERT_EQ (polyline.contours .size (), 2u );
650
655
ASSERT_EQ (polyline.points .size (), 5u );
651
656
ASSERT_EQ (polyline.points [0 ].x , 10 );
652
657
ASSERT_EQ (polyline.points [1 ].x , 20 );
@@ -655,5 +660,107 @@ TEST(GeometryTest, PathCreatePolyLineDoesNotDuplicatePoints) {
655
660
ASSERT_EQ (polyline.points [4 ].x , 50 );
656
661
}
657
662
663
+ TEST (GeometryTest, PathBuilderSetsCorrectContourPropertiesForAddCommands) {
664
+ // Closed shapes.
665
+ {
666
+ Path path = PathBuilder{}.AddCircle ({100 , 100 }, 50 ).TakePath ();
667
+ ContourComponent contour;
668
+ path.GetContourComponentAtIndex (0 , contour);
669
+ ASSERT_POINT_NEAR (contour.destination , Point (100 , 50 ));
670
+ ASSERT_TRUE (contour.is_closed );
671
+ }
672
+
673
+ {
674
+ Path path = PathBuilder{}.AddOval (Rect (100 , 100 , 100 , 100 )).TakePath ();
675
+ ContourComponent contour;
676
+ path.GetContourComponentAtIndex (0 , contour);
677
+ ASSERT_POINT_NEAR (contour.destination , Point (150 , 100 ));
678
+ ASSERT_TRUE (contour.is_closed );
679
+ }
680
+
681
+ {
682
+ Path path = PathBuilder{}.AddRect (Rect (100 , 100 , 100 , 100 )).TakePath ();
683
+ ContourComponent contour;
684
+ path.GetContourComponentAtIndex (0 , contour);
685
+ ASSERT_POINT_NEAR (contour.destination , Point (100 , 100 ));
686
+ ASSERT_TRUE (contour.is_closed );
687
+ }
688
+
689
+ {
690
+ Path path =
691
+ PathBuilder{}.AddRoundedRect (Rect (100 , 100 , 100 , 100 ), 10 ).TakePath ();
692
+ ContourComponent contour;
693
+ path.GetContourComponentAtIndex (0 , contour);
694
+ ASSERT_POINT_NEAR (contour.destination , Point (110 , 100 ));
695
+ ASSERT_TRUE (contour.is_closed );
696
+ }
697
+
698
+ // Open shapes.
699
+ {
700
+ Point p (100 , 100 );
701
+ Path path = PathBuilder{}.AddLine (p, {200 , 100 }).TakePath ();
702
+ ContourComponent contour;
703
+ path.GetContourComponentAtIndex (0 , contour);
704
+ ASSERT_POINT_NEAR (contour.destination , p);
705
+ ASSERT_FALSE (contour.is_closed );
706
+ }
707
+
708
+ {
709
+ Path path =
710
+ PathBuilder{}
711
+ .AddCubicCurve ({100 , 100 }, {100 , 50 }, {100 , 150 }, {200 , 100 })
712
+ .TakePath ();
713
+ ContourComponent contour;
714
+ path.GetContourComponentAtIndex (0 , contour);
715
+ ASSERT_POINT_NEAR (contour.destination , Point (100 , 100 ));
716
+ ASSERT_FALSE (contour.is_closed );
717
+ }
718
+
719
+ {
720
+ Path path = PathBuilder{}
721
+ .AddQuadraticCurve ({100 , 100 }, {100 , 50 }, {200 , 100 })
722
+ .TakePath ();
723
+ ContourComponent contour;
724
+ path.GetContourComponentAtIndex (0 , contour);
725
+ ASSERT_POINT_NEAR (contour.destination , Point (100 , 100 ));
726
+ ASSERT_FALSE (contour.is_closed );
727
+ }
728
+ }
729
+
730
+ TEST (GeometryTest, PathCreatePolylineGeneratesCorrectContourData) {
731
+ Path::Polyline polyline = PathBuilder{}
732
+ .AddLine ({100 , 100 }, {200 , 100 })
733
+ .MoveTo ({100 , 200 })
734
+ .LineTo ({150 , 250 })
735
+ .LineTo ({200 , 200 })
736
+ .Close ()
737
+ .TakePath ()
738
+ .CreatePolyline ();
739
+ ASSERT_EQ (polyline.points .size (), 6u );
740
+ ASSERT_EQ (polyline.contours .size (), 2u );
741
+ ASSERT_EQ (polyline.contours [0 ].is_closed , false );
742
+ ASSERT_EQ (polyline.contours [0 ].start_index , 0u );
743
+ ASSERT_EQ (polyline.contours [1 ].is_closed , true );
744
+ ASSERT_EQ (polyline.contours [1 ].start_index , 2u );
745
+ }
746
+
747
+ TEST (GeometryTest, PolylineGetContourPointBoundsReturnsCorrectRanges) {
748
+ Path::Polyline polyline = PathBuilder{}
749
+ .AddLine ({100 , 100 }, {200 , 100 })
750
+ .MoveTo ({100 , 200 })
751
+ .LineTo ({150 , 250 })
752
+ .LineTo ({200 , 200 })
753
+ .Close ()
754
+ .TakePath ()
755
+ .CreatePolyline ();
756
+ size_t a1, a2, b1, b2;
757
+ std::tie (a1, a2) = polyline.GetContourPointBounds (0 );
758
+ std::tie (b1, b2) = polyline.GetContourPointBounds (1 );
759
+ ASSERT_EQ (a1, 0u );
760
+ ASSERT_EQ (a2, 2u );
761
+ ASSERT_EQ (b1, 2u );
762
+ ASSERT_EQ (b2, 6u );
763
+ }
764
+
658
765
} // namespace testing
659
766
} // namespace impeller
0 commit comments