mirror of https://gitee.com/cf-fz/WebCAD.git
parent
6c72917f71
commit
5c74b7f840
@ -0,0 +1,8 @@
|
||||
import { Point } from "./Point";
|
||||
import convexHull from 'monotone-convex-hull-2d';
|
||||
export function ConvexHull2D(points: Point[]): Point[]
|
||||
{
|
||||
let pts = points.map(p => [p.x, p.y]);
|
||||
let indexs = convexHull(pts);
|
||||
return indexs.map(i => points[i]);
|
||||
}
|
@ -1,10 +1,6 @@
|
||||
|
||||
|
||||
export enum PlaceType
|
||||
{
|
||||
MinBox = 0,
|
||||
MinX = 1,
|
||||
MinY = 2,
|
||||
MaxX = 3,
|
||||
MaxY = 4,
|
||||
Box = 0,
|
||||
Hull = 1,
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
import { FixIndex } from "../Common/Utils";
|
||||
|
||||
export function RandomIndex(count: number): number
|
||||
export function RandomIndex(count: number, exclude?: number): number
|
||||
{
|
||||
let r = Math.random();
|
||||
let index = Math.floor(r * count);
|
||||
if (index === count) return 0;
|
||||
if (index === count) index = 0;
|
||||
if (index === exclude) index = FixIndex(index + 1, count);
|
||||
return index;
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
export function ShuffleArray<T = any>(array: T[])
|
||||
{
|
||||
for (let i = array.length - 1; i > 0; i--)
|
||||
{
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
import { app } from "../../ApplicationServices/Application";
|
||||
import { Point } from "../../DatabaseServices/Entity/Point";
|
||||
import { PromptStatus } from "../../Editor/PromptResult";
|
||||
import { ConvexHull2D } from "../ConvexHull2D";
|
||||
import { Path2Polyline } from "../Converter/Path2Polyline";
|
||||
import { HotCMD } from "../../Hot/HotCommand";
|
||||
|
||||
@HotCMD
|
||||
export class Command_TestHull
|
||||
{
|
||||
async exec()
|
||||
{
|
||||
let ssres = await app.Editor.GetSelection({ Filter: { filterTypes: [Point] } });
|
||||
if (ssres.Status !== PromptStatus.OK) return;
|
||||
|
||||
let ptents = ssres.SelectSet.SelectEntityList as Point[];
|
||||
|
||||
let pts = ptents.map(p => p.Position);
|
||||
let hull = ConvexHull2D(pts);
|
||||
let pl = Path2Polyline(hull);
|
||||
pl.CloseMark = true;
|
||||
app.Database.ModelSpace.Append(pl);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue