@@ -141,38 +141,6 @@ TEST(GeometryTest, QuaternionLerp) {
141141 ASSERT_QUATERNION_NEAR (q3, expected);
142142}
143143
144- TEST (GeometryTest, RectWithPoint) {
145- auto rect = Rect{};
146-
147- auto expected = Rect{};
148-
149- ASSERT_RECT_NEAR (rect, expected);
150-
151- rect = rect.WithPoint ({100 , 100 });
152- expected = Rect{0 , 0 , 100 , 100 };
153- ASSERT_RECT_NEAR (rect, expected);
154-
155- rect = rect.WithPoint ({-11 , -12 });
156- expected = Rect{-11 , -12 , 111 , 112 };
157- ASSERT_RECT_NEAR (rect, expected);
158-
159- rect = rect.WithPoint ({55 , 65 });
160- expected = Rect{-11 , -12 , 111 , 112 };
161- ASSERT_RECT_NEAR (rect, expected);
162-
163- rect = rect.WithPoint ({-25 , 0 });
164- expected = Rect{-25 , -12 , 125 , 112 };
165- ASSERT_RECT_NEAR (rect, expected);
166-
167- rect = rect.WithPoint ({0 , -25 });
168- expected = Rect{-25 , -25 , 125 , 125 };
169- ASSERT_RECT_NEAR (rect, expected);
170-
171- rect = rect.WithPoint ({125 , 135 });
172- expected = Rect{-25 , -25 , 150 , 160 };
173- ASSERT_RECT_NEAR (rect, expected);
174- }
175-
176144TEST (GeometryTest, SimplePath) {
177145 Path path;
178146
@@ -216,7 +184,7 @@ TEST(GeometryTest, BoundingBoxCubic) {
216184 Path path;
217185 path.AddCubicComponent ({120 , 160 }, {25 , 200 }, {220 , 260 }, {220 , 40 });
218186 auto box = path.GetBoundingBox ();
219- Rect expected (0 , 0 , 220 , 198 .862 );
187+ Rect expected (93.9101 , 40 , 126.09 , 158 .862 );
220188 ASSERT_RECT_NEAR (box, expected);
221189}
222190
@@ -225,7 +193,7 @@ TEST(GeometryTest, BoundingBoxOfCompositePathIsCorrect) {
225193 builder.AddRoundedRect ({{10 , 10 }, {300 , 300 }}, {50 , 50 , 50 , 50 });
226194 auto path = builder.CreatePath ();
227195 auto actual = path.GetBoundingBox ();
228- Rect expected (0 , 0 , 310 , 310 );
196+ Rect expected (10 , 10 , 300 , 300 );
229197 ASSERT_RECT_NEAR (actual, expected);
230198}
231199
@@ -273,5 +241,72 @@ TEST(GeometryTest, CanConvertBetweenDegressAndRadians) {
273241 }
274242}
275243
244+ TEST (GeometryTest, RectUnion) {
245+ {
246+ Rect a (100 , 100 , 100 , 100 );
247+ Rect b (0 , 0 , 0 , 0 );
248+ auto u = a.Union (b);
249+ auto expected = Rect (0 , 0 , 200 , 200 );
250+ ASSERT_RECT_NEAR (u, expected);
251+ }
252+
253+ {
254+ Rect a (100 , 100 , 100 , 100 );
255+ Rect b (10 , 10 , 0 , 0 );
256+ auto u = a.Union (b);
257+ auto expected = Rect (10 , 10 , 190 , 190 );
258+ ASSERT_RECT_NEAR (u, expected);
259+ }
260+
261+ {
262+ Rect a (0 , 0 , 100 , 100 );
263+ Rect b (10 , 10 , 100 , 100 );
264+ auto u = a.Union (b);
265+ auto expected = Rect (0 , 0 , 110 , 110 );
266+ ASSERT_RECT_NEAR (u, expected);
267+ }
268+
269+ {
270+ Rect a (0 , 0 , 100 , 100 );
271+ Rect b (100 , 100 , 100 , 100 );
272+ auto u = a.Union (b);
273+ auto expected = Rect (0 , 0 , 200 , 200 );
274+ ASSERT_RECT_NEAR (u, expected);
275+ }
276+ }
277+
278+ TEST (GeometryTest, RectIntersection) {
279+ {
280+ Rect a (100 , 100 , 100 , 100 );
281+ Rect b (0 , 0 , 0 , 0 );
282+
283+ auto u = a.Intersection (b);
284+ ASSERT_FALSE (u.has_value ());
285+ }
286+
287+ {
288+ Rect a (100 , 100 , 100 , 100 );
289+ Rect b (10 , 10 , 0 , 0 );
290+ auto u = a.Intersection (b);
291+ ASSERT_FALSE (u.has_value ());
292+ }
293+
294+ {
295+ Rect a (0 , 0 , 100 , 100 );
296+ Rect b (10 , 10 , 100 , 100 );
297+ auto u = a.Intersection (b);
298+ ASSERT_TRUE (u.has_value ());
299+ auto expected = Rect (10 , 10 , 90 , 90 );
300+ ASSERT_RECT_NEAR (u.value (), expected);
301+ }
302+
303+ {
304+ Rect a (0 , 0 , 100 , 100 );
305+ Rect b (100 , 100 , 100 , 100 );
306+ auto u = a.Intersection (b);
307+ ASSERT_FALSE (u.has_value ());
308+ }
309+ }
310+
276311} // namespace testing
277312} // namespace impeller
0 commit comments