MCPcopy Create free account
hub / github.com/breck7/scroll / arcTo

Method arcTo

external/.d3.js:6089–6137  ·  view source on GitHub ↗
(x1, y1, x2, y2, r)

Source from the content-addressed store, hash-verified

6087 this._append`C${+x1},${+y1},${+x2},${+y2},${this._x1 = +x},${this._y1 = +y}`;
6088 }
6089 arcTo(x1, y1, x2, y2, r) {
6090 x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r;
6091
6092 // Is the radius negative? Error.
6093 if (r < 0) throw new Error(`negative radius: ${r}`);
6094
6095 let x0 = this._x1,
6096 y0 = this._y1,
6097 x21 = x2 - x1,
6098 y21 = y2 - y1,
6099 x01 = x0 - x1,
6100 y01 = y0 - y1,
6101 l01_2 = x01 * x01 + y01 * y01;
6102
6103 // Is this path empty? Move to (x1,y1).
6104 if (this._x1 === null) {
6105 this._append`M${this._x1 = x1},${this._y1 = y1}`;
6106 }
6107
6108 // Or, is (x1,y1) coincident with (x0,y0)? Do nothing.
6109 else if (!(l01_2 > epsilon$4));
6110
6111 // Or, are (x0,y0), (x1,y1) and (x2,y2) collinear?
6112 // Equivalently, is (x1,y1) coincident with (x2,y2)?
6113 // Or, is the radius zero? Line to (x1,y1).
6114 else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon$4) || !r) {
6115 this._append`L${this._x1 = x1},${this._y1 = y1}`;
6116 }
6117
6118 // Otherwise, draw an arc!
6119 else {
6120 let x20 = x2 - x0,
6121 y20 = y2 - y0,
6122 l21_2 = x21 * x21 + y21 * y21,
6123 l20_2 = x20 * x20 + y20 * y20,
6124 l21 = Math.sqrt(l21_2),
6125 l01 = Math.sqrt(l01_2),
6126 l = r * Math.tan((pi$2 - Math.acos((l21_2 + l01_2 - l20_2) / (2 * l21 * l01))) / 2),
6127 t01 = l / l01,
6128 t21 = l / l21;
6129
6130 // If the start tangent is not coincident with (x0,y0), line to.
6131 if (Math.abs(t01 - 1) > epsilon$4) {
6132 this._append`L${x1 + t01 * x01},${y1 + t01 * y01}`;
6133 }
6134
6135 this._append`A${r},${r},0,0,${+(y01 * x20 > x01 * y20)},${this._x1 = x1 + t21 * x21},${this._y1 = y1 + t21 * y21}`;
6136 }
6137 }
6138 arc(x, y, r, a0, a1, ccw) {
6139 x = +x, y = +y, r = +r, ccw = !!ccw;
6140

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected