Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ The format of this changelog is based on

- `isapprox` on arrays of `Point`s, and so on `Polygon`s, returns `false` when the
arrays differ in size. Previously it compared only the elements both arrays have, so
an empty array was approximately equal to any other. (#300)
an empty array was approximately equal to any other.
- `==` and `isapprox` on `ClippedPolygon`s return `false` when the polygon trees have
different numbers of children at any level, such as an extra disjoint shape or an extra
hole. Previously, extra children on either side were ignored.
- Schematic `render!` to a `Cell` or a `SolidModel` with `strict=:no` logs a component
whose geometry fails to build and renders it as empty geometry, instead of throwing.
(#287)
Expand Down
2 changes: 2 additions & 0 deletions src/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ ClippedPolygon{T}(x::Clipper.PolyNode{Point}) where {T} =
function ==(p1::ClippedPolygon, p2::ClippedPolygon)
function children_equal(l, r)
# recursively check contours of all children in the tree
length(Clipper.children(l)) == length(Clipper.children(r)) || return false
for (x, y) in zip(Clipper.children(l), Clipper.children(r))
(!circularequality(x.contour, y.contour) || !children_equal(x, y)) &&
return false
Expand All @@ -449,6 +450,7 @@ end
function isapprox(p1::ClippedPolygon, p2::ClippedPolygon; kwargs...)
function children_approx(l, r)
# recursively check contours of all children in the tree
length(Clipper.children(l)) == length(Clipper.children(r)) || return false
for (x, y) in zip(Clipper.children(l), Clipper.children(r))
(!circularapprox(x.contour, y.contour; kwargs...) || !children_approx(x, y)) &&
return false
Expand Down
17 changes: 17 additions & 0 deletions test/test_clipping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,23 @@
@test d2 == difference2d(d2, [d1])
@test d2 == difference2d([d2], d1)
@test d2 == difference2d([d2], [d1])

# Trees with different numbers of children, at the top level or below, are unequal
sq = Rectangle(T(10), T(10))
a = union2d(sq)
b = union2d([sq, Rectangle(Point(T(20), T(0)), Point(T(30), T(10)))])
hole = Rectangle(Point(T(2), T(2)), Point(T(8), T(8)))
holed = difference2d(sq, hole)
e = intersect2d(d1, d2) # empty
for (p, q) in ((a, b), (a, holed), (a, e))
@test p != q
@test q != p
@test !isapprox(p, q)
@test !isapprox(q, p)
end
@test a == union2d(sq)
@test holed ≈ difference2d(sq, hole)
@test e == intersect2d(r1, r2 + Point(T(5), T(5)))
end

r1 = Rectangle(2, 2)
Expand Down
Loading