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

Method ArcTo

path.go:494–532  ·  view source on GitHub ↗

ArcTo adds an arc with radii rx and ry, with rot the counter clockwise rotation with respect to the coordinate system in degrees, large and sweep booleans (see https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Arcs), and (x,y) the end position of the pen. The start position of the pen

(rx, ry, rot float64, large, sweep bool, x, y float64)

Source from the content-addressed store, hash-verified

492
493// ArcTo adds an arc with radii rx and ry, with rot the counter clockwise rotation with respect to the coordinate system in degrees, large and sweep booleans (see https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Arcs), and (x,y) the end position of the pen. The start position of the pen was given by a previous command's end point.
494func (p *Path) ArcTo(rx, ry, rot float64, large, sweep bool, x, y float64) {
495 start := p.Pos()
496 end := Point{x, y}
497 if start.Equals(end) {
498 return
499 }
500 if Equal(rx, 0.0) || math.IsInf(rx, 0) || Equal(ry, 0.0) || math.IsInf(ry, 0) {
501 p.LineTo(end.X, end.Y)
502 return
503 }
504
505 rx = math.Abs(rx)
506 ry = math.Abs(ry)
507 if Equal(rx, ry) {
508 rot = 0.0 // circle
509 } else if rx < ry {
510 rx, ry = ry, rx
511 rot += 90.0
512 }
513
514 phi := angleNorm(rot * math.Pi / 180.0)
515 if math.Pi <= phi { // phi is canonical within 0 <= phi < 180
516 phi -= math.Pi
517 }
518
519 // scale ellipse if rx and ry are too small
520 lambda := ellipseRadiiCorrection(start, rx, ry, phi, end)
521 if lambda > 1.0 {
522 rx *= lambda
523 ry *= lambda
524 }
525
526 if len(p.d) == 0 {
527 p.MoveTo(0.0, 0.0)
528 } else if p.d[len(p.d)-1] == CloseCmd {
529 p.MoveTo(p.d[len(p.d)-3], p.d[len(p.d)-2])
530 }
531 p.d = append(p.d, ArcToCmd, rx, ry, phi, fromArcFlags(large, sweep), end.X, end.Y, ArcToCmd)
532}
533
534// Arc adds an elliptical arc with radii rx and ry, with rot the counter clockwise rotation in degrees, and theta0 and theta1 the angles in degrees of the ellipse (before rot is applies) between which the arc will run. If theta0 < theta1, the arc will run in a CCW direction. If the difference between theta0 and theta1 is bigger than 360 degrees, one full circle will be drawn and the remaining part of diff % 360, e.g. a difference of 810 degrees will draw one full circle and an arc over 90 degrees.
535func (p *Path) Arc(rx, ry, rot, theta0, theta1 float64) {

Callers 15

PathMethod · 0.95
PathMethod · 0.95
JoinMethod · 0.95
ArcMethod · 0.95
SplitAtMethod · 0.95
ParseSVGPathFunction · 0.95
xmonotoneEllipticArcFunction · 0.95
TestPathReplaceFunction · 0.95
RoundedRectangleFunction · 0.95
EllipseFunction · 0.95
offsetMethod · 0.95
mainFunction · 0.95

Calls 8

PosMethod · 0.95
LineToMethod · 0.95
MoveToMethod · 0.95
EqualFunction · 0.85
angleNormFunction · 0.85
ellipseRadiiCorrectionFunction · 0.85
fromArcFlagsFunction · 0.85
EqualsMethod · 0.45

Tested by 1

TestPathReplaceFunction · 0.76