MCPcopy
hub / github.com/microsoft/SandDance / rectangle

Function rectangle

docs/tests/v2/es6/js/sanddance.js:98144–98178  ·  view source on GitHub ↗
(_, x0, y0)

Source from the content-addressed store, hash-verified

98142 context = null;
98143
98144 function rectangle(_, x0, y0) {
98145 var buffer,
98146 x1 = x0 != null ? x0 : +x.call(this, _),
98147 y1 = y0 != null ? y0 : +y.call(this, _),
98148 w = +width.call(this, _),
98149 h = +height.call(this, _),
98150 s = Math.min(w, h) / 2,
98151 tl = clamp(+crTL.call(this, _), 0, s),
98152 tr = clamp(+crTR.call(this, _), 0, s),
98153 bl = clamp(+crBL.call(this, _), 0, s),
98154 br = clamp(+crBR.call(this, _), 0, s);
98155 if (!context) context = buffer = (0, _d3Path.path)();
98156
98157 if (tl <= 0 && tr <= 0 && bl <= 0 && br <= 0) {
98158 context.rect(x1, y1, w, h);
98159 } else {
98160 var x2 = x1 + w,
98161 y2 = y1 + h;
98162 context.moveTo(x1 + tl, y1);
98163 context.lineTo(x2 - tr, y1);
98164 context.bezierCurveTo(x2 - C * tr, y1, x2, y1 + C * tr, x2, y1 + tr);
98165 context.lineTo(x2, y2 - br);
98166 context.bezierCurveTo(x2, y2 - C * br, x2 - C * br, y2, x2 - br, y2);
98167 context.lineTo(x1 + bl, y2);
98168 context.bezierCurveTo(x1 + C * bl, y2, x1, y2 - C * bl, x1, y2 - bl);
98169 context.lineTo(x1, y1 + tl);
98170 context.bezierCurveTo(x1, y1 + C * tl, x1 + C * tl, y1, x1 + tl, y1);
98171 context.closePath();
98172 }
98173
98174 if (buffer) {
98175 context = null;
98176 return buffer + '' || null;
98177 }
98178 }
98179
98180 rectangle.x = function (_) {
98181 if (arguments.length) {

Callers

nothing calls this directly

Calls 6

clampFunction · 0.70
minMethod · 0.45
rectMethod · 0.45
moveToMethod · 0.45
lineToMethod · 0.45
closePathMethod · 0.45

Tested by

no test coverage detected