Skip to content

Commit d358a7e

Browse files
committed
test quad primitive expand
1 parent e260bcc commit d358a7e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/scenic/primitive/quad_test.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,35 @@ defmodule Scenic.Primitive.QuadTest do
8181
assert Quad.contains_point?(@convex, {400, 520}) == false
8282
assert Quad.contains_point?(@convex, {100, 520}) == false
8383
end
84+
85+
86+
# ============================================================================
87+
# expand
88+
89+
# only works if it is square...
90+
defp quad_square_area({{x0,y0}, {x1,y1}, {x2,y2}, {x3,y3}}) do
91+
w = abs(x1 - x0) * 1.0
92+
h = abs(y2 - y0) * 1.0
93+
w * h
94+
end
95+
96+
test "expand clockwise works" do
97+
quad = {{10,10}, {20,10}, {20,20}, {10,20}}
98+
expanded = Quad.expand(quad, 2)
99+
shrunk = Quad.expand(quad, -2)
100+
101+
assert quad_square_area(expanded) > quad_square_area(quad)
102+
assert quad_square_area(shrunk) < quad_square_area(quad)
103+
end
104+
105+
test "expand counter-clockwise works" do
106+
quad = {{10,20}, {20,20}, {20,10}, {10,10}}
107+
expanded = Quad.expand(quad, 2)
108+
shrunk = Quad.expand(quad, -2)
109+
110+
assert quad_square_area(expanded) > quad_square_area(quad)
111+
assert quad_square_area(shrunk) < quad_square_area(quad)
112+
end
113+
114+
84115
end

0 commit comments

Comments
 (0)