MCPcopy Create free account
hub / github.com/openscopeproject/InteractiveHtmlBom / getCachedPadPath

Function getCachedPadPath

InteractiveHtmlBom/web/render.js:271–290  ·  view source on GitHub ↗
(pad)

Source from the content-addressed store, hash-verified

269}
270
271function getCachedPadPath(pad) {
272 if (!pad.path2d) {
273 // if path2d is not set, build one and cache it on pad object
274 if (pad.shape == "rect") {
275 pad.path2d = new Path2D();
276 pad.path2d.rect(...pad.size.map(c => -c * 0.5), ...pad.size);
277 } else if (pad.shape == "oval") {
278 pad.path2d = getOblongPath(pad.size);
279 } else if (pad.shape == "circle") {
280 pad.path2d = getCirclePath(pad.size[0] / 2);
281 } else if (pad.shape == "roundrect") {
282 pad.path2d = getChamferedRectPath(pad.size, pad.radius, 0, 0);
283 } else if (pad.shape == "chamfrect") {
284 pad.path2d = getChamferedRectPath(pad.size, pad.radius, pad.chamfpos, pad.chamfratio)
285 } else if (pad.shape == "custom") {
286 pad.path2d = getPolygonsPath(pad);
287 }
288 }
289 return pad.path2d;
290}
291
292function drawPad(ctx, pad, color, outline) {
293 ctx.save();

Callers 2

drawPadFunction · 0.85
pointWithinPadFunction · 0.85

Calls 4

getOblongPathFunction · 0.85
getCirclePathFunction · 0.85
getChamferedRectPathFunction · 0.85
getPolygonsPathFunction · 0.85

Tested by

no test coverage detected