曲线组求交

pull/68/head
ChenX 6 years ago
parent ec159ee25e
commit 45c8ec11e8

@ -0,0 +1,72 @@
import { Box3, Vector3 } from "three";
import { Curve } from "../DatabaseServices/Curve";
import { IntersectOption } from "../GraphicsSystem/IntersectWith";
/**
*
* 线, (33.2 线 p599)
*
* @class CurveIntersection
*/
class CurveIntersection
{
//用来缓存的曲线包围盒
private boxMap: Map<Curve, Box3> = new Map();
/**
* ,key 线 value (线Map)
*
* @type {Map<Curve, Map<Curve, Vector3[]>>}
* @memberof CurveIntersection
*/
intersect: Map<Curve, Map<Curve, Vector3[]>> = new Map();
constructor(cus: Curve[])
{
cus.forEach(c =>
{
this.boxMap.set(c, c.BoundingBox);
});
//按x排序
cus.sort((c1, c2) =>
{
return this.boxMap.get(c1).min.x - this.boxMap.get(c2).min.x;
});
let count = cus.length;
for (let i = 0; i < count; i++)
{
let c1 = cus[i];
let c1d = this.GetIntersect(c1);
let c1b = this.boxMap.get(c1);
for (let j = i + 1; j < count; j++)
{
let c2 = cus[j];
//过滤掉不需要计算的曲线
let c2b = this.boxMap.get(c2);
if (c2b.min.x > c1b.max.x)
break;
if (c2b.min.y > c1b.max.y)
continue;
let pts = c1.IntersectWith(c2, IntersectOption.OnBothOperands);
if (pts.length > 0)
{
c1d.set(c2, pts);
this.GetIntersect(c2).set(c1, pts);
}
}
}
}
GetIntersect(cu: Curve): Map<Curve, Vector3[]>
{
if (this.intersect.has(cu))
return this.intersect.get(cu);
let m = new Map();
this.intersect.set(cu, m);
return m;
}
}
Loading…
Cancel
Save