- Fix router import path in main.js - Handle Django REST Framework pagination format in API calls - Add getTemplates function to project API - Restart frontend development server
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
import { getDistanceList } from "./basic.mjs";
|
|
//#region extensions/aligning_guidelines/util/collect-line.ts
|
|
function collectLine(target, points) {
|
|
const list = target.getCoords();
|
|
list.push(target.getCenterPoint());
|
|
const opts = {
|
|
target,
|
|
list,
|
|
points,
|
|
margin: this.margin / this.canvas.getZoom()
|
|
};
|
|
return {
|
|
vLines: collectPoints({
|
|
...opts,
|
|
type: "x"
|
|
}),
|
|
hLines: collectPoints({
|
|
...opts,
|
|
type: "y"
|
|
})
|
|
};
|
|
}
|
|
const originArr = [
|
|
["left", "top"],
|
|
["right", "top"],
|
|
["right", "bottom"],
|
|
["left", "bottom"],
|
|
["center", "center"]
|
|
];
|
|
function collectPoints(props) {
|
|
const { target, list, points, margin, type } = props;
|
|
const res = [];
|
|
const arr = [];
|
|
let min = Infinity;
|
|
for (const item of list) {
|
|
const o = getDistanceList(item, points, type);
|
|
arr.push(o);
|
|
if (min > o.dis) min = o.dis;
|
|
}
|
|
if (min > margin) return res;
|
|
let b = false;
|
|
for (let i = 0; i < list.length; i++) {
|
|
if (arr[i].dis != min) continue;
|
|
for (const item of arr[i].arr) res.push({
|
|
origin: list[i],
|
|
target: item
|
|
});
|
|
if (b) continue;
|
|
b = true;
|
|
const d = arr[i].arr[0][type] - list[i][type];
|
|
list.forEach((item) => {
|
|
item[type] += d;
|
|
});
|
|
target.setXY(list[i], ...originArr[i]);
|
|
target.setCoords();
|
|
}
|
|
return res;
|
|
}
|
|
//#endregion
|
|
export { collectLine };
|
|
|
|
//# sourceMappingURL=collect-line.mjs.map
|