clip

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2019 License: MIT Imports: 3 Imported by: 0

README

orb/clip Godoc Reference

Package orb/clip provides functions for clipping lines and polygons to a bounding box.

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)
Acknowledgements

This library is based on mapbox/lineclip.

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

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
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.

Directories

Path Synopsis
Package smartclip performs a more advanced clipping algorithm so it can deal with correctly oriented open rings and polygon.
Package smartclip performs a more advanced clipping algorithm so it can deal with correctly oriented open rings and polygon.

Jump to

Keyboard shortcuts

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