package clip

import "github.com/paulmach/orb/clip"

Package clip is a library for clipping geometry to a bounding box.

Index

Examples

Functions

func Bound

func Bound(b, bound orb.Bound) orb.Bound

Bound intersects the two bounds. May result in an empty/degenerate bound.

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

func Geometry(b orb.Bound, g orb.Geometry) orb.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

Code:play 

package main

import (
	"fmt"

	"github.com/paulmach/orb"
	"github.com/paulmach/orb/clip"
)

func main() {
	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}}

	// returns an orb.Geometry interface.
	clipped := clip.Geometry(bound, ls)

	fmt.Println(clipped)
}

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.

func Polygon

func Polygon(b orb.Bound, p orb.Polygon) orb.Polygon

Polygon clips the polygon to the bounding box excluding the inner rings if they do not intersect the bounding box. This operation will modify the input by using as a scratch space so clone if necessary.

func Ring

func Ring(b orb.Bound, r orb.Ring) orb.Ring

Ring clips the ring to the bounding box and returns another ring. This operation will modify the input by using as a scratch space so clone if necessary.

Types

type Option

type Option func(*options)

An Option is a possible parameter to the clip operations.

func OpenBound

func OpenBound(yes bool) Option

OpenBound is an option to treat the bound as open. i.e. any lines along the bound sides will be removed and a point on boundary will cause the line to be split.

Source Files

clip.go helpers.go options.go

Directories

PathSynopsis
clip/smartclipPackage smartclip performs a more advanced clipping algorithm so it can deal with correctly oriented open rings and polygon.
Version
v0.11.1 (latest)
Published
Jan 29, 2024
Platform
js/wasm
Imports
3 packages
Last checked
1 day ago

Tools for package owners.