Skip to content

Commit bfd7877

Browse files
authored
Merge pull request #44 from plut/minkowski
Added functions for Minkowski sum and difference
2 parents 2fc9002 + 6c84cb9 commit bfd7877

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Clipper.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export PolyType, PolyTypeSubject, PolyTypeClip, ClipType, ClipTypeIntersection,
99
EndTypeClosedLine, EndTypeOpenSquare, EndTypeOpenRound, EndTypeOpenButt, Clip,
1010
add_path!, add_paths!, execute, clear!, get_bounds, IntPoint, IntRect, orientation,
1111
area, pointinpolygon, ClipperOffset, PolyNode, execute_pt, contour, ishole, contour,
12-
children, tofloat
12+
children, tofloat, minkowski_sum, minkowski_difference
1313

1414
@enum PolyType PolyTypeSubject = 0 PolyTypeClip = 1
1515

@@ -296,4 +296,26 @@ function simplify_polygons(polys::Vector{Vector{IntPoint}},
296296
return simplified
297297
end
298298

299+
function minkowski_sum(poly1::Vector{IntPoint}, poly2::Vector{IntPoint},
300+
is_closed::Bool = true)
301+
polys = Vector{Vector{IntPoint}}()
302+
@ccall libcclipper.minkowski_sum(
303+
poly1::Ptr{IntPoint}, length(poly1)::Csize_t,
304+
poly2::Ptr{IntPoint}, length(poly2)::Csize_t,
305+
polys::Any,
306+
@cfunction(append_poly!, Any, (Ptr{Cvoid}, Csize_t, IntPoint))::Ptr{Cvoid},
307+
is_closed::Cuchar)::Cvoid
308+
return polys
309+
end
310+
function minkowski_difference(poly1::Vector{IntPoint}, poly2::Vector{IntPoint})
311+
polys = Vector{Vector{IntPoint}}()
312+
@ccall libcclipper.minkowski_difference(
313+
poly1::Ptr{IntPoint}, length(poly1)::Csize_t,
314+
poly2::Ptr{IntPoint}, length(poly2)::Csize_t,
315+
polys::Any,
316+
@cfunction(append_poly!, Any, (Ptr{Cvoid}, Csize_t, IntPoint))::Ptr{Cvoid})::Cvoid
317+
return polys
318+
end
319+
320+
299321
end

test/clipper_test.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,9 @@ test("IntPoint to floating point") do
384384
@test tofloat(point, 3, 4) == (1324.5, 34)
385385
@test tofloat(point, -4, 4) == (0.00013245, 0.0000034)
386386
end
387+
388+
test("Minkowski sum") do
389+
tri = [IntPoint(0,0), IntPoint(10,0), IntPoint(0,20)]
390+
@test minkowski_sum(tri,tri) ==
391+
[[IntPoint(0,0), IntPoint(20,0), IntPoint(0,40)]]
392+
end

0 commit comments

Comments
 (0)