mirror of https://gitee.com/cf-fz/WebCAD.git
!1919 变更:在修改封边时,总是更新板的上下左右封边
parent
9f30433bea
commit
6c2f51331a
@ -0,0 +1,27 @@
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { Log } from "../../Common/Log";
|
||||
import { Curve } from "../../DatabaseServices/Entity/Curve";
|
||||
import { Command } from "../../Editor/CommandMachine";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { ParseEdgeSealDir } from "../../GraphicsSystem/ParseEdgeSealDir";
|
||||
|
||||
|
||||
export class Command_TestParseEdgeSealDir implements Command
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let ssRes = await app.Editor.GetSelection({ Filter: { filterTypes: [Curve] } });
|
||||
if (ssRes.Status !== PromptStatus.OK) return;
|
||||
let ents = ssRes.SelectSet.SelectEntityList as Curve[];
|
||||
|
||||
let arr = ParseEdgeSealDir(ents);
|
||||
Log(`左右上下,1234色,结果:${arr.join(",")}`);
|
||||
|
||||
for (let i = 0; i < arr.length; i++)
|
||||
{
|
||||
let id = arr[i];
|
||||
let c = ents[id];
|
||||
c.ColorIndex = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
import Flatbush from 'flatbush';
|
||||
import { Box3, Vector3 } from "three";
|
||||
import { Curve } from "../DatabaseServices/Entity/Curve";
|
||||
import { XAxis, YAxis } from '../Geometry/GeUtils';
|
||||
|
||||
/**
|
||||
* 分析曲线的上下左右位置的线
|
||||
* @param curves
|
||||
*/
|
||||
export function ParseEdgeSealDir(curves: Curve[]): [number, number, number, number]
|
||||
{
|
||||
let boxAll = new Box3;
|
||||
let boxs: Box3[] = [];
|
||||
|
||||
let fb = new Flatbush(curves.length);
|
||||
|
||||
for (let c of curves)
|
||||
{
|
||||
let box = c.BoundingBox;
|
||||
boxs.push(box);
|
||||
boxAll.union(box);
|
||||
|
||||
fb.add(box.min.x, box.min.y, box.max.x, box.max.y);
|
||||
}
|
||||
|
||||
fb.finish();
|
||||
|
||||
let leftids = fb.search(boxAll.min.x - 1, boxAll.min.y - 1, boxAll.min.x + 1, boxAll.max.y + 1);
|
||||
let rightids = fb.search(boxAll.max.x - 1, boxAll.min.y - 1, boxAll.max.x + 1, boxAll.max.y + 1);
|
||||
let topids = fb.search(boxAll.min.x - 1, boxAll.max.y - 1, boxAll.max.x + 1, boxAll.max.y + 1);
|
||||
let bottomids = fb.search(boxAll.min.x - 1, boxAll.min.y - 1, boxAll.max.x + 1, boxAll.min.y + 1);
|
||||
|
||||
const FindBestCurveIndex = (ids: number[], dirRef: Vector3) =>
|
||||
{
|
||||
if (ids.length === 1) return ids[0];
|
||||
|
||||
let maxLength = -Infinity;
|
||||
let bestIndex = -1;
|
||||
for (let id of ids)
|
||||
{
|
||||
let c = curves[id];
|
||||
let dir = c.EndPoint.sub(c.StartPoint).normalize();
|
||||
let length = Math.abs(dir.dot(dirRef));//取模(模越长 表示和dirRef越平行(接近))
|
||||
if (length > maxLength)
|
||||
{
|
||||
bestIndex = id;
|
||||
maxLength = length;
|
||||
}
|
||||
}
|
||||
return bestIndex;
|
||||
};
|
||||
|
||||
let left = FindBestCurveIndex(leftids, YAxis);
|
||||
let right = FindBestCurveIndex(rightids, YAxis);
|
||||
let top = FindBestCurveIndex(topids, XAxis);
|
||||
let bottom = FindBestCurveIndex(bottomids, XAxis);
|
||||
|
||||
return [left, right, top, bottom];
|
||||
}
|
Loading…
Reference in new issue