@tscircuit/routing
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -1,9 +0,5 @@ | ||
import type { StorybookConfig } from "@storybook/nextjs"; | ||
import type { StorybookConfig } from "@storybook/nextjs" | ||
const config: StorybookConfig = { | ||
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], | ||
addons: [ | ||
"@storybook/addon-links", | ||
"@storybook/addon-essentials", | ||
"@storybook/addon-interactions", | ||
], | ||
addons: [], | ||
framework: { | ||
@@ -13,6 +9,3 @@ name: "@storybook/nextjs", | ||
}, | ||
docs: { | ||
autodocs: "tag", | ||
}, | ||
}; | ||
export default config; | ||
} | ||
export default config |
@@ -120,2 +120,6 @@ type Obstacle = { | ||
export { FoundPath, Grid, Obstacle, Path, PathFindingParameters, PathFindingResult, Point, findRoute, findSchematicRoute, findTwoPointGranularRoute, findTwoPointMixedGranularityRoute, findTwoPointNearBiasRoute, findTwoPointSchematicRoute, getPointDistance, isInObstacle }; | ||
declare const movePointsOutsideObstacles: (params: PathFindingParameters, opts?: { | ||
margin: number; | ||
}) => PathFindingParameters; | ||
export { FoundPath, Grid, Obstacle, Path, PathFindingParameters, PathFindingResult, Point, findRoute, findSchematicRoute, findTwoPointGranularRoute, findTwoPointMixedGranularityRoute, findTwoPointNearBiasRoute, findTwoPointSchematicRoute, getPointDistance, isInObstacle, movePointsOutsideObstacles }; |
@@ -39,3 +39,4 @@ var __create = Object.create; | ||
getPointDistance: () => getPointDistance, | ||
isInObstacle: () => isInObstacle | ||
isInObstacle: () => isInObstacle, | ||
movePointsOutsideObstacles: () => movePointsOutsideObstacles | ||
}); | ||
@@ -611,2 +612,37 @@ module.exports = __toCommonJS(src_exports); | ||
}; | ||
// src/lib/move-points-outside-obstacles.ts | ||
var movePointsOutsideObstacles = (params, opts) => { | ||
const { pointsToConnect, obstacles } = params; | ||
const { margin = params.grid.segmentSize } = opts ?? {}; | ||
const pointsToConnectOutsideObstacles = pointsToConnect.map((oldPoint) => { | ||
const newPoint = { ...oldPoint }; | ||
for (const obstacle of obstacles) { | ||
if (isInObstacle({ point: newPoint, obstacles: [obstacle], margin })) { | ||
const { center, width, height } = obstacle; | ||
let udx = Math.sign(newPoint.x - center.x); | ||
let udy = Math.sign(newPoint.y - center.y); | ||
if (udx === 0) | ||
udx = 1; | ||
if (udy === 0) | ||
udy = 1; | ||
const x_edge = center.x + width / 2 * udx; | ||
const y_edge = center.y + height / 2 * udy; | ||
const dx_edge = Math.abs(newPoint.x - x_edge); | ||
const dy_edge = Math.abs(newPoint.y - y_edge); | ||
const y_edge_is_closer = dy_edge < dx_edge; | ||
if (y_edge_is_closer) { | ||
newPoint.y = y_edge + margin * udy; | ||
} else { | ||
newPoint.x = x_edge + margin * udx; | ||
} | ||
} | ||
} | ||
return newPoint; | ||
}); | ||
return { | ||
...params, | ||
pointsToConnect: pointsToConnectOutsideObstacles | ||
}; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -621,3 +657,4 @@ 0 && (module.exports = { | ||
getPointDistance, | ||
isInObstacle | ||
isInObstacle, | ||
movePointsOutsideObstacles | ||
}); |
{ | ||
"name": "@tscircuit/routing", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -10,1 +10,2 @@ export * from "./is-in-obstacle" | ||
export * from "./find-two-point-schematic-route" | ||
export * from "./move-points-outside-obstacles" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83335
45
2822