MCPcopy
hub / github.com/tdewolff/canvas / Offset

Method Offset

path_stroke.go:634–655  ·  view source on GitHub ↗

Offset offsets the path by w and returns a new path. A positive w will offset the path to the right-hand side, that is, it expands CCW oriented contours and contracts CW oriented contours. If you don't know the orientation you can use `Path.CCW` to find out, but if there may be self-intersection you

(w float64, tolerance float64)

Source from the content-addressed store, hash-verified

632
633// Offset offsets the path by w and returns a new path. A positive w will offset the path to the right-hand side, that is, it expands CCW oriented contours and contracts CW oriented contours. If you don't know the orientation you can use `Path.CCW` to find out, but if there may be self-intersection you should use `Path.Settle` to remove them and orient all filling contours CCW. The tolerance is the maximum deviation from the actual offset when flattening Béziers and optimizing the path.
634func (p *Path) Offset(w float64, tolerance float64) *Path {
635 if Equal(w, 0.0) {
636 return p
637 }
638
639 q := &Path{}
640 if !FastStroke {
641 // make sure all filling paths are CCW
642 p = p.Settle(NonZero) // TODO: set/check boolean if path is settled to avoid costly and unnecessary settling
643 }
644 for _, pi := range p.Split() {
645 rhs, _ := pi.offset(w, ButtCap, RoundJoin, false, tolerance)
646 if rhs != nil {
647 q = q.Append(rhs)
648 }
649 }
650 if !FastStroke {
651 // fix overlapping and spilled parts
652 q = q.Settle(Positive)
653 }
654 return q
655}
656
657// Stroke converts a path into a stroke of width w and returns a new path. It uses cr to cap the start and end of the path, and jr to join all path elements. If the path closes itself, it will use a join between the start and end instead of capping them. The tolerance is the maximum deviation from the original path when flattening Béziers and optimizing the stroke.
658func (p *Path) Stroke(w float64, cr Capper, jr Joiner, tolerance float64) *Path {

Callers 12

toPathMethod · 0.95
TestPathOffsetFunction · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
DecorateMethod · 0.80
mainFunction · 0.80

Calls 5

SettleMethod · 0.95
SplitMethod · 0.95
AppendMethod · 0.95
EqualFunction · 0.85
offsetMethod · 0.80

Tested by 1

TestPathOffsetFunction · 0.64