GizStack
View .mdOpen in ChatGPTOpen in Claude

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).

gizlang
import * as Geo from "gizmodel/sql/types/geo";

Types

Geometry

gizlang
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: string
  • pts: Vec<M159.Pt>
  • closed: bool
  • a: f64
  • b: f64
  • c: f64
  • r: f64

Functions

comparisons

gizlang
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

gizlang
function geoKindOf(declared: string): string

The geometric type a declared type names, lower case, or "".

Effects: fail, alloc.

geoParse

gizlang
function geoParse(kind: string, text: string): Geometry throws DbError

Reads 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

gizlang
function shortest(x: f64): string

float8out with the shortest exact digits.

Effects: fail, alloc.

geoNumbers

gizlang
function geoNumbers(g: Geometry): Vec<f64>

The numbers of g in the order its text writes them.

Effects: fail, alloc.

geoText

gizlang
function geoText(g: Geometry, s: Vec<string>): string

The output text of g with its numbers (geoNumbers) written as s.

Effects: fail, alloc.

geoInput

gizlang
function geoInput(kind: string, text: string): string throws DbError

text read as kind and written back canonically (an input cast).

Effects: fail, alloc.

geoFunction

gizlang
function geoFunction(name: string): bool

Whether name is the name of a geometric function.

Effects: fail, alloc.

geoResolve

gizlang
function geoResolve(op: string, kinds: Vec<string>): string

The 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

gizlang
function geoResultOf(sig: string): string

The type a signature returns.

Effects: fail, alloc.

asText

gizlang
function asText(v: Value): string

The text of a text value, else "".

geoApply

gizlang
function geoApply(sig: string, args: Vec<Value>): Value throws DbError

Evaluates the signature sig (geoResolve) over args: geometric values as text, numbers as floats or integers. A null argument gives null.

Effects: fail, alloc.