55 EXPECT_EQ(arc1->initialPoint(),
Point(5,0));
56 EXPECT_EQ(arc1->finalPoint(),
Point(0,10));
57 EXPECT_EQ(arc1->boundsExact(), Rect::from_xywh(0,0,5,10));
58 EXPECT_EQ(arc1->center(), e.
center());
59 EXPECT_EQ(arc1->largeArc(),
false);
60 EXPECT_EQ(arc1->sweep(),
false);
64 EXPECT_EQ(arc1r->boundsExact(), arc1->boundsExact());
65 EXPECT_EQ(arc1r->sweep(),
true);
66 EXPECT_EQ(arc1r->largeArc(),
false);
70 EXPECT_EQ(arc2->boundsExact(), Rect::from_xywh(0,0,10,20));
71 EXPECT_EQ(arc2->largeArc(),
true);
72 EXPECT_EQ(arc2->sweep(),
true);
76 EXPECT_EQ(arc2r->boundsExact(), arc2->boundsExact());
77 EXPECT_EQ(arc2r->largeArc(),
true);
78 EXPECT_EQ(arc2r->sweep(),
false);
83 EXPECT_EQ(arc3->boundsExact(), Rect::from_xywh(0,0,5,20));
84 EXPECT_EQ(arc3->largeArc(),
false);
85 EXPECT_EQ(arc3->sweep(),
false);
90 EXPECT_EQ(arc4->initialPoint(),
Point(5,0));
91 EXPECT_EQ(arc4->finalPoint(),
Point(0,10));
92 EXPECT_EQ(arc4->boundsExact(), Rect::from_xywh(0,0,5,10));
93 EXPECT_EQ(arc4->largeArc(),
false);
94 EXPECT_EQ(arc4->sweep(),
false);
98 EXPECT_EQ(arc4r->initialPoint(),
Point(0,10));
99 EXPECT_EQ(arc4r->finalPoint(),
Point(5,0));
100 EXPECT_EQ(arc4r->boundsExact(), Rect::from_xywh(0,0,5,10));
101 EXPECT_EQ(arc4r->largeArc(),
false);
102 EXPECT_EQ(arc4r->sweep(),
true);
154TEST(EllipseTest, LineIntersection) {
158 std::vector<ShapeIntersection> xs = e.
intersect(l);
160 ASSERT_EQ(xs.size(), 2ul);
164 EXPECT_NEAR(xs[0].point()[
X], 0, 1e-15);
165 EXPECT_NEAR(xs[0].point()[
Y], -2, 1e-15);
166 EXPECT_NEAR(xs[1].point()[
X], 9./5, 1e-15);
167 EXPECT_NEAR(xs[1].point()[
Y], 8./5, 1e-15);
169 EXPECT_intersections_valid(e, l, xs, 1e-15);
175 g_random_set_seed(0xCAFECAFE);
177 for (
size_t _ = 0; _ < 10'000; _++) {
178 auto line =
Line(
Point(g_random_double_range(-3.0, 3.0), g_random_double_range(-3.0, -1.0)),
179 Point(g_random_double_range(-3.0, 3.0), g_random_double_range(1.0, 3.0)));
180 auto xings =
degen.intersect(line);
181 EXPECT_EQ(xings.size(), 2u);
182 EXPECT_intersections_valid(
degen, line, xings, 1e-14);
185 for (
size_t _ = 0; _ < 10'000; _++) {
186 auto other =
Ellipse(
Point(g_random_double_range(-1.0, 1.0), g_random_double_range(-1.0, 1.0)),
187 Point(g_random_double_range(1.0, 2.0), g_random_double_range(1.0, 3.0)), 0);
188 auto xings =
degen.intersect(other);
189 EXPECT_intersections_valid(
degen, other, xings, 1e-14);
192 for (
size_t _ = 0; _ < 10'000; _++) {
193 auto other =
Ellipse({0, 0}, {1, 1}, 0);
194 other *=
Scale(0.0, g_random_double_range(0.5, 4.0));
195 other *=
Rotate(g_random_double_range(-1.5, 1.5));
196 other *=
Translate(g_random_double_range(-2.9, 2.9), 0.0);
197 auto xings =
degen.intersect(other);
198 EXPECT_EQ(xings.size(), 4u);
199 EXPECT_intersections_valid(
degen, other, xings, 1e-14);
203TEST(EllipseTest, EllipseIntersection) {
206 std::vector<ShapeIntersection> xs;
211 EXPECT_EQ(xs.size(), 4ul);
212 EXPECT_intersections_valid(e1, e2, xs, 4e-10);
217 EXPECT_EQ(xs.size(), 2ul);
218 EXPECT_intersections_valid(e1, e2, xs, 1e-10);
223 EXPECT_EQ(xs.size(), 2ul);
224 EXPECT_intersections_valid(e1, e2, xs, 1e-10);
228 e1.
set({0, 0}, {5, 3}, 0);
229 e2.
set({6, 0}, {1, 2}, 0);
231 ASSERT_GT(xs.size(), 0);
232 EXPECT_intersections_valid(e1, e2, xs, 1e-10);
236 e1.
set({30, 0}, {9, 1}, 0);
237 e2.
set({18, 0}, {3, 2}, 0);
239 ASSERT_GT(xs.size(), 0);
240 EXPECT_intersections_valid(e1, e2, xs, 1e-10);
244 e1.
set({0, 0}, {3, 3}, 0);
245 e2.
set({3, 4}, {2, 2}, 0);
249 ASSERT_GT(xs.size(), 0);
250 EXPECT_intersections_valid(e1, e2, xs, 1e-6);
254 e1.
set({0, 0}, {8, 17}, 0);
255 e2.
set({6, 0}, {2, 1}, 0);
257 ASSERT_GT(xs.size(), 0);
258 EXPECT_intersections_valid(e1, e2, xs, 1e-10);
262 e1.
set({30, 0}, {9, 5}, 0);
263 e2.
set({36, 0}, {3, 1}, 0);
265 ASSERT_GT(xs.size(), 0);
266 EXPECT_intersections_valid(e1, e2, xs, 1e-6);
270 e1.
set({4, 3}, {5, 5}, 0);
271 e2.
set({8, 6}, {10, 10}, 0);
273 ASSERT_GT(xs.size(), 0);
274 EXPECT_intersections_valid(e1, e2, xs, 1e-6);
309TEST(EllipseTest, UnitCircleTransform) {
310 std::vector<Ellipse>
es;
316 for (
auto & e :
es) {
317 EXPECT_near(e.unitCircleTransform() * e.inverseUnitCircleTransform(),
Affine::identity(), 1e-8);
319 for (
Coord t = -1; t < 10; t += 0.25) {
320 Point p = e.pointAt(t);
321 p *= e.inverseUnitCircleTransform();
322 EXPECT_near(p.
length(), 1., 1e-10);
323 p *= e.unitCircleTransform();
324 EXPECT_near(e.pointAt(t), p, 1e-10);