README
¶
orb/clip 
Package orb/clip provides functions for clipping lines and polygons to a bounding box.
- uses Cohen-Sutherland algorithm for line clipping
- uses Sutherland-Hodgman algorithm for polygon clipping
Example
bound := orb.Bound{Min: orb.Point{0, 0}, Max: orb.Point{30, 30}}
ls := orb.LineString{
{-10, 10}, {10, 10}, {10, -10}, {20, -10}, {20, 10},
{40, 10}, {40, 20}, {20, 20}, {20, 40}, {10, 40},
{10, 20}, {5, 20}, {-10, 20},
}
// works on and returns an orb.Geometry interface.
clipped = clip.Geometry(bound, ls)
// or clip the line string directly
clipped = clip.LineString(bound, ls)
List of sub-package utilities
smartclip
- handles partial 2d geometries
Acknowledgements
This library is based on mapbox/lineclip.
Documentation
¶
Overview ¶
Package clip is a library for clipping geometry to a bounding box.
Index ¶
- func Bound(b, bound orb.Bound) orb.Bound
- func Collection(b orb.Bound, c orb.Collection) orb.Collection
- func Geometry(b orb.Bound, g orb.Geometry) orb.Geometry
- func LineString(b orb.Bound, ls orb.LineString, opts ...Option) orb.MultiLineString
- func MultiLineString(b orb.Bound, mls orb.MultiLineString, opts ...Option) orb.MultiLineString
- func MultiPoint(b orb.Bound, mp orb.MultiPoint) orb.MultiPoint
- func MultiPolygon(b orb.Bound, mp orb.MultiPolygon) orb.MultiPolygon
- func Polygon(b orb.Bound, p orb.Polygon) orb.Polygon
- func Ring(b orb.Bound, r orb.Ring) orb.Ring
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collection ¶
func Collection(b orb.Bound, c orb.Collection) orb.Collection
Collection clips each element in the collection to the bounding box. It will exclude elements if they don't intersect the bounding box. This operation will modify the input of '2d geometry' by using as a scratch space so clone if necessary.
func Geometry ¶
Geometry will clip the geometry to the bounding box using the correct functions for the type. This operation will modify the input of '1d or 2d geometry' by using as a scratch space so clone if necessary.
Example ¶
Output: [[[0 10] [10 10] [10 0]] [[20 0] [20 10] [30 10]] [[30 20] [20 20] [20 30]] [[10 30] [10 20] [5 20] [0 20]]]
func LineString ¶
func LineString(b orb.Bound, ls orb.LineString, opts ...Option) orb.MultiLineString
LineString clips the linestring to the bounding box.
func MultiLineString ¶
func MultiLineString(b orb.Bound, mls orb.MultiLineString, opts ...Option) orb.MultiLineString
MultiLineString clips the linestrings to the bounding box and returns a linestring union.
func MultiPoint ¶
func MultiPoint(b orb.Bound, mp orb.MultiPoint) orb.MultiPoint
MultiPoint returns a new set with the points outside the bound removed.
func MultiPolygon ¶
func MultiPolygon(b orb.Bound, mp orb.MultiPolygon) orb.MultiPolygon
MultiPolygon clips the multi polygon to the bounding box excluding any polygons if they don't intersect the bounding box. This operation will modify the input by using as a scratch space so clone if necessary.