biscuitboard 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/npm.js CHANGED
@@ -14121,6 +14121,31 @@ var createBiscuitBoardAutorouter = (options = {}) => ({
14121
14121
  var createBiscuitBoardAutorouter2 = (options = {}) => createBiscuitBoardAutorouter(options);
14122
14122
 
14123
14123
  // lib/create-prefabricated-via-autorouter.ts
14124
+ var ROUTER_COORDINATE_SCALE = 1e6;
14125
+ var ROUTER_COORDINATE_EPSILON = 1e-7;
14126
+ var normalizeCoordinate = (value) => Math.round(value * ROUTER_COORDINATE_SCALE) / ROUTER_COORDINATE_SCALE;
14127
+ var normalizePoint = (point) => {
14128
+ const x = normalizeCoordinate(point.x);
14129
+ const y = normalizeCoordinate(point.y);
14130
+ if (Math.abs(x - point.x) <= ROUTER_COORDINATE_EPSILON && Math.abs(y - point.y) <= ROUTER_COORDINATE_EPSILON) {
14131
+ return point;
14132
+ }
14133
+ return { ...point, x, y };
14134
+ };
14135
+ var normalizeRouterTerminalCoordinates = (input) => {
14136
+ let inputChanged = false;
14137
+ const connections = input.connections.map((connection) => {
14138
+ const pointsToConnect = connection.pointsToConnect.map(normalizePoint);
14139
+ if (pointsToConnect.every(
14140
+ (point, pointIndex) => point === connection.pointsToConnect[pointIndex]
14141
+ )) {
14142
+ return connection;
14143
+ }
14144
+ inputChanged = true;
14145
+ return { ...connection, pointsToConnect };
14146
+ });
14147
+ return inputChanged ? { ...input, connections } : input;
14148
+ };
14124
14149
  var createPrefabricatedViaAutorouter = ({
14125
14150
  width,
14126
14151
  height,
@@ -14132,27 +14157,31 @@ var createPrefabricatedViaAutorouter = ({
14132
14157
  }) => ({
14133
14158
  ...createBiscuitBoardAutorouter2(options),
14134
14159
  algorithmFn: async (input) => {
14160
+ const normalizedInput = normalizeRouterTerminalCoordinates(input);
14135
14161
  const maximumTraceWidth = Math.max(
14136
- input.minTraceWidth,
14137
- input.nominalTraceWidth ?? 0,
14162
+ normalizedInput.minTraceWidth,
14163
+ normalizedInput.nominalTraceWidth ?? 0,
14138
14164
  minimumTraceWidth ?? 0,
14139
14165
  nominalTraceWidth,
14140
- ...input.connections.map(
14141
- (connection) => connection.width ?? input.minTraceWidth
14166
+ ...normalizedInput.connections.map(
14167
+ (connection) => connection.width ?? normalizedInput.minTraceWidth
14142
14168
  )
14143
14169
  );
14144
14170
  return new BiscuitBoardAutorouter(
14145
14171
  {
14146
- ...input,
14147
- minTraceWidth: Math.max(input.minTraceWidth, minimumTraceWidth ?? 0),
14172
+ ...normalizedInput,
14173
+ minTraceWidth: Math.max(
14174
+ normalizedInput.minTraceWidth,
14175
+ minimumTraceWidth ?? 0
14176
+ ),
14148
14177
  nominalTraceWidth: Math.max(
14149
- input.nominalTraceWidth ?? 0,
14178
+ normalizedInput.nominalTraceWidth ?? 0,
14150
14179
  nominalTraceWidth,
14151
14180
  minimumTraceWidth ?? 0
14152
14181
  ),
14153
- connections: input.connections.map((connection) => {
14182
+ connections: normalizedInput.connections.map((connection) => {
14154
14183
  const width2 = Math.max(
14155
- connection.width ?? input.minTraceWidth,
14184
+ connection.width ?? normalizedInput.minTraceWidth,
14156
14185
  minimumTraceWidth ?? 0
14157
14186
  );
14158
14187
  return {
@@ -14165,7 +14194,7 @@ var createPrefabricatedViaAutorouter = ({
14165
14194
  )
14166
14195
  };
14167
14196
  }),
14168
- obstacles: [...input.obstacles, ...reservedObstacles],
14197
+ obstacles: [...normalizedInput.obstacles, ...reservedObstacles],
14169
14198
  // The clad DRC measures clearance from the copper edge, while this
14170
14199
  // router bound constrains trace centerlines.
14171
14200
  minBoardEdgeClearance: edgeClearance + maximumTraceWidth / 2,