pgeo

package module
v0.0.0-...-8dc2bc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 10 Imported by: 0

README

pgeo

Package pgeo implements geometric types for Postgres

It uses Scanner and Valuer interfaces from database/sql

Types

//Points are the fundamental two-dimensional building block for geometric types.
//X and Y are the respective coordinates, as floating-point numbers
type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

//Circles are represented by a center point and radius.
type Circle struct {
	Point
	Radius float64 `json:"radius"`
}

//Line represents a infinite line with the linear equation Ax + By + C = 0, where A and B are not both zero.
type Line struct {
	A float64 `json:"a"`
	B float64 `json:"b"`
	C float64 `json:"c"`
}

//Paths are represented by lists of connected points.
//Paths can be open, where the first and last points in the list are considered not connected,
//or closed, where the first and last points are considered connected.
type Path struct {
	Points []Point `json:"points"`
	Closed bool    `json:"closed"`
}

//Boxes are represented by pairs of points that are opposite corners of the box.
type Box [2]Point

//Line segments are represented by pairs of points that are the endpoints of the segment.
type Lseg [2]Point

//Polygons are represented by lists of points (the vertexes of the polygon).
type Polygon []Point
Null Types
type NullPoint struct {
	Point
	Valid bool `json:"valid"`
}

//Same for others...

Functions

Create Types
NewPoint(X, Y float64) Point

NewLine(A, B, C float64) Line

NewLseg(A, B Point) Lseg

NewBox(A, B Point) Box

NewPath(P []Point, Closed bool) Path

NewPolygon(P []Point) Polygon

NewCircle(P Point, Radius float64) Circle
Null Types
NewNullPoint(P Point, valid bool) NullPoint

NewNullLine(L Line, valid bool) NullLine

NewNullLseg(L Lseg, valid bool) NullLseg

NewNullBox(B Box, valid bool) NullBox

NewNullPath(P Path, valid bool) NullPath

NewNullPolygon(P Polygon, valid bool) NullPolygon

NewNullCircle(C Circle, valid bool) NullCircle
Rand Types
NewRandPoint() Point

NewRandLine() Line

NewRandLseg() Lseg

NewRandBox() Box

NewRandPath() Path

NewRandPolygon() Polygon

NewRandCircle() Circle
Zero Point
//Returns a Point X=0, Y=0
NewZeroPoint() Point

Documentation

Overview

Package pgeo implements geometric types for Postgres

Geometryc types: https://www.postgresql.org/docs/current/static/datatype-geometric.html

Description: https://github.com/saulortega/pgeo

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Box

type Box [2]Point

Box is represented by pair of points that are opposite corners of the box.

func NewBox

func NewBox(A, B Point) Box

func NewRandBox

func NewRandBox() Box

func (*Box) Scan

func (b *Box) Scan(src interface{}) error

func (Box) Value

func (b Box) Value() (driver.Value, error)

type Circle

type Circle struct {
	Point
	Radius float64 `json:"radius"`
}

Circles are represented by a center point and radius.

func NewCircle

func NewCircle(P Point, R float64) Circle

func NewRandCircle

func NewRandCircle() Circle

func (*Circle) Scan

func (c *Circle) Scan(src interface{}) error

func (Circle) Value

func (c Circle) Value() (driver.Value, error)

type Line

type Line struct {
	A float64 `json:"a"`
	B float64 `json:"b"`
	C float64 `json:"c"`
}

Line represents a infinite line with the linear equation Ax + By + C = 0, where A and B are not both zero.

func NewLine

func NewLine(A, B, C float64) Line

func NewRandLine

func NewRandLine() Line

func (*Line) Scan

func (l *Line) Scan(src interface{}) error

func (Line) Value

func (l Line) Value() (driver.Value, error)

type Lseg

type Lseg [2]Point

Line segments are represented by pairs of points that are the endpoints of the segment.

func NewLseg

func NewLseg(A, B Point) Lseg

func NewRandLseg

func NewRandLseg() Lseg

func (*Lseg) Scan

func (l *Lseg) Scan(src interface{}) error

func (Lseg) Value

func (l Lseg) Value() (driver.Value, error)

type NullBox

type NullBox struct {
	Box
	Valid bool `json:"valid"`
}

func NewNullBox

func NewNullBox(B Box, v bool) NullBox

func (*NullBox) MarshalJSON

func (b *NullBox) MarshalJSON() ([]byte, error)

func (*NullBox) Scan

func (b *NullBox) Scan(src interface{}) error

func (*NullBox) UnmarshalJSON

func (b *NullBox) UnmarshalJSON(data []byte) error

func (NullBox) Value

func (b NullBox) Value() (driver.Value, error)

type NullCircle

type NullCircle struct {
	Circle
	Valid bool `json:"valid"`
}

func NewNullCircle

func NewNullCircle(C Circle, v bool) NullCircle

func (*NullCircle) MarshalJSON

func (c *NullCircle) MarshalJSON() ([]byte, error)

func (*NullCircle) Scan

func (c *NullCircle) Scan(src interface{}) error

func (*NullCircle) UnmarshalJSON

func (c *NullCircle) UnmarshalJSON(data []byte) error

func (NullCircle) Value

func (c NullCircle) Value() (driver.Value, error)

type NullLine

type NullLine struct {
	Line
	Valid bool `json:"valid"`
}

func NewNullLine

func NewNullLine(L Line, v bool) NullLine

func (*NullLine) MarshalJSON

func (l *NullLine) MarshalJSON() ([]byte, error)

func (*NullLine) Scan

func (l *NullLine) Scan(src interface{}) error

func (*NullLine) UnmarshalJSON

func (l *NullLine) UnmarshalJSON(data []byte) error

func (NullLine) Value

func (l NullLine) Value() (driver.Value, error)

type NullLseg

type NullLseg struct {
	Lseg
	Valid bool `json:"valid"`
}

func NewNullLseg

func NewNullLseg(L Lseg, v bool) NullLseg

func (*NullLseg) MarshalJSON

func (l *NullLseg) MarshalJSON() ([]byte, error)

func (*NullLseg) Scan

func (l *NullLseg) Scan(src interface{}) error

func (*NullLseg) UnmarshalJSON

func (l *NullLseg) UnmarshalJSON(data []byte) error

func (NullLseg) Value

func (l NullLseg) Value() (driver.Value, error)

type NullPath

type NullPath struct {
	Path
	Valid bool `json:"valid"`
}

func NewNullPath

func NewNullPath(P Path, v bool) NullPath

func (*NullPath) MarshalJSON

func (p *NullPath) MarshalJSON() ([]byte, error)

func (*NullPath) Scan

func (p *NullPath) Scan(src interface{}) error

func (*NullPath) UnmarshalJSON

func (p *NullPath) UnmarshalJSON(data []byte) error

func (NullPath) Value

func (p NullPath) Value() (driver.Value, error)

type NullPoint

type NullPoint struct {
	Point
	Valid bool `json:"valid"`
}

func NewNullPoint

func NewNullPoint(P Point, v bool) NullPoint

func (*NullPoint) MarshalJSON

func (p *NullPoint) MarshalJSON() ([]byte, error)

func (*NullPoint) Scan

func (p *NullPoint) Scan(src interface{}) error

func (*NullPoint) UnmarshalJSON

func (p *NullPoint) UnmarshalJSON(data []byte) error

func (NullPoint) Value

func (p NullPoint) Value() (driver.Value, error)

type NullPolygon

type NullPolygon struct {
	Polygon
	Valid bool `json:"valid"`
}

func NewNullPolygon

func NewNullPolygon(P Polygon, v bool) NullPolygon

func (*NullPolygon) MarshalJSON

func (p *NullPolygon) MarshalJSON() ([]byte, error)

func (*NullPolygon) Scan

func (p *NullPolygon) Scan(src interface{}) error

func (*NullPolygon) UnmarshalJSON

func (p *NullPolygon) UnmarshalJSON(data []byte) error

func (NullPolygon) Value

func (p NullPolygon) Value() (driver.Value, error)

type Path

type Path struct {
	Points []Point `json:"points"`
	Closed bool    `json:"closed"`
}

Path is represented by list of connected points. Paths can be open, where the first and last points in the list are considered not connected, or closed, where the first and last points are considered connected.

func NewPath

func NewPath(P []Point, C bool) Path

func NewRandPath

func NewRandPath() Path

func (*Path) MarshalJSON

func (p *Path) MarshalJSON() ([]byte, error)

func (*Path) Scan

func (p *Path) Scan(src interface{}) error

func (*Path) UnmarshalJSON

func (p *Path) UnmarshalJSON(data []byte) error

func (Path) Value

func (p Path) Value() (driver.Value, error)

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

Points are the fundamental two-dimensional building block for geometric types. X and Y are the respective coordinates, as floating-point numbers

func NewPoint

func NewPoint(X, Y float64) Point

func NewRandPoint

func NewRandPoint() Point

func NewZeroPoint

func NewZeroPoint() Point

func RandPoints

func RandPoints(n int) []Point

func (*Point) Scan

func (p *Point) Scan(src interface{}) error

func (Point) Value

func (p Point) Value() (driver.Value, error)

type Polygon

type Polygon []Point

Polygons are represented by lists of points (the vertexes of the polygon).

func NewPolygon

func NewPolygon(P []Point) Polygon

func NewRandPolygon

func NewRandPolygon() Polygon

func (*Polygon) Scan

func (p *Polygon) Scan(src interface{}) error

func (Polygon) Value

func (p Polygon) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL