!223 并集共线线段连接

Merge pull request !223 from ZoeLeeFZ/fixUnion
pull/223/MERGE
ZoeLeeFZ 6 years ago committed by ChenX
parent 641ec77c8c
commit 7307eaae5e

@ -8,13 +8,14 @@ import { Circle } from "./Circle";
import { Curve } from "./Curve";
import { Polyline } from "./Polyline";
import { Vector3 } from "three";
import { FixIndex } from "../Common/Utils";
export class Contour
{
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 instanceof Polyline && closeCurve.CloseMark === false)
@ -82,7 +83,31 @@ export class Contour
UnionBoolOperation(target: Contour): Contour[]
{
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完全被减去
SubstactBoolOperation(target: Contour): Contour[]
@ -193,16 +218,26 @@ export class Contour
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[] = []
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));
}
@ -213,11 +248,11 @@ export class Contour
* @returns
* @memberof Polyline
*/
static Combine(cus: Curve[]): Curve
static Combine(cus: Curve[], needLink = true): Curve
{
if (cus.length === 0) return undefined;
let groups = curveLinkGroup(cus);
let groups = needLink ? curveLinkGroup(cus) : [cus];
let joinCus: Curve[] = [];

@ -47,17 +47,6 @@ export class SurroundOutlineParse extends ISpaceParse
for (let pl of pls)
{
let cus = pl.Explode().filter(cu => !equaln(cu.Length, 0, 1e-6));
for (let i = 0; i < cus.length; i++)
{
let c1 = cus[i];
let nextI = FixIndex(i + 1, cus);
let c2 = cus[nextI];
if (c1.Join(c2))
{
cus.splice(nextI, 1);
i--;
}
}
this.m_Outlines.push(...cus);
}
}

Loading…
Cancel
Save