Clipper
Bindings to the Clipper2 polygon clipping library
module type V = sig ... end
Signature of a 2d vector type to be used to represent points for the construction and destruction of Clipper2 path types
module type Poly = sig ... end
Signature of a polygon type -- an outer path and zero or more inner paths (holes). To be used for construction and destruction of Clipper2 paths types.
type clip_type = [
|
`None
|
`Intersection
AND -- regions covered by both subject and clip polygons
*)|
`Union
OR -- regions covered by subject or clip polygons, or both polygons
*)|
`Difference
NOT -- regions covered by subject, but not clip polygons
*)|
`Xor
exclusive or -- regions covered by subject or clip polygons, but not both
*) ]
Clipping types for boolean operations. See Clipper2's docs for visual demonstrations.
type fill_rule = [
|
`EvenOdd
only odd numbered sub-regions are filled
*)|
`NonZero
non-zero sub-regions are filled
*)|
`Positive
only sub-regions with winding counts > 0
are filled
|
`Negative
only sub-regions with winding counts < 0
are filled
]
Filling rules used by the clipping algorithm for boolean operations. See Clipper2's docs for a detailed explanation of how they differ).
type join_type = [
|
`Square
squaring applied uniformally at all joins where the internal join angle is less than 90 degrees. The squared edg will be at exactly the offset distance from the join vertex
*)|
`Round
rounding is appliedto all joins that have convex external angles, and it maintains the exact offset distance from the join vertex
*)|
`Miter
there's a necessary limit to mitered joins (to avoid narrow angled joins producing excessively long and narrow spikes)). The limit sets the maximum distance in multiples of the delta
specified for the offsetting operation (default is 2.
, which is the minimum allowed).
]
Defines the treatment of corners when offsetting paths. Visual examples are available in the Clipper2 docs.
type end_type = [
|
`Polygon
paths are assumed to be closed and treated as polygons
*)|
`Joined
ends are joined and the paths are treated as polylines
*)|
`Butt
ends are squared off without any extrusion
*)|
`Square
ends extend the offset amount while being squared off
*)|
`Round
ends extend the offset amount while being rounded off
*) ]
Sets whether paths are treated as closed (`Polygon
) when offsetting or open (and how to do so, if so). Visual examples are available in the Clipper2 docs.
module type Config = sig ... end
Configuration parameters allowing user control Clipper2 interface defaults
val config :
?fill_rule:fill_rule ->
?join_type:join_type ->
?end_type:end_type ->
?precision:int ->
?eps:float ->
unit ->
(module Config)
config ?fill_rule ?join_type ?end_type ?precision ?eps ()
Construct a Config
functor argument to set defaults appropriate to your use case.
MakeD (V) ((val config ()))
fill_rule
sets the default filling rule used by the clipping algorithm used for boolean operations (default is `NonZero
, as used by OpenSCAD).join_type
defines the treatment of corners when offsetting paths (default is `Round
).end_type
sets whether paths are treated as closed (polygons) when offsetting (as with the default `Polygon
) or open (and how to do so, if so).precision
sets the number of decimals of precision used for operations that are performed with int64
internally in Clipper2 (default is 2
, up to 8
is allowed). This is only relevant if using the decimal interface.eps
sets the default epsilon value used for the functions that take it as argument. If not provided, this defaults to the smallest relevant significant figure as determined by precision
in the case of the decimal interface (e.g. 0.01
when precision = 2
), or simply 1
for the int64
interface.module type S = sig ... end
The signature of Clipper2 binding modules produced by the provided Make
functors
module MakeD'
(V : V with type n := float)
(Ctr : sig ... end)
(P : Poly with type v := V.t)
(_ : Config) :
S
with type n := float
and type v := V.t
and type contour := Ctr.t
and type poly := P.t
MakeD' (V) (Ctr) (P) (Conf)
creates a Clipper2 module with the 2d float
vector V
, the contour Ctr
and polygon P
types (composed of V.t
s, used for input/output), and a user configuration (see config
for convenience constructor).
module Make64'
(V : V with type n := int64)
(Ctr : sig ... end)
(P : Poly with type v := V.t)
(_ : Config) :
S
with type n := int64
and type v := V.t
and type contour := Ctr.t
and type poly := P.t
MakeD' (V) (Ctr) (P) (Conf)
creates a Clipper2 module with the 2d int64
vector V
, the contour Ctr
and polygon P
types (composed of V.t
s, used for input/output), and a user configuration (see config
for convenience constructor).