Module Gg_kit.Ring2

2D linear rings.

Linear rings are closed lists of straight segments. They may self-intersect.

Rings are oriented using the right-hand rule. Counterclockwise rings bound a positive surface and clockwise ones a negative one (holes).

Rings may self-interesect and be degenerate when made of less than three points.

Linear rings

type t

The type for linear rings.

val of_pts : Gg.P2.t list -> t

of_pts pts is a linear ring defined by points pts. Any two consecutive points of pts defines a segment of the ring. The last point is connected to the first one.

val empty : t

empty is an empty ring.


val pts : t -> Gg.P2.t list

pts r is the list of points of r. See of_pts.

val area : t -> float

area r is the signed area of the ring r. You may be suprised by results on self-intersecting rings. Returns 0. on degenerate rings.

val centroid : t -> Gg.P2.t

centroid r is the centroid of r

val box : t -> Gg.Box2.t

box r is the bounding box of r. This is Box2.empty if is_empty r is true.


val is_empty : t -> bool

is_empty r is true iff r is empty, that is if has no points.

val mem : Gg.P2.t -> t -> bool

mem pt r is true iff pt is inside the ring r.


val swap_orientation : t -> t

swap_orientation r turns counterclockwise rings into clockwise ones and vice versa.


val fold_pts : (Gg.P2.t -> 'a -> 'a) -> t -> 'a -> 'a

fold_pts f r acc is the result of folding f with acc on the points of r. This is acc if c is empty.

val fold_segs : (Gg.P2.t -> Gg.P2.t -> 'a -> 'a) -> t -> 'a -> 'a

fold_segs f r acc is the result of folding f with acc on the segments of r. This is acc if r is empty, and calls f p p on degenerate singleton rings made of a single point.