Module Gamelle.Shape

Arbitrary shapes: segments, circles and polygons.

type t

The type of shapes: segments, circles, polygons.

val segment : Segment.t -> t

segment s is the shape representing the segment s.

val circle : Circle.t -> t

circle c is the shape representing the circle c.

val rect : Box.t -> t

rect b is the shape representing the rectangle b.

val polygon : Polygon.t -> t

polygon p is the shape representing the polygon p.

Draw

val draw : io:io -> ?color:Color.t -> t -> unit

draw ~io s draws the outline border of the shape s.

val fill : io:io -> ?color:Color.t -> t -> unit

fill ~io p fills the inside of the shape s.

val pp : Stdlib.Format.formatter -> t -> unit

Format.printf "%a" pp t pretty prints the shape t.

Accessors

val center : t -> Point.t

center s returns the center of mass of the shape s.

val signed_area : t -> float

signed_area s returns the signed area of the shape s.

Transform

val rotate : ?center:Point.t -> float -> t -> t

rotate a s rotates the shape s by angle a (in radians).

Collisions

val mem : Point.t -> t -> bool

mem pt s returns true if point pt lies inside the shape s, false otherwise.

val distance2 : Point.t -> t -> float

distance2 pt s returns the squared distance of the point pt with the shape s.

val intersect : t -> t -> bool

intersect a b returns true if the shape a intersects the shape b, false otherwise.

val intersections : t -> t -> Point.t list

intersections a b returns the list of intersections points between the shapes a and b.