Skip to content

Commit

Permalink
Support arc tracks
Browse files Browse the repository at this point in the history
Closes #230
  • Loading branch information
Funkenjaeger authored and qu1ck committed Mar 1, 2021
1 parent e47db71 commit 2ad2be4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 15 deletions.
44 changes: 33 additions & 11 deletions InteractiveHtmlBom/ecad/schema/genericjsonpcbdata_v1.schema
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,39 @@
},
"Track": {
"type": "object",
"additionalProperties": false,
"properties": {
"start": { "$ref": "#/definitions/Coordinates" },
"end": { "$ref": "#/definitions/Coordinates" },
"width": { "type": "number" },
"net": { "type": "string" }
},
"required": [
"start",
"end",
"width"
"oneOf":[
{
"additionalProperties": false,
"properties": {
"start": { "$ref": "#/definitions/Coordinates" },
"end": { "$ref": "#/definitions/Coordinates" },
"width": { "type": "number" },
"net": { "type": "string" }
},
"required": [
"start",
"end",
"width"
]
},
{
"additionalProperties": false,
"properties": {
"center": { "$ref": "#/definitions/Coordinates" },
"startangle": { "type": "number" },
"endangle": { "type": "number" },
"radius": { "type": "number" },
"width": { "type": "number" },
"net": { "type": "string" }
},
"required": [
"center",
"startangle",
"endangle",
"radius",
"width"
]
}
]
},
"Zones": {
Expand Down
55 changes: 51 additions & 4 deletions InteractiveHtmlBom/web/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,16 @@ function drawTracks(canvas, layer, color, highlight) {
if (highlight && highlightedNet != track.net) continue;
ctx.lineWidth = track.width;
ctx.beginPath();
ctx.moveTo(...track.start);
ctx.lineTo(...track.end);
if ('radius' in track) {
ctx.arc(
...track.center,
track.radius,
deg2rad(track.startangle),
deg2rad(track.endangle));
} else {
ctx.moveTo(...track.start);
ctx.lineTo(...track.end);
}
ctx.stroke();
}
}
Expand Down Expand Up @@ -632,6 +640,39 @@ function pointWithinDistanceToSegment(x, y, x1, y1, x2, y2, d) {
return dx * dx + dy * dy <= d * d;
}

function modulo(n, mod) {
return ((n % mod) + mod ) % mod;
}

function pointWithinDistanceToArc(x, y, xc, yc, radius, startangle, endangle, d) {
var dx = x - xc;
var dy = y - yc;
var r_sq = dx * dx + dy * dy;
var rmin = Math.max(0, radius-d);
var rmax = radius + d;

if (r_sq < rmin * rmin || r_sq > rmax * rmax)
return false;

var angle1 = modulo(deg2rad(startangle), 2 * Math.PI);
var dx1 = xc + radius * Math.cos(angle1) - x;
var dy1 = yc + radius * Math.sin(angle1) - y;
if (dx1 * dx1 + dy1 * dy1 <= d * d)
return true;

var angle2 = modulo(deg2rad(endangle), 2 * Math.PI);
var dx2 = xc + radius * Math.cos(angle2) - x;
var dy2 = yc + radius * Math.sin(angle2) - y;
if (dx2 * dx2 + dy2 * dy2 <= d * d)
return true;

var angle = modulo(Math.atan2(dy, dx), 2 * Math.PI);
if (angle1 > angle2)
return (angle >= angle2 || angle <= angle1);
else
return (angle >= angle1 && angle <= angle2);
}

function pointWithinPad(x, y, pad) {
var v = [x - pad.pos[0], y - pad.pos[1]];
v = rotateVector(v, -pad.angle);
Expand All @@ -646,8 +687,14 @@ function netHitScan(layer, x, y) {
// Check track segments
if (settings.renderTracks && pcbdata.tracks) {
for(var track of pcbdata.tracks[layer]) {
if (pointWithinDistanceToSegment(x, y, ...track.start, ...track.end, track.width / 2)) {
return track.net;
if ('radius' in track) {
if (pointWithinDistanceToArc(x, y, ...track.center, track.radius, track.startangle, track.endangle, track.width / 2)) {
return track.net;
}
} else {
if (pointWithinDistanceToSegment(x, y, ...track.start, ...track.end, track.width / 2)) {
return track.net;
}
}
}
}
Expand Down

0 comments on commit 2ad2be4

Please sign in to comment.