heavyfishdesign: github.com/dustismo/heavyfishdesign/path Index | Files

package path

import "github.com/dustismo/heavyfishdesign/path"

Index

Package Files

attributes.go draw.go path.go path_parser.go segment_operators.go transforms.go util.go

Constants

const (
    DefaultPrecision = 3 // how many decimal places do we want to consider
)
const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1

func DegreesToRadians Uses

func DegreesToRadians(degrees float64) float64

func Distance Uses

func Distance(p1 Point, p2 Point) float64

Distance finds the straightline distance between the two points distance will never be negative

func Float64ArrayContains Uses

func Float64ArrayContains(a []float64, x float64) bool

func Float64ArrayDeDup Uses

func Float64ArrayDeDup(a []float64) []float64

removes any duplicates from the array order may or may not be maintained

func Float64ArrayInsertIfAbsent Uses

func Float64ArrayInsertIfAbsent(a []float64, x float64) []float64

inserts the requested item if it does not already exist

func IsEmptyPath Uses

func IsEmptyPath(pth Path) bool

returns true if the path either has no segments, or contains only Move segments

func IsMove Uses

func IsMove(seg Segment) bool

returns true if this segment is a move

func IsPoint00 Uses

func IsPoint00(p Point) bool

returns true if this point is at 0,0

func PathAttribute Uses

func PathAttribute(attr string, p Path, so SegmentOperators) (interface{}, error)

func PointInBoundingBox Uses

func PointInBoundingBox(topL, bottomR, point Point) bool

returns true if the givin point is within the bounding box points points that lie directly on the bounding box are considered inside

func PrecisionCompare Uses

func PrecisionCompare(f1, f2 float64, precision int) int

compares two floats based on the passed in precision f1 == f2 => 0 f1 < f2 => -1 f1 > f2 => 1

func PrecisionEquals Uses

func PrecisionEquals(f1, f2 float64, precision int) bool

determines equality based on the number of digits of precision

func PrecisionPointInBoundingBox Uses

func PrecisionPointInBoundingBox(topL, bottomR, point Point, precision int) bool

func StringArrayDeDup Uses

func StringArrayDeDup(a []string) []string

removes any duplicates maintaining ordering

func StringElipses Uses

func StringElipses(str string, maxChars int) string

will trim a string to the requested length and add elipses

func SvgString Uses

func SvgString(path Path, numDecimals int) string

type BezierCurveOperators Uses

type BezierCurveOperators struct {
    // 0.5?
    CurveIntersectionThreshold float64
}

the default implementation of curve operators.

func NewBezierCurveOperators Uses

func NewBezierCurveOperators() BezierCurveOperators

func (BezierCurveOperators) BoundingBox Uses

func (b BezierCurveOperators) BoundingBox(curve Curve) (topLeft, bottomRight Point, err error)

func (BezierCurveOperators) IntersectCurve Uses

func (b BezierCurveOperators) IntersectCurve(curve1 Curve, curve2 Curve) ([]Point, error)

func (BezierCurveOperators) IntersectLine Uses

func (b BezierCurveOperators) IntersectLine(curve Curve, line LineSegment) ([]Point, error)

func (BezierCurveOperators) IntersectProjectedLine Uses

func (b BezierCurveOperators) IntersectProjectedLine(curve Curve, line LineSegment) ([]Point, error)

find the points where the given line *would* intersect if it were projected in either direction.

func (BezierCurveOperators) Offset Uses

func (b BezierCurveOperators) Offset(curve Curve, distance float64) ([]Curve, error)

func (BezierCurveOperators) Split Uses

func (b BezierCurveOperators) Split(curve Curve, point Point) ([]Curve, error)

type Curve Uses

type Curve interface {
    Start() Point
    End() Point
    ControlStart() Point
    ControlEnd() Point
}

type CurveOperators Uses

type CurveOperators interface {
    BoundingBox(curve Curve) (topLeft, bottomRight Point, err error)
    IntersectLine(curve Curve, line LineSegment) ([]Point, error)
    IntersectProjectedLine(curve Curve, line LineSegment) ([]Point, error)
    IntersectCurve(c1 Curve, c2 Curve) ([]Point, error)
    Split(curve Curve, point Point) ([]Curve, error)
    Offset(curve Curve, distance float64) ([]Curve, error)
}

type CurveSegment Uses

type CurveSegment struct {
    StartPoint        Point
    ControlPointStart Point
    EndPoint          Point
    ControlPointEnd   Point
}

func (CurveSegment) Clone Uses

func (c CurveSegment) Clone() Segment

func (CurveSegment) ControlEnd Uses

func (c CurveSegment) ControlEnd() Point

func (CurveSegment) ControlStart Uses

func (c CurveSegment) ControlStart() Point

func (CurveSegment) End Uses

func (c CurveSegment) End() Point

func (CurveSegment) SetStart Uses

func (c CurveSegment) SetStart(p Point) Segment

func (CurveSegment) Start Uses

func (c CurveSegment) Start() Point

func (CurveSegment) SvgString Uses

func (c CurveSegment) SvgString(numDecimals int) string

func (CurveSegment) UniqueString Uses

func (c CurveSegment) UniqueString(numDecimals int) string

type DefaultSegmentOperators Uses

type DefaultSegmentOperators struct {
    CurveOperators CurveOperators
    Precision      int
}

contains the segment operators for all the segments except some special Curve operators

func (DefaultSegmentOperators) BoundingBox Uses

func (do DefaultSegmentOperators) BoundingBox(segment Segment) (topLeft, bottomRight Point, err error)

func (DefaultSegmentOperators) Intersect Uses

func (do DefaultSegmentOperators) Intersect(s1, s2 Segment) ([]Point, error)

func (DefaultSegmentOperators) Join Uses

func (do DefaultSegmentOperators) Join(s1, s2 Segment) ([]Segment, error)

func (DefaultSegmentOperators) JoinCurveAndLine Uses

func (do DefaultSegmentOperators) JoinCurveAndLine(c1 CurveSegment, c2 LineSegment) ([]Segment, error)

func (DefaultSegmentOperators) JoinCurves Uses

func (do DefaultSegmentOperators) JoinCurves(c1, c2 CurveSegment) ([]Segment, error)

func (DefaultSegmentOperators) JoinLineAndCurve Uses

func (do DefaultSegmentOperators) JoinLineAndCurve(c1 LineSegment, c2 CurveSegment) ([]Segment, error)

joins the line and curve, by projecting the line until it intersects with the curve

func (DefaultSegmentOperators) JoinLines Uses

func (do DefaultSegmentOperators) JoinLines(l1, l2 LineSegment) ([]Segment, error)

Joins the two lines by finding the intersection

func (DefaultSegmentOperators) Move Uses

func (do DefaultSegmentOperators) Move(s Segment, amount Point) (Segment, error)

func (DefaultSegmentOperators) Offset Uses

func (do DefaultSegmentOperators) Offset(segment Segment, distance float64) (ret []Segment, err error)

func (DefaultSegmentOperators) Reverse Uses

func (do DefaultSegmentOperators) Reverse(segment Segment) (Segment, error)

func (DefaultSegmentOperators) Split Uses

func (do DefaultSegmentOperators) Split(segment Segment, point Point) (ret []Segment, err error)

func (DefaultSegmentOperators) TransformPoints Uses

func (do DefaultSegmentOperators) TransformPoints(s Segment, pt PointTransform) (Segment, error)

type Draw Uses

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

a draw is decorator of a Path which has convenient drawing operations

func NewDraw Uses

func NewDraw() *Draw

func (*Draw) AddSegment Uses

func (d *Draw) AddSegment(seg Segment)

tries to safely add a new segment if this segment doesnt start from the current position, then the segment start is mutated to the current position

func (*Draw) AddSegments Uses

func (d *Draw) AddSegments(segs []Segment)

func (*Draw) Circle Uses

func (d *Draw) Circle(r float64)

Draws an approximation of a circle at the current location This uses bezier curves so a perfect circle is impossible. origin is top left

func (*Draw) CurrentPosition Uses

func (d *Draw) CurrentPosition() Point

func (*Draw) CurveTo Uses

func (d *Draw) CurveTo(controlPointStart, controlPointEnd, point Point)

draws a Curve this is the Cubic Bezier

func (*Draw) HLineTo Uses

func (d *Draw) HLineTo(dx float64)

Draws a horizontal line from the current position to the passed in position

func (*Draw) LineByAngle Uses

func (d *Draw) LineByAngle(length, angle float64)

Draws a line from the current position based on length and angle

func (*Draw) LineTo Uses

func (d *Draw) LineTo(point Point)

line to

func (*Draw) MoveTo Uses

func (d *Draw) MoveTo(point Point)

func (*Draw) Path Uses

func (d *Draw) Path() Path

Returns the underlying Path

func (*Draw) QCurveTo Uses

func (d *Draw) QCurveTo(controlPoint, point Point)

Quadratic curve. Note - we convert to cubic curves

func (*Draw) Rect Uses

func (d *Draw) Rect(w, h float64)

draws a rectangle from the current location, ending in the current location

func (*Draw) RelCurveTo Uses

func (d *Draw) RelCurveTo(controlPointStartDxDy, controlPointEndDxDy, dxdy Point)

draws a Relative Curve this is the Cubic Bezier

func (*Draw) RelHLineTo Uses

func (d *Draw) RelHLineTo(dx float64)

Draws a horizontal line relative to the current position

func (*Draw) RelLineTo Uses

func (d *Draw) RelLineTo(dxdy Point)

Relative line to

func (*Draw) RelMoveTo Uses

func (d *Draw) RelMoveTo(dxdy Point)

moves relative to current cursor position

func (*Draw) RelQCurveTo Uses

func (d *Draw) RelQCurveTo(controlPointEndDxDy, dxdy Point)

relative Quadratic curve. Note - we convert to cubic curves

func (*Draw) RelRoundedCornerTo Uses

func (d *Draw) RelRoundedCornerTo(dxdy Point, dxdyCorner Point, radius float64)

func (*Draw) RelSmoothCurveTo Uses

func (d *Draw) RelSmoothCurveTo(controlPointEndDxDy, dxdy Point)

draws a smooth curve. Note that this is converted to a Cubic Bezier

func (*Draw) RelVLineTo Uses

func (d *Draw) RelVLineTo(dy float64)

Draws a vertical line relative to the current position

func (*Draw) RoundedCornerTo Uses

func (d *Draw) RoundedCornerTo(to Point, corner Point, radius float64)

Round corner draws a 90 deg corner using a curve

func (*Draw) SmoothCurveTo Uses

func (d *Draw) SmoothCurveTo(controlPointEnd, point Point)

draws a smooth curve. Note that this is converted to a Cubic Bezier

func (*Draw) SvgPath Uses

func (d *Draw) SvgPath(svg string) error

adds all segments from an svg path string

func (*Draw) ToAbsPosition Uses

func (d *Draw) ToAbsPosition(dxdy Point) Point

func (*Draw) VLineTo Uses

func (d *Draw) VLineTo(dy float64)

Draws a vertical line from the current position to the passed in position

type LineSegment Uses

type LineSegment struct {
    StartPoint Point
    EndPoint   Point
}

func NewLineSegmentAngle Uses

func NewLineSegmentAngle(start Point, length, angle float64) LineSegment

creates a line segment based on start point, length and angle where a positive horizontal line is 0 degrees

func Parallel Uses

func Parallel(segment LineSegment, distance float64) LineSegment

Given a line segment, and distance this gives a parrallel line, at 90 deg and distance d

func (LineSegment) Angle Uses

func (l LineSegment) Angle() float64

the angle of the line in degrees. where a positive horizontal line is 0

func (LineSegment) Clone Uses

func (l LineSegment) Clone() Segment

func (LineSegment) End Uses

func (l LineSegment) End() Point

func (LineSegment) EvalX Uses

func (l LineSegment) EvalX(x float64) float64

gets the value of Y for the given X

func (LineSegment) IsHorizontalPrecision Uses

func (l LineSegment) IsHorizontalPrecision(precision int) bool

func (LineSegment) IsVerticalPrecision Uses

func (l LineSegment) IsVerticalPrecision(precision int) bool

returns true if this line is vertical

func (LineSegment) Length Uses

func (l LineSegment) Length() float64

func (LineSegment) PointAtDistance Uses

func (l LineSegment) PointAtDistance(distance float64) Point

Finds the point at the specified distance from the start point in the direction of the end point..

func (LineSegment) SetStart Uses

func (l LineSegment) SetStart(p Point) Segment

func (LineSegment) Slope Uses

func (l LineSegment) Slope() float64

func (LineSegment) Start Uses

func (l LineSegment) Start() Point

func (LineSegment) SvgString Uses

func (l LineSegment) SvgString(numDecimals int) string

func (LineSegment) UniqueString Uses

func (l LineSegment) UniqueString(numDecimals int) string

func (LineSegment) YIntercept Uses

func (l LineSegment) YIntercept() float64

type MoveSegment Uses

type MoveSegment struct {
    StartPoint Point
    EndPoint   Point
}

func (MoveSegment) Clone Uses

func (m MoveSegment) Clone() Segment

func (MoveSegment) End Uses

func (m MoveSegment) End() Point

func (MoveSegment) SetStart Uses

func (m MoveSegment) SetStart(p Point) Segment

func (MoveSegment) Start Uses

func (m MoveSegment) Start() Point

func (MoveSegment) SvgString Uses

func (m MoveSegment) SvgString(numDecimals int) string

func (MoveSegment) UniqueString Uses

func (m MoveSegment) UniqueString(numDecimals int) string

type Params Uses

type Params interface {
    GetString(key string) string
}

type Path Uses

type Path interface {
    Segments() []Segment
    AddSegments(seg ...Segment)
    Clone() Path
}

func MultiTransform Uses

func MultiTransform(p Path, transforms ...PathTransform) (Path, error)

executes multiple transforms

func NewPath Uses

func NewPath() Path

func NewPathFromSegments Uses

func NewPathFromSegments(segments []Segment) Path

func NewPathFromSegmentsWithoutMove Uses

func NewPathFromSegmentsWithoutMove(segments []Segment) Path

creates a new Path from the passed in segments without adding a move at the beginning.

func ParsePathFromSvg Uses

func ParsePathFromSvg(path string) (Path, error)

parses a path from the SVG style string

func SplitPathOnMove Uses

func SplitPathOnMove(pth Path) []Path

splits the path into an array of paths, where each path begins with a move operation

type PathAttr Uses

type PathAttr string

defines the special points on a box

const (
    // positions based on the bounding box of the drawn shape
    // Note this will take whitespace into account
    TopLeft      PathAttr = "$TOP_LEFT"
    TopRight     PathAttr = "$TOP_RIGHT"
    TopMiddle    PathAttr = "$TOP_MIDDLE"
    BottomLeft   PathAttr = "$BOTTOM_LEFT"
    BottomRight  PathAttr = "$BOTTOM_RIGHT"
    BottomMiddle PathAttr = "$BOTTOM_MIDDLE"
    MiddleLeft   PathAttr = "$MIDDLE_LEFT"
    MiddleRight  PathAttr = "$MIDDLE_RIGHT"
    MiddleMiddle PathAttr = "$MIDDLE_MIDDLE"

    // the first and last visible pixel
    StartPoint PathAttr = "$START_POINT"
    EndPoint   PathAttr = "$END_POINT"

    // current cursor location
    Cursor PathAttr = "$CURSOR"

    // the first point in the path, this
    // differs from StartPoint because this could be
    // a Move.
    StartPosition PathAttr = "$START_POSITION"
    EndPosition   PathAttr = "$END_POSITION"

    Width  PathAttr = "$WIDTH"
    Height PathAttr = "$HEIGHT"

    Origin PathAttr = "$ORIGIN"
)

func ToPathAttr Uses

func ToPathAttr(str string) (PathAttr, error)

func ToPathAttrFromPoint Uses

func ToPathAttrFromPoint(point Point, precision int) PathAttr

type PathImpl Uses

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

func (*PathImpl) AddSegments Uses

func (p *PathImpl) AddSegments(seg ...Segment)

func (*PathImpl) Clone Uses

func (p *PathImpl) Clone() Path

func (*PathImpl) Segments Uses

func (p *PathImpl) Segments() []Segment

func (*PathImpl) SvgString Uses

func (p *PathImpl) SvgString(decimals int) string

type PathTransform Uses

type PathTransform interface {
    PathTransform(path Path) (Path, error)
}

transform a Path into a new Path

type Point Uses

type Point struct {
    X   float64
    Y   float64
    // contains filtered or unexported fields
}

func BoundingBoxTrimWhitespace Uses

func BoundingBoxTrimWhitespace(p Path, so SegmentOperators) (topLeft, bottomRight Point, err error)

func BoundingBoxWithWhitespace Uses

func BoundingBoxWithWhitespace(p Path, so SegmentOperators) (topLeft, bottomRight Point, err error)

gets the bounding box, including any trailing or leading whitespace

func GetStartAndEnd Uses

func GetStartAndEnd(segments []Segment) (start, end Point)

returns the start point and the end point of the segment array note that the start point is the target point of the first segment I.e. if the segments start with a move then the start point is where it moves TO

func HorizontalIntercepts Uses

func HorizontalIntercepts(p Path, y float64, so SegmentOperators) ([]Point, error)

The ordered points (by increasing x) of where this path intercepts the given y axis

func LineIntersection Uses

func LineIntersection(l1, l2 LineSegment, precision int) (p Point, success bool)

returns the point where the two lines would intersect, success is false if the lines are parrallel

func NewPoint Uses

func NewPoint(x float64, y float64) Point

Creates a new point, will convert -0.0 to 0.0

func NewPointRounded Uses

func NewPointRounded(x float64, y float64) Point

creates a new point, with the values rounded to 3 decimal places

func PathCursor Uses

func PathCursor(p Path) Point

returns the current cursor location of the path.

func PointPathAttribute Uses

func PointPathAttribute(pos PathAttr, p Path, so SegmentOperators) (Point, error)

func PolarToCartesian Uses

func PolarToCartesian(r, theta float64) Point

func Rotate Uses

func Rotate(degree float64, point Point) Point

Rotate the points by the given degrees. (clockwise)

func (Point) Clone Uses

func (p Point) Clone() Point

func (Point) Equals Uses

func (p Point) Equals(other Point) bool

checks if the points are equal this check for exact equality (the floats must be the same)

func (Point) EqualsPrecision Uses

func (p Point) EqualsPrecision(other Point, numDecimals int) bool

checks if the points are equal based to the requested number of decimal places

func (Point) String Uses

func (p Point) String() string

func (Point) StringPrecision Uses

func (p Point) StringPrecision(numDecimals int) string

func (Point) StringRounded Uses

func (p Point) StringRounded() string

func (Point) ToDynMap Uses

func (p Point) ToDynMap() *dynmap.DynMap

type PointTransform Uses

type PointTransform func(p Point) Point

type Segment Uses

type Segment interface {
    // SetStart(p Point) Segment
    Start() Point
    End() Point
    SvgString(numDecimals int) string
    UniqueString(numDecimals int) string
    Clone() Segment
}

func FixHeadMove Uses

func FixHeadMove(seg []Segment) []Segment

if the first move does not start at 0,0 then fix it

func HeadMove Uses

func HeadMove(seg []Segment) []Segment

func KnifeCut Uses

func KnifeCut(seg Segment, knife Segment, so SegmentOperators) ([]Segment, error)

will split the segment wherever the knife segment intersects

func SetSegmentStart Uses

func SetSegmentStart(segment Segment, start Point) (Segment, error)

func Tail Uses

func Tail(seg []Segment) Segment

returns the last Segment in the list, or nil

func TrimFirst Uses

func TrimFirst(seg []Segment) []Segment

func TrimLast Uses

func TrimLast(seg []Segment) []Segment

returns a segment list without the last element if empty, will return empty

func TrimMove Uses

func TrimMove(seg []Segment) []Segment

removes any Moves in the front or tail of the list.

func TrimTailMove Uses

func TrimTailMove(seg []Segment) []Segment

removes any Move segments from the tail of the list

type SegmentOperators Uses

type SegmentOperators interface {
    Reverse(segment Segment) (Segment, error)
    BoundingBox(segment Segment) (topLeft, bottomRight Point, err error)
    // find the intersection between the two segments
    Intersect(segment1, segment2 Segment) ([]Point, error)
    // Splits the segment at the requested point
    // if point does not exist on the segment then ??
    Split(segment Segment, point Point) ([]Segment, error)
    Offset(segment Segment, distance float64) ([]Segment, error)
    // Joins the two disjoint segments into on continuous path
    // possibly returns multiple segments
    Join(segment1, segment2 Segment) ([]Segment, error)
    // transforms all the points associated with the segment
    TransformPoints(segment Segment, pt PointTransform) (Segment, error)
}

various operations we should be able to perform on segments

func NewSegmentOperators Uses

func NewSegmentOperators() SegmentOperators

type SegmentTransform Uses

type SegmentTransform interface {
    SegmentTransform(segment Segment) Segment
}

transforma a segment

type SvgCommand Uses

type SvgCommand rune
const (
    // These are the only supported Command types
    Move         SvgCommand = 'M'
    Line         SvgCommand = 'L'
    CurveCommand SvgCommand = 'C'
    ClosePath    SvgCommand = 'Z'
)

Package path imports 7 packages (graph) and is imported by 5 packages. Updated 2020-07-19. Refresh now. Tools for package owners.