Documentation ¶
Index ¶
- Constants
- func DegreesToRadians(degrees float64) float64
- func Distance(p1 Point, p2 Point) float64
- func Float64ArrayContains(a []float64, x float64) bool
- func Float64ArrayDeDup(a []float64) []float64
- func Float64ArrayInsertIfAbsent(a []float64, x float64) []float64
- func IsEmptyPath(pth Path) bool
- func IsMove(seg Segment) bool
- func IsPoint00(p Point) bool
- func PathAttribute(attr string, p Path, so SegmentOperators) (interface{}, error)
- func PointInBoundingBox(topL, bottomR, point Point) bool
- func PrecisionCompare(f1, f2 float64, precision int) int
- func PrecisionEquals(f1, f2 float64, precision int) bool
- func PrecisionPointInBoundingBox(topL, bottomR, point Point, precision int) bool
- func StringArrayDeDup(a []string) []string
- func StringElipses(str string, maxChars int) string
- func SvgString(path Path, numDecimals int) string
- type BezierCurveOperators
- func (b BezierCurveOperators) BoundingBox(curve Curve) (topLeft, bottomRight Point, err error)
- func (b BezierCurveOperators) IntersectCurve(curve1 Curve, curve2 Curve) ([]Point, error)
- func (b BezierCurveOperators) IntersectLine(curve Curve, line LineSegment) ([]Point, error)
- func (b BezierCurveOperators) IntersectProjectedLine(curve Curve, line LineSegment) ([]Point, error)
- func (b BezierCurveOperators) Offset(curve Curve, distance float64) ([]Curve, error)
- func (b BezierCurveOperators) Split(curve Curve, point Point) ([]Curve, error)
- type Curve
- type CurveOperators
- type CurveSegment
- func (c CurveSegment) Clone() Segment
- func (c CurveSegment) ControlEnd() Point
- func (c CurveSegment) ControlStart() Point
- func (c CurveSegment) End() Point
- func (c CurveSegment) SetStart(p Point) Segment
- func (c CurveSegment) Start() Point
- func (c CurveSegment) SvgString(numDecimals int) string
- func (c CurveSegment) UniqueString(numDecimals int) string
- type DefaultSegmentOperators
- func (do DefaultSegmentOperators) BoundingBox(segment Segment) (topLeft, bottomRight Point, err error)
- func (do DefaultSegmentOperators) Intersect(s1, s2 Segment) ([]Point, error)
- func (do DefaultSegmentOperators) Join(s1, s2 Segment) ([]Segment, error)
- func (do DefaultSegmentOperators) JoinCurveAndLine(c1 CurveSegment, c2 LineSegment) ([]Segment, error)
- func (do DefaultSegmentOperators) JoinCurves(c1, c2 CurveSegment) ([]Segment, error)
- func (do DefaultSegmentOperators) JoinLineAndCurve(c1 LineSegment, c2 CurveSegment) ([]Segment, error)
- func (do DefaultSegmentOperators) JoinLines(l1, l2 LineSegment) ([]Segment, error)
- func (do DefaultSegmentOperators) Move(s Segment, amount Point) (Segment, error)
- func (do DefaultSegmentOperators) Offset(segment Segment, distance float64) (ret []Segment, err error)
- func (do DefaultSegmentOperators) Reverse(segment Segment) (Segment, error)
- func (do DefaultSegmentOperators) Split(segment Segment, point Point) (ret []Segment, err error)
- func (do DefaultSegmentOperators) TransformPoints(s Segment, pt PointTransform) (Segment, error)
- type Draw
- func (d *Draw) AddSegment(seg Segment)
- func (d *Draw) AddSegments(segs []Segment)
- func (d *Draw) Circle(r float64)
- func (d *Draw) CurrentPosition() Point
- func (d *Draw) CurveTo(controlPointStart, controlPointEnd, point Point)
- func (d *Draw) HLineTo(dx float64)
- func (d *Draw) LineByAngle(length, angle float64)
- func (d *Draw) LineTo(point Point)
- func (d *Draw) MoveTo(point Point)
- func (d *Draw) Path() Path
- func (d *Draw) QCurveTo(controlPoint, point Point)
- func (d *Draw) Rect(w, h float64)
- func (d *Draw) RelCurveTo(controlPointStartDxDy, controlPointEndDxDy, dxdy Point)
- func (d *Draw) RelHLineTo(dx float64)
- func (d *Draw) RelLineTo(dxdy Point)
- func (d *Draw) RelMoveTo(dxdy Point)
- func (d *Draw) RelQCurveTo(controlPointEndDxDy, dxdy Point)
- func (d *Draw) RelRoundedCornerTo(dxdy Point, dxdyCorner Point, radius float64)
- func (d *Draw) RelSmoothCurveTo(controlPointEndDxDy, dxdy Point)
- func (d *Draw) RelVLineTo(dy float64)
- func (d *Draw) RoundedCornerTo(to Point, corner Point, radius float64)
- func (d *Draw) SmoothCurveTo(controlPointEnd, point Point)
- func (d *Draw) SvgPath(svg string) error
- func (d *Draw) ToAbsPosition(dxdy Point) Point
- func (d *Draw) VLineTo(dy float64)
- type LineSegment
- func (l LineSegment) Angle() float64
- func (l LineSegment) Clone() Segment
- func (l LineSegment) End() Point
- func (l LineSegment) EvalX(x float64) float64
- func (l LineSegment) IsHorizontalPrecision(precision int) bool
- func (l LineSegment) IsVerticalPrecision(precision int) bool
- func (l LineSegment) Length() float64
- func (l LineSegment) PointAtDistance(distance float64) Point
- func (l LineSegment) SetStart(p Point) Segment
- func (l LineSegment) Slope() float64
- func (l LineSegment) Start() Point
- func (l LineSegment) SvgString(numDecimals int) string
- func (l LineSegment) UniqueString(numDecimals int) string
- func (l LineSegment) YIntercept() float64
- type MoveSegment
- type Params
- type Path
- type PathAttr
- type PathImpl
- type PathTransform
- type Point
- func BoundingBoxTrimWhitespace(p Path, so SegmentOperators) (topLeft, bottomRight Point, err error)
- func BoundingBoxWithWhitespace(p Path, so SegmentOperators) (topLeft, bottomRight Point, err error)
- func GetStartAndEnd(segments []Segment) (start, end Point)
- func HorizontalIntercepts(p Path, y float64, so SegmentOperators) ([]Point, error)
- func LineIntersection(l1, l2 LineSegment, precision int) (p Point, success bool)
- func NewPoint(x float64, y float64) Point
- func NewPointRounded(x float64, y float64) Point
- func PathCursor(p Path) Point
- func PointPathAttribute(pos PathAttr, p Path, so SegmentOperators) (Point, error)
- func PolarToCartesian(r, theta float64) Point
- func Rotate(degree float64, point Point) Point
- type PointTransform
- type Segment
- func FixHeadMove(seg []Segment) []Segment
- func HeadMove(seg []Segment) []Segment
- func KnifeCut(seg Segment, knife Segment, so SegmentOperators) ([]Segment, error)
- func SetSegmentStart(segment Segment, start Point) (Segment, error)
- func Tail(seg []Segment) Segment
- func TrimFirst(seg []Segment) []Segment
- func TrimLast(seg []Segment) []Segment
- func TrimMove(seg []Segment) []Segment
- func TrimTailMove(seg []Segment) []Segment
- type SegmentOperators
- type SegmentTransform
- type SvgCommand
Constants ¶
const (
DefaultPrecision = 3 // how many decimal places do we want to consider
)
const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1
Variables ¶
This section is empty.
Functions ¶
func DegreesToRadians ¶
func Distance ¶
Distance finds the straightline distance between the two points distance will never be negative
func Float64ArrayContains ¶
func Float64ArrayDeDup ¶
removes any duplicates from the array order may or may not be maintained
func Float64ArrayInsertIfAbsent ¶
inserts the requested item if it does not already exist
func IsEmptyPath ¶
returns true if the path either has no segments, or contains only Move segments
func PathAttribute ¶
func PathAttribute(attr string, p Path, so SegmentOperators) (interface{}, error)
func PointInBoundingBox ¶
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 ¶
compares two floats based on the passed in precision f1 == f2 => 0 f1 < f2 => -1 f1 > f2 => 1
func PrecisionEquals ¶
determines equality based on the number of digits of precision
func StringArrayDeDup ¶
removes any duplicates maintaining ordering
func StringElipses ¶
will trim a string to the requested length and add elipses
Types ¶
type BezierCurveOperators ¶
type BezierCurveOperators struct { // 0.5? CurveIntersectionThreshold float64 }
the default implementation of curve operators.
func NewBezierCurveOperators ¶
func NewBezierCurveOperators() BezierCurveOperators
func (BezierCurveOperators) BoundingBox ¶
func (b BezierCurveOperators) BoundingBox(curve Curve) (topLeft, bottomRight Point, err error)
func (BezierCurveOperators) IntersectCurve ¶
func (b BezierCurveOperators) IntersectCurve(curve1 Curve, curve2 Curve) ([]Point, error)
func (BezierCurveOperators) IntersectLine ¶
func (b BezierCurveOperators) IntersectLine(curve Curve, line LineSegment) ([]Point, error)
func (BezierCurveOperators) IntersectProjectedLine ¶
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.
type CurveOperators ¶
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 ¶
type CurveSegment struct { StartPoint Point ControlPointStart Point EndPoint Point ControlPointEnd Point }
func (CurveSegment) Clone ¶
func (c CurveSegment) Clone() Segment
func (CurveSegment) ControlEnd ¶
func (c CurveSegment) ControlEnd() Point
func (CurveSegment) ControlStart ¶
func (c CurveSegment) ControlStart() Point
func (CurveSegment) End ¶
func (c CurveSegment) End() Point
func (CurveSegment) SetStart ¶
func (c CurveSegment) SetStart(p Point) Segment
func (CurveSegment) Start ¶
func (c CurveSegment) Start() Point
func (CurveSegment) SvgString ¶
func (c CurveSegment) SvgString(numDecimals int) string
func (CurveSegment) UniqueString ¶
func (c CurveSegment) UniqueString(numDecimals int) string
type DefaultSegmentOperators ¶
type DefaultSegmentOperators struct { CurveOperators CurveOperators Precision int }
contains the segment operators for all the segments except some special Curve operators
func (DefaultSegmentOperators) BoundingBox ¶
func (do DefaultSegmentOperators) BoundingBox(segment Segment) (topLeft, bottomRight Point, err error)
func (DefaultSegmentOperators) Intersect ¶
func (do DefaultSegmentOperators) Intersect(s1, s2 Segment) ([]Point, error)
func (DefaultSegmentOperators) Join ¶
func (do DefaultSegmentOperators) Join(s1, s2 Segment) ([]Segment, error)
func (DefaultSegmentOperators) JoinCurveAndLine ¶
func (do DefaultSegmentOperators) JoinCurveAndLine(c1 CurveSegment, c2 LineSegment) ([]Segment, error)
func (DefaultSegmentOperators) JoinCurves ¶
func (do DefaultSegmentOperators) JoinCurves(c1, c2 CurveSegment) ([]Segment, error)
func (DefaultSegmentOperators) JoinLineAndCurve ¶
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 ¶
func (do DefaultSegmentOperators) JoinLines(l1, l2 LineSegment) ([]Segment, error)
Joins the two lines by finding the intersection
func (DefaultSegmentOperators) Move ¶
func (do DefaultSegmentOperators) Move(s Segment, amount Point) (Segment, error)
func (DefaultSegmentOperators) Offset ¶
func (do DefaultSegmentOperators) Offset(segment Segment, distance float64) (ret []Segment, err error)
func (DefaultSegmentOperators) Reverse ¶
func (do DefaultSegmentOperators) Reverse(segment Segment) (Segment, error)
func (DefaultSegmentOperators) Split ¶
func (do DefaultSegmentOperators) Split(segment Segment, point Point) (ret []Segment, err error)
func (DefaultSegmentOperators) TransformPoints ¶
func (do DefaultSegmentOperators) TransformPoints(s Segment, pt PointTransform) (Segment, error)
type Draw ¶
type Draw struct {
// contains filtered or unexported fields
}
a draw is decorator of a Path which has convenient drawing operations
func (*Draw) AddSegment ¶
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 ¶
func (*Draw) Circle ¶
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 ¶
func (*Draw) LineByAngle ¶
Draws a line from the current position based on length and angle
func (*Draw) RelCurveTo ¶
draws a Relative Curve this is the Cubic Bezier
func (*Draw) RelHLineTo ¶
Draws a horizontal line relative to the current position
func (*Draw) RelQCurveTo ¶
relative Quadratic curve. Note - we convert to cubic curves
func (*Draw) RelRoundedCornerTo ¶
func (*Draw) RelSmoothCurveTo ¶
draws a smooth curve. Note that this is converted to a Cubic Bezier
func (*Draw) RelVLineTo ¶
Draws a vertical line relative to the current position
func (*Draw) RoundedCornerTo ¶
Round corner draws a 90 deg corner using a curve
func (*Draw) SmoothCurveTo ¶
draws a smooth curve. Note that this is converted to a Cubic Bezier
func (*Draw) ToAbsPosition ¶
type LineSegment ¶
func NewLineSegmentAngle ¶
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 ¶
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 ¶
func (l LineSegment) Angle() float64
the angle of the line in degrees. where a positive horizontal line is 0
func (LineSegment) Clone ¶
func (l LineSegment) Clone() Segment
func (LineSegment) End ¶
func (l LineSegment) End() Point
func (LineSegment) EvalX ¶
func (l LineSegment) EvalX(x float64) float64
gets the value of Y for the given X
func (LineSegment) IsHorizontalPrecision ¶
func (l LineSegment) IsHorizontalPrecision(precision int) bool
func (LineSegment) IsVerticalPrecision ¶
func (l LineSegment) IsVerticalPrecision(precision int) bool
returns true if this line is vertical
func (LineSegment) Length ¶
func (l LineSegment) Length() float64
func (LineSegment) PointAtDistance ¶
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 ¶
func (l LineSegment) SetStart(p Point) Segment
func (LineSegment) Slope ¶
func (l LineSegment) Slope() float64
func (LineSegment) Start ¶
func (l LineSegment) Start() Point
func (LineSegment) SvgString ¶
func (l LineSegment) SvgString(numDecimals int) string
func (LineSegment) UniqueString ¶
func (l LineSegment) UniqueString(numDecimals int) string
func (LineSegment) YIntercept ¶
func (l LineSegment) YIntercept() float64
type MoveSegment ¶
func (MoveSegment) Clone ¶
func (m MoveSegment) Clone() Segment
func (MoveSegment) End ¶
func (m MoveSegment) End() Point
func (MoveSegment) SetStart ¶
func (m MoveSegment) SetStart(p Point) Segment
func (MoveSegment) Start ¶
func (m MoveSegment) Start() Point
func (MoveSegment) SvgString ¶
func (m MoveSegment) SvgString(numDecimals int) string
func (MoveSegment) UniqueString ¶
func (m MoveSegment) UniqueString(numDecimals int) string
type Path ¶
func MultiTransform ¶
func MultiTransform(p Path, transforms ...PathTransform) (Path, error)
executes multiple transforms
func NewPathFromSegments ¶
func NewPathFromSegmentsWithoutMove ¶
creates a new Path from the passed in segments without adding a move at the beginning.
func ParsePathFromSvg ¶
parses a path from the SVG style string
func SplitPathOnMove ¶
splits the path into an array of paths, where each path begins with a move operation
type PathAttr ¶
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 ¶
func ToPathAttrFromPoint ¶
type PathImpl ¶
type PathImpl struct {
// contains filtered or unexported fields
}
func (*PathImpl) AddSegments ¶
type PathTransform ¶
transform a Path into a new Path
type Point ¶
func BoundingBoxTrimWhitespace ¶
func BoundingBoxTrimWhitespace(p Path, so SegmentOperators) (topLeft, bottomRight Point, err error)
func BoundingBoxWithWhitespace ¶
func BoundingBoxWithWhitespace(p Path, so SegmentOperators) (topLeft, bottomRight Point, err error)
gets the bounding box, including any trailing or leading whitespace
func GetStartAndEnd ¶
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 ¶
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 ¶
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 NewPointRounded ¶
creates a new point, with the values rounded to 3 decimal places
func PointPathAttribute ¶
func PointPathAttribute(pos PathAttr, p Path, so SegmentOperators) (Point, error)
func PolarToCartesian ¶
func (Point) Equals ¶
checks if the points are equal this check for exact equality (the floats must be the same)
func (Point) EqualsPrecision ¶
checks if the points are equal based to the requested number of decimal places
func (Point) StringPrecision ¶
func (Point) StringRounded ¶
type PointTransform ¶
type Segment ¶
type Segment interface { // SetStart(p Point) Segment Start() Point End() Point SvgString(numDecimals int) string UniqueString(numDecimals int) string Clone() Segment }
func FixHeadMove ¶
if the first move does not start at 0,0 then fix it
func KnifeCut ¶
func KnifeCut(seg Segment, knife Segment, so SegmentOperators) ([]Segment, error)
will split the segment wherever the knife segment intersects
func TrimTailMove ¶
removes any Move segments from the tail of the list
type SegmentOperators ¶
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 ¶
func NewSegmentOperators() SegmentOperators
type SegmentTransform ¶
transforma a segment
type SvgCommand ¶
type SvgCommand rune
const ( // These are the only supported Command types Move SvgCommand = 'M' Line SvgCommand = 'L' CurveCommand SvgCommand = 'C' ClosePath SvgCommand = 'Z' )