Clipper provides OCaml bindings to the Clipper2 polygon clipping (C++) library.
Clipper
-- top level library interface
V
-- 2d vector type (float or int64)Poly
-- polygon (outer path and zero or more inner paths) typeConfig
-- user specifiable defaults (see: config
)Each functor produces instances that adhere to the signature S
. The D
variants take a 2d float vector type in V
, and create bindings to the decimal interface of Clipper2, while the 64
variants do the same but for the int64 interface.
MakeD
-- float
interface to Clipper2MakeD'
-- same, but additionally taking Poly
Make64
-- int64
interface to Clipper2Make64'
-- same, but additionally taking Poly
module C = Clipper.MakeD (struct
type t = float * float
let v x y = x, y
let x t = fst t
let y t = snd t
end)
((val Clipper.config ~fill_rule:`EvenOdd ()))
let ex =
let a = [ 0., 0.; 10., 0.; 10., 10.; 0., 10. ] in
let b = List.map (fun (x, y) -> x +. 5., y +. 5.) a in
C.(contour @@ difference (path a) ([ path b ]))
In addition to the the higher level abstraction provided by the main library, the sub-librarys clipper.c
and clipper.clpr
are provided to enable lower-level access to the underlying C API.