geo

package
v0.0.0-...-7df57c3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: BSD-3-Clause Imports: 7 Imported by: 3

README

A Go library to compute the contour of simple rectilinear polygons

This is not intended to be a general purpose library, but fits the need I had, namely to find the contour of a bunch of rectangles of possibly different sizes and mostly touching each other.

The heart of the library is the implementation of one of the sweep algorithms found in the following article :

Souvaine, Diane & Bjorling-Sachs, Iliana. (1992). The Contour Problem for Restricted-Orientation Polygons. Proceedings of the IEEE. 80. 1449 - 1470. 10.1109/5.163411.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrWrongOrientation indicates that an attempt was made to use clockwise polygons
	// (or a mix of counter and clock-wise polygons), while this library's algorithms
	// only works with counter-clockwise polygons
	ErrWrongOrientation = errors.New("polygons should be oriented counterclockwise for this algorithm")
)

Functions

func EqualBBox

func EqualBBox(a, b BBox) bool

EqualBBox checks if two boxes are equal. For the precision of the comparison see EqualFloat function.

func EqualContour

func EqualContour(c1, c2 Contour) bool

EqualContour returns true if the two contours have the same set of (sorted) vertices

func EqualEdge

func EqualEdge(a, b manhattanEdge) bool

EqualEdge returns true if edges a and b are equal

func EqualFloat

func EqualFloat(a, b float64) bool

EqualFloat checks if two float64 are equal within 1E-4 (on difference)

func EqualFloat64Slice

func EqualFloat64Slice(a, b []float64) bool

EqualFloat64Slice checks if two float64 slices are equal (same elements in exact same order)

func EqualPolygon

func EqualPolygon(a, b Polygon) bool

EqualPolygon checks if two polygon are the same (same vertices, whetever the order)

func EqualVertex

func EqualVertex(a, b Vertex) bool

EqualVertex checks if two vertices are equal For the precision of the comparison see EqualFloat function.

func IsInRangeFloat64

func IsInRangeFloat64(x, a, b float64) bool

IsInRangeFloat64 returns true if a<=x<=b

func IsStrictlyBelowFloat

func IsStrictlyBelowFloat(a, b float64) bool

IsStrictlyBelowFloat returns true if a < b

func SquaredDistanceOfPointToSegment

func SquaredDistanceOfPointToSegment(p, p0, p1 Vertex) float64

SquaredDistanceOfPointToSegment computes the square of the distance between point p and segment (p0,p1)

func SquaredDistancePointToPolygon

func SquaredDistancePointToPolygon(point Vertex, p Polygon) float64

SquaredDistancePointToPolygon return the square of the distance between a point and a polygon

Types

type BBox

type BBox interface {
	Xcenter() float64
	Ycenter() float64
	Width() float64
	Height() float64
	Xmin() float64
	Xmax() float64
	Ymin() float64
	Ymax() float64
	Contains(x, y float64) bool
	fmt.Stringer
}

BBox describes a simple bounding box.

func Intersect

func Intersect(a, b BBox) (BBox, error)

Intersect returns the common part of boxes a and b.

func NewBBox

func NewBBox(xmin, ymin, xmax, ymax float64) (BBox, error)

NewBBox creates a bounding box that is guaranteed to be valid if error is nil

func NewBBoxUnchecked

func NewBBoxUnchecked(xmin, ymin, xmax, ymax float64) BBox

NewBBoxUnchecked return a bbox that might contain garbage (mostly used in test to ease declaration of multiple bounding boxes)

type Contour

type Contour []Polygon

Contour is a set of polygons

func NewContour

func NewContour(polygons []Polygon) (Contour, error)

NewContour returns the boolean union of the polygons

func (Contour) BBox

func (c Contour) BBox() BBox

BBox returns the bounding box of this contour

func (Contour) Contains

func (c Contour) Contains(x, y float64) bool

Contains returns true if the point (x,y) is inside the contour

func (Contour) String

func (c Contour) String() string

type Polygon

type Polygon []Vertex

Polygon describes a simple, rectilinear, closed set of vertices with a specific orientation

func Translate

func Translate(src []Polygon, x, y float64) []Polygon

func (Polygon) BBox

func (p Polygon) BBox() BBox

BBox returns the bounding box of the polygon.

func (Polygon) Contains

func (p Polygon) Contains(xp, yp float64) (bool, error)

Contains returns true if the point (xp,yp) is inside the polygon

Note that this algorithm yields unpredicatable result if the point xp,yp is on one edge of the polygon. Should not generally matters, except when comparing two different implementations maybe.

TODO : look e.g. to http://alienryderflex.com/polygon/ for some possible optimizations (e.g. pre-computation)

func (Polygon) String

func (p Polygon) String() string

func (Polygon) Translate

func (p Polygon) Translate(x, y float64) Polygon

Translate returns a new polygon shifted by the given offset

type SVGWriter

type SVGWriter struct {
	// contains filtered or unexported fields
}

SVGWriter is a utility object to create SVG output for polygon, contours etc...

func NewSVGWriter

func NewSVGWriter(width int) *SVGWriter

func (*SVGWriter) Circle

func (w *SVGWriter) Circle(x, y, radius float64)

func (*SVGWriter) Contour

func (w *SVGWriter) Contour(c *Contour)

Contour adds one polygon object per sub-contour

func (*SVGWriter) GroupEnd

func (w *SVGWriter) GroupEnd()

GroupEnd ends a group tag

func (*SVGWriter) GroupStart

func (w *SVGWriter) GroupStart(classname string)

GroupStart starts a group tag with a given classname.

func (*SVGWriter) Height

func (w *SVGWriter) Height() int

Height returns the height of this SVG object

func (*SVGWriter) MoveToOrigin

func (w *SVGWriter) MoveToOrigin()

func (*SVGWriter) Polygon

func (w *SVGWriter) Polygon(p *Polygon)

Polygon adds a polygon object

func (*SVGWriter) PolygonWithClass

func (w *SVGWriter) PolygonWithClass(p *Polygon, class string)

PolygonWithClass adds a polygon object with a given CSS class

func (*SVGWriter) Rect

func (w *SVGWriter) Rect(x, y, width, height float64)

Rect adds a rectangle object

func (*SVGWriter) RectWithClass

func (w *SVGWriter) RectWithClass(x, y, width, height float64, class string)

Rect adds a rectangle object

func (*SVGWriter) Style

func (w *SVGWriter) Style(style string)

Style add some style

func (*SVGWriter) Text

func (w *SVGWriter) Text(text string, x, y float64)

Text adds a text object

func (*SVGWriter) Translate

func (w *SVGWriter) Translate(x0, y0 float64)

func (*SVGWriter) ViewBox

func (w *SVGWriter) ViewBox(xleft, xright, ybottom, ytop float64)

func (*SVGWriter) ViewBoxHeight

func (w *SVGWriter) ViewBoxHeight() float64

func (*SVGWriter) ViewBoxWidth

func (w *SVGWriter) ViewBoxWidth() float64

func (*SVGWriter) Width

func (w *SVGWriter) Width() int

func (*SVGWriter) WriteHTML

func (w *SVGWriter) WriteHTML(out io.Writer)

WriteHTML output

func (*SVGWriter) WriteSVG

func (w *SVGWriter) WriteSVG(out io.Writer)

WriteSVG output

func (*SVGWriter) WriteStyle

func (w *SVGWriter) WriteStyle(out io.Writer)

WriteStyle outputs <style> options

type Vertex

type Vertex struct {
	X, Y float64
}

Vertex is a simple (x,y) float64 pair

func (Vertex) String

func (v Vertex) String() string

Jump to

Keyboard shortcuts

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