intgeom

package
v0.0.0-...-aaa3bb6 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package intgeom resembles github.com/go-spatial/geom but uses int64s internally to avoid floating point errors when performing arithmetic with the coords. The idea is that an int64's range (math.MaxInt64) is enough for (most) (earthly) geom operations. See https://www.explainxkcd.com/wiki/index.php/2170:_Coordinate_Precision. Using the last 9 digits as decimals should be enough for identifying the location of a grain of sand (in degrees). That leaves 10 digits for the whole units of measurement in your SRS. If that unit is degrees, it's more than enough (a circle only has 360). If that unit is feet, earth's circumference (131 482 560) also still fits. This is not intended to cover everything. go-spatial/geom has much more functionality. You are not required to use this.

Index

Constants

View Source
const (
	Precision = 1e09
)

Variables

This section is empty.

Functions

func FromGeomOrd

func FromGeomOrd(o float64) int64

FromGeomOrd turns a floating point ordinate into a representation by an integer

func SegmentIntersect

func SegmentIntersect(l1, l2 Line) ([2]int64, bool)

SegmentIntersect will find the intersection point (x,y) between two lines if there is one. Ok will be true if it found an intersection point and if the point is on both lines. ref: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line TODO implement this with integers

func ToGeomOrd

func ToGeomOrd(o int64) float64

ToGeomOrd turns an ordinate represented as an integer back into a floating point

Types

type ClockwiseFunc

type ClockwiseFunc func(...[2]int64) bool

ClockwiseFunc returns whether the set of points should be considered clockwise or counterclockwise. The last point is not the same as the first point, and the function should connect these points as needed.

type Extent

type Extent [4]int64

Extent represents the minx, miny, maxx and maxy A nil extent represents the whole universe.

func FromGeomExtent

func FromGeomExtent(e geom.Extent) Extent

func (Extent) Edges

func (e Extent) Edges(cwfn ClockwiseFunc) [][2][2]int64

Edges returns the clockwise order of the edges that make up the extent.

func (Extent) Extent

func (e Extent) Extent() [4]int64

Extent returns back the min and max of the Extent

func (Extent) MaxX

func (e Extent) MaxX() int64

MaxX is the larger of the x values.

func (Extent) MaxY

func (e Extent) MaxY() int64

MaxY is the larger of the y values.

func (Extent) MinX

func (e Extent) MinX() int64

MinX is the smaller of the x values.

func (Extent) MinY

func (e Extent) MinY() int64

MinY is the smaller of the y values.

func (Extent) ToGeomExtent

func (e Extent) ToGeomExtent() geom.Extent

func (Extent) Vertices

func (e Extent) Vertices() [][2]int64

Vertices return the vertices of the Bounding Box. The vertices are ordered in the following manner. (minx,miny), (maxx,miny), (maxx,maxy), (minx,maxy)

func (Extent) XSpan

func (e Extent) XSpan() int64

XSpan is the distance of the Extent in X

func (Extent) YSpan

func (e Extent) YSpan() int64

YSpan is the distance of the Extent in Y

type Extenter

type Extenter interface {
	Extent() (extent [4]int64)
}

Extenter represents an interface that returns a boundbox.

type Line

type Line [2][2]int64

Line has exactly two points

func FromGeomLine

func FromGeomLine(l geom.Line) Line

func (Line) ContainsPoint

func (l Line) ContainsPoint(pt [2]int64) bool

ContainsPoint checks to see if the given pont lines on the line segment. (Including the end points.)

func (Line) IsHorizontal

func (l Line) IsHorizontal() bool

IsHorizontal returns true if the `x` elements of the points that make the line (l) are equal.

func (Line) IsVertical

func (l Line) IsVertical() bool

IsVertical returns true if the `y` elements of the points that make up the line (l) are equal.

func (Line) Point1

func (l Line) Point1() *Point

Point1 returns a new copy of the first point in the line.

func (Line) Point2

func (l Line) Point2() *Point

Point2 returns a new copy of the second point in the line.

func (Line) ToGeomLine

func (l Line) ToGeomLine() geom.Line

func (Line) Vertices

func (l Line) Vertices() [][2]int64

type MinMaxer

type MinMaxer interface {
	MinX() int64
	MinY() int64
	MaxX() int64
	MaxY() int64
}

MinMaxer is a wrapper for an Extent that gets min/max of the extent

type Point

type Point [2]int64

Point describes a simple 2D point

func FromGeomPoint

func FromGeomPoint(p geom.Point) Point

func (Point) SetXY

func (p Point) SetXY(xy [2]int64)

SetXY sets a pair of coordinates

func (Point) ToGeomPoint

func (p Point) ToGeomPoint() geom.Point

func (Point) X

func (p Point) X() int64

X is the x coordinate of a point in the projection

func (Point) XY

func (p Point) XY() [2]int64

XY returns an array of 2D coordinates

func (Point) Y

func (p Point) Y() int64

Y is the y coordinate of a point in the projection

Jump to

Keyboard shortcuts

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