Legend:
Library
Module
Module type
Parameter
Class
Class type
Values are stored in the Rtree and must provide a means of calculating an envelope (minimal bounding box).
An example
A two-dimensional lines that uses Rectangle as a bounding box could be implemented as
module Line = struct
type t = { p0 : float * float; p1 : float * float }
let t =
let open Repr in
record "line" (fun p0 p1 -> { p0; p1 })
|+ field "p0" (pair float float) (fun t -> t.p0)
|+ field "p1" (pair float float) (fun t -> t.p1)
|> sealr
type envelope = Rtree.Rectangle.t
let envelope { p0 = (x1, y1); p1 = (x2, y2) } =
let x0 = Float.min x1 x2 in
let x1 = Float.max x1 x2 in
let y0 = Float.min y1 y2 in
let y1 = Float.max y1 y2 in
Rtree.Rectangle.v ~x0 ~y0 ~x1 ~y1
end
Note that a runtime representation must also be provided.