geometry

package
v0.0.0-...-ae1d368 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Determinate

func Determinate(a, b, c Point) float64

Determinate calculates the determinate of a triangle

func IsClockwise

func IsClockwise(poly []Point) bool

IsClockwise checks if a polygon is clockwise or not

func IsConvex

func IsConvex(a, b, c Point) bool

IsConvex checks if a triangle is convex (angle less than 180deg) based on its determinate

func LineIntersects

func LineIntersects(line1, line2 []Point) (bool, error)

LineIntersects checks if a line interesects another line

func PointInsidePolygon

func PointInsidePolygon(p *Point, polygon *Polygon) bool

PointInsidePolygon checks if given point is present inside polygon by using precalculated triangles

func PointInsideTriangle

func PointInsideTriangle(p, ta, tb, tc *Point) bool

PointInsideTriangle take a point and an triangle as ta tb tc Point2d

func PolygonArea

func PolygonArea(data []Point) float64

PolygonArea calculates an area of a polygon

Types

type BoundingBox

type BoundingBox struct {
	MaxX float64
	MaxY float64
	MinX float64
	MinY float64
}

BoundingBox contains information about the Shape bounding box

func CalculateBoundingBox

func CalculateBoundingBox(points []Point) BoundingBox

CalculateBoundingBox calculates the bounding box based on given list of Point

func (*BoundingBox) BoundingBoxIntersects

func (boundingBox *BoundingBox) BoundingBoxIntersects(intersectingBoundingBox *BoundingBox) bool

BoundingBoxIntersects checks if another BoundingBox intersects with the bounding box

func (*BoundingBox) ContainsPoint

func (boundingBox *BoundingBox) ContainsPoint(p *Point) bool

ContainsPoint checks if a Point is within the bounding box

type Circle

type Circle struct {
	ID         int64
	Name       string
	Origo      Point
	Radius     float64
	Properties ShapeProperties
}

Circle contains information about circle

func (*Circle) CircleInside

func (circle *Circle) CircleInside(circleCandidate *Circle) bool

CircleInside checks whether a circle is inside the circle Expects the Radius to be normalized according to X,Y-grid

func (*Circle) GetBoundingBox

func (circle *Circle) GetBoundingBox() BoundingBox

BoundingBox returns the circles BoundingBox

func (*Circle) GetID

func (circle *Circle) GetID() int64

GetID Returns the ID of the circle

func (*Circle) GetName

func (circle *Circle) GetName() string

GetName returns the circle name

func (*Circle) GetProperties

func (circle *Circle) GetProperties() ShapeProperties

GetProperties fetches the properties of the circle shape

func (*Circle) PointInside

func (circle *Circle) PointInside(point *Point) bool

PointInside checks if a point is inside circle

func (*Circle) PointInsideBoundingBox

func (circle *Circle) PointInsideBoundingBox(point *Point) bool

PointInsideBoundingBox checks if a point is inside the circle

func (*Circle) PolygonInside

func (circle *Circle) PolygonInside(polygon *Polygon) bool

PolygonInside checks whether a polygon is inside the circle

func (*Circle) SetID

func (circle *Circle) SetID(id int64)

SetID Sets the ID of the circle

func (*Circle) SetProperties

func (circle *Circle) SetProperties(shapeProperties ShapeProperties)

SetProperties sets the properties of the circle shape

func (*Circle) ShapeInside

func (circle *Circle) ShapeInside(shape Shape) bool

ShapeInside checks if a shape is inside the circle

func (*Circle) Type

func (circle *Circle) Type() string

Type returns the shape type

type Point

type Point struct {
	X float64
	Y float64
}

Point is a 2d point representation

func NewPointFromFloat

func NewPointFromFloat(floatList []float64) (Point, error)

NewPointFromFloat takes a list of float64 which represents X and Y and returns a single Point

func NewPointsFromFloat

func NewPointsFromFloat(floatList []float64) ([]Point, error)

NewPointsFromFloat takes a list of float64 and returns a list of Points

func NormalizePoints

func NormalizePoints(points []Point) []Point

NormalizePoints takes in an array of Point2d and removes redundant points from the list

func (*Point) Cross

func (p1 *Point) Cross(p2 *Point) float64

Cross takes the cross product against another point

func (*Point) DistanceTo

func (p1 *Point) DistanceTo(p2 *Point) float64

DistanceTo calculates squared distance between two points.

func (*Point) DistanceToLine

func (p1 *Point) DistanceToLine(a, b *Point) float64

DistanceToLine Checks the point' distance towards a line by creating a 90 deg normal between p1 and the line

func (*Point) Divide

func (p1 *Point) Divide(value float64) Point

Divide Divides a value with the point and returns a new Point instance

func (*Point) Dot

func (p1 *Point) Dot(p2 *Point) float64

Dot returns the dot product against another point

func (*Point) Equal

func (p1 *Point) Equal(p2 *Point) bool

Equal checks if a point is equal to another

func (*Point) MinusPoint

func (p1 *Point) MinusPoint(p2 *Point) Point

MinusPoint Subtracts points together and returns a new Point instance

func (*Point) PlusPoint

func (p1 *Point) PlusPoint(p2 *Point) Point

PlusPoint Adds points together and returns a new Point instance

func (*Point) Times

func (p1 *Point) Times(value float64) Point

Times Multiplies a value together with the point and returns a new Point instance

type PointElement

type PointElement struct {
	Prev, Next *PointElement
	Point      Point
}

PointElement ...

func (*PointElement) CleanUp

func (e *PointElement) CleanUp()

CleanUp ...

func (*PointElement) Remove

func (e *PointElement) Remove()

Remove ...

type Polygon

type Polygon struct {
	ID          int64
	Name        string
	Description string
	AlphaShape  []Point
	Triangles   [][]Point
	BoundingBox BoundingBox
	Properties  ShapeProperties
}

Polygon contains static and processed information about a polygon

func NewPolygonFromPoints

func NewPolygonFromPoints(points []Point) Polygon

NewPolygonFromPoints Returns a new Polygon with BoundingBox and AlphaShape, without triangulating points

func (*Polygon) CircleInside

func (polygon *Polygon) CircleInside(circle *Circle) bool

CircleInside checks whether a circle is inside the polygon

func (*Polygon) GetBoundingBox

func (polygon *Polygon) GetBoundingBox() BoundingBox

BoundingBox returns the polygons BoundingBox

func (*Polygon) GetID

func (polygon *Polygon) GetID() int64

GetID Returns the ID of the polygon

func (*Polygon) GetName

func (polygon *Polygon) GetName() string

GetName returns the name of the polygon

func (*Polygon) GetProperties

func (polygon *Polygon) GetProperties() ShapeProperties

GetProperties fetches the properties of the polygon shape

func (*Polygon) PointInside

func (polygon *Polygon) PointInside(point *Point) bool

PointInside checks if a point is inside the given polygon

func (*Polygon) PointInsideBoundingBox

func (polygon *Polygon) PointInsideBoundingBox(point *Point) bool

PointInsideBoundingBox checks if a point is inside the given polygon

func (*Polygon) PolygonInside

func (polygon *Polygon) PolygonInside(polygonCandidate *Polygon) bool

PolygonInside checks whether a polygon is inside the polygon

func (*Polygon) SetID

func (polygon *Polygon) SetID(id int64)

SetID Sets the ID of the polygon

func (*Polygon) SetProperties

func (polygon *Polygon) SetProperties(shapeProperties ShapeProperties)

SetProperties sets the properties of the polygon shape

func (*Polygon) ShapeInside

func (polygon *Polygon) ShapeInside(shape Shape) bool

ShapeInside checks if another shape is inside the given polygon

func (*Polygon) Type

func (polygon *Polygon) Type() string

Type returns the shape type

type Shape

type Shape interface {
	GetName() string
	Type() string

	GetID() int64
	SetID(int64)

	GetProperties() ShapeProperties
	SetProperties(shapeProperties ShapeProperties)

	GetBoundingBox() BoundingBox

	PointInside(point *Point) bool
	PointInsideBoundingBox(point *Point) bool

	ShapeInside(shape Shape) bool
}

Shape is a interface which is an abstract way of checking if a point exists within it

func ShapeStoreToShapes

func ShapeStoreToShapes(store *ShapeStore) []Shape

ShapeStoreToShapes deserializes a ShapeStore to a list of shapes

type ShapeProperties

type ShapeProperties map[string]interface{}

ShapeProperties represents arbitrary string properties connected to a shape

func (*ShapeProperties) Scan

func (shapeProperties *ShapeProperties) Scan(src interface{}) error

Scan implements SQL scan driver

func (ShapeProperties) Value

func (shapeProperties ShapeProperties) Value() (driver.Value, error)

Value implements SQL value driver

type ShapeStore

type ShapeStore struct {
	Circles  []Circle
	Polygons []Polygon
}

ShapeStore is a local struct to easier serialize/deserialize a list of shapes

func ShapesToShapeStore

func ShapesToShapeStore(shapes []Shape) ShapeStore

ShapesToShapeStore creates a serializable ShapeStore from a list of shapes

func (*ShapeStore) Scan

func (shapeStore *ShapeStore) Scan(src interface{}) error

Scan implements SQL scan driver

func (ShapeStore) Value

func (shapeStore ShapeStore) Value() (driver.Value, error)

Value implements SQL value driver

Jump to

Keyboard shortcuts

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