Module Clipper

Bindings to the Clipper2 polygon clipping library

Functor Parameters

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.

Configuration

type clip_type = [
  1. | `None
  2. | `Intersection
    (*

    AND -- regions covered by both subject and clip polygons

    *)
  3. | `Union
    (*

    OR -- regions covered by subject or clip polygons, or both polygons

    *)
  4. | `Difference
    (*

    NOT -- regions covered by subject, but not clip polygons

    *)
  5. | `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 = [
  1. | `EvenOdd
    (*

    only odd numbered sub-regions are filled

    *)
  2. | `NonZero
    (*

    non-zero sub-regions are filled

    *)
  3. | `Positive
    (*

    only sub-regions with winding counts > 0 are filled

    *)
  4. | `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 = [
  1. | `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

    *)
  2. | `Round
    (*

    rounding is appliedto all joins that have convex external angles, and it maintains the exact offset distance from the join vertex

    *)
  3. | `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 = [
  1. | `Polygon
    (*

    paths are assumed to be closed and treated as polygons

    *)
  2. | `Joined
    (*

    ends are joined and the paths are treated as polylines

    *)
  3. | `Butt
    (*

    ends are squared off without any extrusion

    *)
  4. | `Square
    (*

    ends extend the offset amount while being squared off

    *)
  5. | `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.

Clipper Instance

module type S = sig ... end

The signature of Clipper2 binding modules produced by the provided Make functors

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.ts, used for input/output), and a user configuration (see config for convenience constructor).

module MakeD (V : V with type n := float) (_ : Config) : S with type n := float and type v := V.t and type contour := V.t list and type poly := V.t list list

MakeD (V) (C) creates a Clipper2 module with the 2d float vector V, and a user configuration (see config for convenience constructor). Same as MakeD', but the contour and polygon types is preset to use list.

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.ts, used for input/output), and a user configuration (see config for convenience constructor).

module Make64 (V : V with type n := int64) (_ : Config) : S with type n := int64 and type v := V.t and type contour := V.t list and type poly := V.t list list

MakeD (V) (Conf) creates a Clipper2 module with the 2d int64 vector V, and a user configuration (see config for convenience constructor). Same as MakeD', but the contour and polygon type is preset to use list.