gizmodel/sql/types/geo
PostgreSQL's geometric types (point, lseg, line, box, path, polygon, circle) as PostgreSQL 16's geo_ops.c reads, writes and compares them. A value is the text of its canonical output with the shortest exact digits; the binder resolves each operator and function to a signature (geoResolve) and the call evaluates it (geoApply).
import * as Geo from "gizmodel/sql/types/geo";Types
Geometry
type Geometry = { kind: string; pts: Vec<Pt>; closed: bool; a: f64; b: f64; c: f64; r: f64; }One geometric value: a point (pts[0]), lseg (pts[0..2]), line (a, b, c), box (pts[0] high, pts[1] low), path (pts, closed), polygon (pts) or circle (pts[0] center, r).
kind:stringpts:Vec<M159.Pt>closed:boola:f64b:f64c:f64r:f64
Functions
comparisons
function comparisons(): Vec<string>The comparison operators, in the order the catalog lists them (a function: reading a module Vec is an effect).
Effects: fail, alloc.
geoKindOf
function geoKindOf(declared: string): stringThe geometric type a declared type names, lower case, or "".
Effects: fail, alloc.
geoParse
function geoParse(kind: string, text: string): Geometry throws DbErrorReads text as a value of the geometric type kind (geo_ops.c point_in, lseg_in, line_in, box_in, path_in,
poly_in, circle_in).
Effects: fail, alloc.
shortest
function shortest(x: f64): stringfloat8out with the shortest exact digits.
Effects: fail, alloc.
geoNumbers
function geoNumbers(g: Geometry): Vec<f64>The numbers of g in the order its text writes them.
Effects: fail, alloc.
geoText
function geoText(g: Geometry, s: Vec<string>): stringThe output text of g with its numbers (geoNumbers) written as s.
Effects: fail, alloc.
geoInput
function geoInput(kind: string, text: string): string throws DbErrortext read as kind and written back canonically (an input cast).
Effects: fail, alloc.
geoFunction
function geoFunction(name: string): boolWhether name is the name of a geometric function.
Effects: fail, alloc.
geoResolve
function geoResolve(op: string, kinds: Vec<string>): stringThe signature ("op left right result", or "fn:name args... result") of op applied to arguments of kinds
(a geometric type, float8 for a number, unknown for an untyped literal, "" for anything else), or "". An
unknown argument takes the type of the other one first, as PostgreSQL resolves it.
Effects: fail, alloc.
geoResultOf
function geoResultOf(sig: string): stringThe type a signature returns.
Effects: fail, alloc.
asText
function asText(v: Value): stringThe text of a text value, else "".
geoApply
function geoApply(sig: string, args: Vec<Value>): Value throws DbErrorEvaluates the signature sig (geoResolve) over args: geometric values as text, numbers as floats or
integers. A null argument gives null.
Effects: fail, alloc.