polygon

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Overview

Package polygon deals with polygons, ie paths with straight lines.

This is, besides other functionality, a proxy class for a polyclip package from

https://github.com/akavel/polyclip-go

(See CREDITS file for details)

BSD License

Copyright (c) 2017-20, Norbert Pillmayer (norbert@pillmayer.com)

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of this software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsString

func AsString(pg Polygon) string

AsString pretty-prints a polygon.

func L

func L() tracing.Trace

L is tracing to the syntax tracer.

func Pr2Pt

func Pr2Pt(p arithm.Pair) pc.Point

Pr2Pt is a quick convertion to go-polygon's point type.

func Pt2Pr

func Pt2Pr(pt pc.Point) arithm.Pair

Pt2Pr is a quick convertion from go-polygon's point type.

Types

type GPPolygon

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

GPPolygon is a concrete implementation of Polygon, based on Go-Polygon's types.

func Box

func Box(topleft arithm.Pair, bottomright arithm.Pair) *GPPolygon

Box creates a box given the top-left and bottom-right corner.

func NullPolygon

func NullPolygon() *GPPolygon

NullPolygon creates an empty polygon. This is the starting point for a builder-like functionality. Clients start with a null-polygon and subsequently add knots to it.

Example (package qualifiers omitted for clarity and brevity):

polygon := NullPolygon().Knot(P(1,2)).Knot(P(12,5)).Knot(P(20,3.5)).Cycle()

func (*GPPolygon) AppendSubpath

func (pg *GPPolygon) AppendSubpath(p Polygon) *GPPolygon

AppendSubpath appends a polygon to a polygon.

func (*GPPolygon) Copy

func (pg *GPPolygon) Copy() *GPPolygon

Copy gets a copy of a polygon.

func (*GPPolygon) Cycle

func (pg *GPPolygon) Cycle() *GPPolygon

Cycle closes a polygon.

func (*GPPolygon) IsCycle

func (pg *GPPolygon) IsCycle() bool

IsCycle is part of iterface Polygon.

func (*GPPolygon) Knot

func (pg *GPPolygon) Knot(pr arithm.Pair) *GPPolygon

Knot appends a knot to a polygon.

func (*GPPolygon) N

func (pg *GPPolygon) N() int

N is part of interface Polygon.

func (*GPPolygon) Pt

func (pg *GPPolygon) Pt(i int) arithm.Pair

Pt is par of interface Polygon.

func (*GPPolygon) Reverse

func (pg *GPPolygon) Reverse()

Reverse a polygon. Destructive operation.

func (*GPPolygon) String

func (pg *GPPolygon) String() string

Stringer

func (*GPPolygon) Subpath

func (pg *GPPolygon) Subpath(from, to int)

Subpath clips out a subpath of a polygon. Destructive operation.

type Polygon

type Polygon interface {
	IsCycle() bool      // is this a cyclic polygon, i.e, is it complete?
	N() int             // number of knots in the polygon
	Pt(int) arithm.Pair // knot #i modulo N
}

Polygon is an interface for immutable polygons.

func Difference

func Difference(pg1 Polygon, pg2 Polygon) Polygon

Difference constructs the difference of 2 polygons. Returns a new polygon.

func Intersection

func Intersection(pg1 Polygon, pg2 Polygon) Polygon

Intersection constructs the intersection of 2 polygons. Returns a new polygon.

func Transform

func Transform(pg Polygon, t arithm.AT) Polygon

Transform applies an affine transform to (all knots of) a polygon. Returns a new polygon (input parameters are unchanged).

func Union

func Union(pg1 Polygon, pg2 Polygon) Polygon

Union constructs the union of 2 polygons. Returns a new polygon.

Jump to

Keyboard shortcuts

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