51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
|
|
//#region extensions/aligning_guidelines/util/basic.ts
|
||
|
|
function getDistance(a, b) {
|
||
|
|
return Math.abs(a - b);
|
||
|
|
}
|
||
|
|
function getDistanceList(point, list, type) {
|
||
|
|
let dis = Infinity;
|
||
|
|
let arr = [];
|
||
|
|
for (const item of list) {
|
||
|
|
const v = getDistance(point[type], item[type]);
|
||
|
|
if (dis > v) {
|
||
|
|
arr = [];
|
||
|
|
dis = v;
|
||
|
|
}
|
||
|
|
if (dis == v) arr.push(item);
|
||
|
|
}
|
||
|
|
return {
|
||
|
|
dis,
|
||
|
|
arr
|
||
|
|
};
|
||
|
|
}
|
||
|
|
function getPointMap(target) {
|
||
|
|
const coords = target.getCoords();
|
||
|
|
return {
|
||
|
|
tl: coords[0],
|
||
|
|
tr: coords[1],
|
||
|
|
br: coords[2],
|
||
|
|
bl: coords[3],
|
||
|
|
mt: coords[0].add(coords[1]).scalarDivide(2),
|
||
|
|
mr: coords[1].add(coords[2]).scalarDivide(2),
|
||
|
|
mb: coords[2].add(coords[3]).scalarDivide(2),
|
||
|
|
ml: coords[3].add(coords[0]).scalarDivide(2)
|
||
|
|
};
|
||
|
|
}
|
||
|
|
function getContraryMap(target) {
|
||
|
|
var _target$aCoords;
|
||
|
|
const aCoords = (_target$aCoords = target.aCoords) !== null && _target$aCoords !== void 0 ? _target$aCoords : target.calcACoords();
|
||
|
|
return {
|
||
|
|
tl: aCoords.br,
|
||
|
|
tr: aCoords.bl,
|
||
|
|
br: aCoords.tl,
|
||
|
|
bl: aCoords.tr,
|
||
|
|
mt: aCoords.br.add(aCoords.bl).scalarDivide(2),
|
||
|
|
mr: aCoords.bl.add(aCoords.tl).scalarDivide(2),
|
||
|
|
mb: aCoords.tl.add(aCoords.tr).scalarDivide(2),
|
||
|
|
ml: aCoords.tr.add(aCoords.br).scalarDivide(2)
|
||
|
|
};
|
||
|
|
}
|
||
|
|
//#endregion
|
||
|
|
export { getContraryMap, getDistanceList, getPointMap };
|
||
|
|
|
||
|
|
//# sourceMappingURL=basic.mjs.map
|