diff --git a/__test__/Booloperate/__snapshots__/circlebox.test.ts.snap b/__test__/Booloperate/__snapshots__/circlebox.test.ts.snap new file mode 100644 index 000000000..31dd9390c --- /dev/null +++ b/__test__/Booloperate/__snapshots__/circlebox.test.ts.snap @@ -0,0 +1,16 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`圆的包围盒 1`] = ` +Box3 { + "max": Vector3 { + "x": 797.2893269281506, + "y": 28.66753717738038, + "z": 0, + }, + "min": Vector3 { + "x": -653.9554950751378, + "y": -1422.577284825908, + "z": 0, + }, +} +`; diff --git a/__test__/Booloperate/circlebox.test.ts b/__test__/Booloperate/circlebox.test.ts new file mode 100644 index 000000000..7d82939b5 --- /dev/null +++ b/__test__/Booloperate/circlebox.test.ts @@ -0,0 +1,9 @@ +import { Circle } from "../../src/api"; +import { LoadEntityFromFileData } from "../Utils/LoadEntity.util"; + +test('圆的包围盒', () => +{ + let d = { "file": [1, "Region", 8, 2, 105, false, 1, 7, 0, [0.6691018466770633, 0.7431707198035619, 0, 0, -0.7431707198035619, 0.6691018466770633, 0, 0, 0, 0, -1, 0, 71.6669159265063, -696.9548738242638, 0, 1], 0, 0, true, [0.6691018466770633, 0.7431707198035619, 0, 0, -0.7431707198035619, 0.6691018466770633, 0, 0, 0, 0, -1, 0, 71.6669159265063, -696.9548738242638, 0, 1], 0, 1, 1, 1, 1, "Circle", 8, 2, 0, false, 0, 7, 0, [0.6691018466770633, 0.7431707198035619, 0, 0, 0.7431707198035619, -0.6691018466770633, 0, 0, 0, 0, -1, 0, 71.6669159265063, -696.9548738242638, 0, 1], 0, 0, true, [0.7431707198035619, -0.6691018466770633, 0, 0, 0.6691018466770633, 0.7431707198035619, 0, 0, 0, 0, -1, 0, -2215.799673512821, 1439.917154472948, 0, 1], 0, 1, 725.6224110016442, 0], "basePt": { "x": -653.9554950751378, "y": -1422.577284825908, "z": 0 }, "ucs": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] }; + let ens = LoadEntityFromFileData(d) as Circle[]; + expect(ens[0].BoundingBox).toMatchSnapshot(); +}); diff --git a/src/Common/Matrix4Utils.ts b/src/Common/Matrix4Utils.ts index 1a769f51e..7526e9ab0 100644 --- a/src/Common/Matrix4Utils.ts +++ b/src/Common/Matrix4Utils.ts @@ -1,6 +1,6 @@ import { Matrix4, Quaternion, Vector2, Vector3 } from 'three'; import { CoordinateSystem } from '../Geometry/CoordinateSystem'; -import { equaln, isParallelTo, ZAxis } from '../Geometry/GeUtils'; +import { equaln, isParallelTo } from '../Geometry/GeUtils'; /** * 设置矩阵的某列的向量 @@ -167,4 +167,4 @@ export function NormalMatrix(mtx: Matrix4) export const tempMatrix1 = new Matrix4; -export const ZMirrorMatrix = GetMirrorMat(ZAxis); +export const ZMirrorMatrix = GetMirrorMat(new Vector3(0, 0, 1)); diff --git a/src/DatabaseServices/Entity/Circle.ts b/src/DatabaseServices/Entity/Circle.ts index aec03dc23..55b662cd4 100644 --- a/src/DatabaseServices/Entity/Circle.ts +++ b/src/DatabaseServices/Entity/Circle.ts @@ -10,6 +10,7 @@ import { ObjectSnapMode } from '../../Editor/ObjectSnapMode'; import { Box3Ext } from '../../Geometry/Box'; import { BufferGeometryUtils } from '../../Geometry/BufferGeometryUtils'; import { angle, AsVector3, equaln, equalv2, MoveMatrix, polar, ZeroVec } from '../../Geometry/GeUtils'; +import { Orbit } from '../../Geometry/Orbit'; import { IntersectCircleAndArc, IntersectCircleAndCircle, IntersectEllipseAndCircleOrArc, IntersectLineAndCircle, IntersectOption, IntersectPolylineAndCurve, reverseIntersectOption } from '../../GraphicsSystem/IntersectWith'; import { RenderType } from '../../GraphicsSystem/RenderType'; import { Factory } from '../CADFactory'; @@ -238,9 +239,20 @@ export class Circle extends Curve } //******************** Curve function end*****************// + get BoundingBoxInOCS(): Box3Ext + { + return new Box3Ext(new Vector3(-this.Radius, -this.Radius), new Vector3(this.Radius, this.Radius)); + } + get BoundingBox(): Box3Ext { - return new Box3Ext().setFromPoints(this.GetGripPoints()); + let z = this.Normal; + let x = new Vector3; + let y = new Vector3; + Orbit.ComputUpDirection(z, y, x); + let m = new Matrix4().makeBasis(x, y, z).setPosition(this.Center); + //使用任意轴坐标系 以便我们正确的对齐世界坐标系 + return this.BoundingBoxInOCS.applyMatrix4(m); } InitDrawObject(renderType: RenderType = RenderType.Wireframe) diff --git a/src/Geometry/DrillParse/Face.ts b/src/Geometry/DrillParse/Face.ts index 2d86fa772..3f8454620 100644 --- a/src/Geometry/DrillParse/Face.ts +++ b/src/Geometry/DrillParse/Face.ts @@ -1,13 +1,13 @@ import { Box3, Matrix4, Vector3 } from "three"; import { MatrixPlanarizere } from "../../Common/Matrix4Utils"; +import { Contour } from "../../DatabaseServices/Contour"; import { Board } from "../../DatabaseServices/Entity/Board"; +import { Polyline } from "../../DatabaseServices/Entity/Polyline"; import { Region } from "../../DatabaseServices/Entity/Region"; import { BoolOpeartionType } from "../../GraphicsSystem/BoolOperateUtils"; import { Box3Ext } from "../Box"; import { equaln, XAxis } from "../GeUtils"; import { BoardFaceType } from "./BoardGetFace"; -import { Polyline } from "../../DatabaseServices/Entity/Polyline"; -import { Contour } from "../../DatabaseServices/Contour"; export interface BoardFaceParams {