|
|
@ -8,13 +8,14 @@ import { Circle } from "./Circle";
|
|
|
|
import { Curve } from "./Curve";
|
|
|
|
import { Curve } from "./Curve";
|
|
|
|
import { Polyline } from "./Polyline";
|
|
|
|
import { Polyline } from "./Polyline";
|
|
|
|
import { Vector3 } from "three";
|
|
|
|
import { Vector3 } from "three";
|
|
|
|
|
|
|
|
import { FixIndex } from "../Common/Utils";
|
|
|
|
|
|
|
|
|
|
|
|
export class Contour
|
|
|
|
export class Contour
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private m_Curve: Polyline | Circle;
|
|
|
|
private m_Curve: Polyline | Circle;
|
|
|
|
static CreateContour(cus: Curve[])
|
|
|
|
static CreateContour(cus: Curve[], needLink = true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let closeCurve = Contour.Combine(cus) as Polyline | Circle;
|
|
|
|
let closeCurve = Contour.Combine(cus, needLink) as Polyline | Circle;
|
|
|
|
if (closeCurve && closeCurve.IsClose)
|
|
|
|
if (closeCurve && closeCurve.IsClose)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (closeCurve instanceof Polyline && closeCurve.CloseMark === false)
|
|
|
|
if (closeCurve instanceof Polyline && closeCurve.CloseMark === false)
|
|
|
@ -82,7 +83,31 @@ export class Contour
|
|
|
|
UnionBoolOperation(target: Contour): Contour[]
|
|
|
|
UnionBoolOperation(target: Contour): Contour[]
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let resultCus = this.getOperatedCurves(target);
|
|
|
|
let resultCus = this.getOperatedCurves(target);
|
|
|
|
return Contour.GetAllContour(resultCus.unionList);
|
|
|
|
//并集后的线段表如果有共线的直接合并起来
|
|
|
|
|
|
|
|
let cus: Curve[] = [];
|
|
|
|
|
|
|
|
for (let pl of resultCus.unionList)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (pl instanceof Polyline)
|
|
|
|
|
|
|
|
cus.push(...pl.Explode());
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
cus.push(pl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let cuGroups = curveLinkGroup(cus);
|
|
|
|
|
|
|
|
for (let g of cuGroups)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (let i = 0; i < g.length; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let c1 = g[i];
|
|
|
|
|
|
|
|
let nextI = FixIndex(i + 1, g);
|
|
|
|
|
|
|
|
let c2 = g[nextI];
|
|
|
|
|
|
|
|
if (c1.Join(c2))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
g.splice(nextI, 1);
|
|
|
|
|
|
|
|
i--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Contour.GetAllContour(cuGroups);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//差集:等于0完全被减去
|
|
|
|
//差集:等于0完全被减去
|
|
|
|
SubstactBoolOperation(target: Contour): Contour[]
|
|
|
|
SubstactBoolOperation(target: Contour): Contour[]
|
|
|
@ -193,16 +218,26 @@ export class Contour
|
|
|
|
return { intersectionList, unionList, subtractList };
|
|
|
|
return { intersectionList, unionList, subtractList };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获得所有闭合的轮廓.
|
|
|
|
/**
|
|
|
|
static GetAllContour(cus: Curve[])
|
|
|
|
* 获得全部闭合曲线
|
|
|
|
|
|
|
|
* @若传入二维曲线数据,将默认子数组为闭合曲线段
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GetAllContour(cus: Curve[] | Curve[][]): Contour[]
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let cuGroups = curveLinkGroup(cus);
|
|
|
|
if (cus.length === 0)
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let cuGroups: Curve[][];
|
|
|
|
|
|
|
|
if (Array.isArray(cus[0]))
|
|
|
|
|
|
|
|
cuGroups = cus as Curve[][];
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
cuGroups = curveLinkGroup(cus as Curve[]);
|
|
|
|
|
|
|
|
|
|
|
|
let contours: Contour[] = []
|
|
|
|
let contours: Contour[] = []
|
|
|
|
|
|
|
|
|
|
|
|
cuGroups.forEach(cus =>
|
|
|
|
cuGroups.forEach(c =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
contours.push(Contour.CreateContour(cus));
|
|
|
|
contours.push(Contour.CreateContour(c, false));
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return contours.filter(c => c !== undefined && !equaln(c.Area, 0, 1e-6));
|
|
|
|
return contours.filter(c => c !== undefined && !equaln(c.Area, 0, 1e-6));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -213,11 +248,11 @@ export class Contour
|
|
|
|
* @returns
|
|
|
|
* @returns
|
|
|
|
* @memberof Polyline
|
|
|
|
* @memberof Polyline
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static Combine(cus: Curve[]): Curve
|
|
|
|
static Combine(cus: Curve[], needLink = true): Curve
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (cus.length === 0) return undefined;
|
|
|
|
if (cus.length === 0) return undefined;
|
|
|
|
|
|
|
|
|
|
|
|
let groups = curveLinkGroup(cus);
|
|
|
|
let groups = needLink ? curveLinkGroup(cus) : [cus];
|
|
|
|
|
|
|
|
|
|
|
|
let joinCus: Curve[] = [];
|
|
|
|
let joinCus: Curve[] = [];
|
|
|
|
|
|
|
|
|
|
|
|