Skip to content

Commit 785d940

Browse files
committed
polys
1 parent a7fba75 commit 785d940

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/primitives/rectangles.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,7 @@ end
526526

527527
function coordinates(rect::Rect2, nvertices=(2, 2))
528528
mini, maxi = extrema(rect)
529-
xrange, yrange = LinRange.(mini, maxi, nvertices)
530-
return ivec(((x, y) for x in xrange, y in yrange))
529+
return [mini, Point(mini[1], maxi[2]), maxi, Point(maxi[1], mini[2])]
531530
end
532531

533532
function texturecoordinates(rect::Rect2, nvertices=(2, 2))

test/polygons.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@testset "Polygon" begin
2+
@testset "from points" begin
3+
points = connect([1, 2, 3, 4, 5, 6], PointPoint2f(2))
4+
polygon = Polygon(points)
5+
@test polygon == Polygon(points)
6+
end
7+
8+
end
9+
10+
rect = Rect2f(0, 0, 1, 1)
11+
hole = Circle(Point2f(0.5), 0.2)
12+
poly2 = Polygon(decompose(Point2f, rect), [decompose(Point2f, hole)])
13+
poly1 = Polygon(rect, [hole])
14+
@test poly1 == poly2
15+
@test poly.exterior == decompose(Point2f, rect)
16+
@test poly.interiors == [decompose(Point2f, hole)]
17+
18+
faces(poly1)
19+
20+
GeometryBasics.earcut_triangulate([poly.exterior[[1, 2, 3, 4, 1]]])
21+
22+
poly = [
23+
[Point2f(100, 0), Point2f(100, 100), Point2f(0, 100), Point2f(0, 0)],
24+
# Following polylines define holes.
25+
[Point2f(75, 25), Point2f(75, 75), Point2f(25, 75), Point2f(25, 25)]
26+
]
27+
28+
GeometryBasics.earcut_triangulate(poly)

test/runtests.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,6 @@ end
113113
end
114114

115115
@testset "constructors" begin
116-
@testset "Polygon" begin
117-
points = connect([1, 2, 3, 4, 5, 6], Point{2})
118-
polygon = Polygon(points)
119-
@test polygon == Polygon(points)
120-
end
121-
122116
@testset "Mesh" begin
123117
numbers = [1, 2, 3, 4, 5, 6]
124118
points = connect(numbers, Point{2})

0 commit comments

Comments
 (0)