MCPcopy Index your code
hub / github.com/tdewolff/canvas / Direction

Method Direction

path.go:725–747  ·  view source on GitHub ↗

Direction returns the direction of the path at the given segment and t in [0.0,1.0] along that path. The direction is a vector of unit length.

(seg int, t float64)

Source from the content-addressed store, hash-verified

723
724// Direction returns the direction of the path at the given segment and t in [0.0,1.0] along that path. The direction is a vector of unit length.
725func (p *Path) Direction(seg int, t float64) Point {
726 if len(p.d) <= 4 {
727 return Point{}
728 }
729
730 curSeg := 0
731 iStart, iSeg, iEnd := 0, 0, 0
732 for i := 0; i < len(p.d); {
733 cmd := p.d[i]
734 if cmd == MoveToCmd {
735 if seg < curSeg {
736 pi := &Path{p.d[iStart:iEnd]}
737 return pi.direction(iSeg-iStart, t)
738 }
739 iStart = i
740 }
741 if seg == curSeg {
742 iSeg = i
743 }
744 i += cmdLen(cmd)
745 }
746 return Point{} // if segment doesn't exist
747}
748
749// CoordDirections returns the direction of the segment start/end points. It will return the average direction at the intersection of two end points, and for an open path it will simply return the direction of the start and end points of the path.
750func (p *Path) CoordDirections() []Point {

Callers 1

ShapeMethod · 0.80

Calls 2

directionMethod · 0.95
cmdLenFunction · 0.85

Tested by

no test coverage detected