|
| 1 | +import { VectorHelperService } from "../../../../../lib/api/vector-helper.service"; |
| 2 | +import { ShapesHelperService } from "../../../../../lib/api/shapes-helper.service"; |
| 3 | +import initOpenCascade, { OpenCascadeInstance } from "../../../../../bitbybit-dev-occt/bitbybit-dev-occt"; |
| 4 | +import { OCCTEdge } from "./edge"; |
| 5 | +import { OccHelper } from "../../occ-helper"; |
| 6 | +import { OCCTGeom } from "../geom/geom"; |
| 7 | +import { OCCTWire } from "./wire"; |
| 8 | + |
| 9 | +describe('OCCT wire unit tests', () => { |
| 10 | + let wire: OCCTWire; |
| 11 | + let edge: OCCTEdge; |
| 12 | + let geom: OCCTGeom; |
| 13 | + let occHelper: OccHelper |
| 14 | + |
| 15 | + const closeToNr = 13; |
| 16 | + |
| 17 | + beforeAll(async () => { |
| 18 | + const occt: OpenCascadeInstance = await (initOpenCascade as any).default(); |
| 19 | + const vec = new VectorHelperService(); |
| 20 | + const s = new ShapesHelperService(); |
| 21 | + occHelper = new OccHelper(vec, s, occt); |
| 22 | + geom = new OCCTGeom(occt, occHelper); |
| 23 | + edge = new OCCTEdge(occt, occHelper); |
| 24 | + wire = new OCCTWire(occt, occHelper); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should create a circle edge of the right radius and it will mach the length', async () => { |
| 28 | + const w = wire.createCircleWire({ radius: 3, center: [1, 0, 0], direction: [0, 1, 0] }); |
| 29 | + const length = wire.getWireLength({ shape: w }).result; |
| 30 | + expect(length).toBe(18.849555921538762); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should create a square wire', async () => { |
| 34 | + const w = wire.createSquareWire({ size: 4, center: [1, 0, 0], direction: [0, 1, 0] }); |
| 35 | + const length = wire.getWireLength({ shape: w }).result; |
| 36 | + expect(length).toBe(16); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should create an open bezier wire', async () => { |
| 40 | + const w = wire.createBezier({ points: [[0, 0, 0], [1, 1, 0], [0, 2, 5]], closed: false }); |
| 41 | + const length = wire.getWireLength({ shape: w }).result; |
| 42 | + expect(length).toBe(5.72415866652804); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should create a closed bezier wire', async () => { |
| 46 | + const w = wire.createBezier({ points: [[0, 0, 0], [1, 1, 0], [0, 2, 5]], closed: true }); |
| 47 | + const length = wire.getWireLength({ shape: w }).result; |
| 48 | + expect(length).toBe(5.333863420641158); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should interpolate points', async () => { |
| 52 | + const w = wire.interpolatePoints({ points: [[0, 0, 0], [1, 1, 0], [0, 2, 5]], periodic: false, tolerance: 1e-7 }); |
| 53 | + const length = wire.getWireLength({ shape: w }).result; |
| 54 | + expect(length).toBe(7.256109149279404); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should interpolate points into periodic bspline', async () => { |
| 58 | + const w = wire.interpolatePoints({ points: [[0, 0, 0], [1, 1, 0], [0, 2, 5]], periodic: true, tolerance: 1e-7 }); |
| 59 | + const length = wire.getWireLength({ shape: w }).result; |
| 60 | + expect(length).toBe(13.782923673238976); |
| 61 | + }); |
| 62 | + |
| 63 | + |
| 64 | + it('should create open bspline through points', async () => { |
| 65 | + const w = wire.createBSpline({ points: [[0, 0, 0], [1, 1, 0], [0, 2, 5]], closed: false }); |
| 66 | + const length = wire.getWireLength({ shape: w }).result; |
| 67 | + expect(length).toBe(7.064531406714803); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should create closed bspline through points', async () => { |
| 71 | + const w = wire.createBSpline({ points: [[0, 0, 0], [1, 1, 0], [0, 2, 5]], closed: true }); |
| 72 | + const length = wire.getWireLength({ shape: w }).result; |
| 73 | + expect(length).toBe(14.120032294676554); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should create a polygon wire', async () => { |
| 77 | + const w = wire.createPolygonWire({ points: [[0, 0, 0], [1, 1, 0], [0, 2, 5]] }); |
| 78 | + const length = wire.getWireLength({ shape: w }).result; |
| 79 | + expect(length).toBe(11.99553079221423); |
| 80 | + }); |
| 81 | + |
| 82 | + it('should create a star wire', async () => { |
| 83 | + const w = wire.createStarWire({ numRays: 9, outerRadius: 5, innerRadius: 2, center: [0, 0, 0], direction: [0, 0, 1], half: false }); |
| 84 | + const length = wire.getWireLength({ shape: w }).result; |
| 85 | + const cornerPoints = edge.getCornerPointsOfEdgesForShape({ shape: w }).result; |
| 86 | + expect(cornerPoints.length).toBe(18); |
| 87 | + expect(length).toBe(57.5047112618376); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should create ellipse wire', async () => { |
| 91 | + const w = wire.createEllipseWire({ radiusMajor: 5, radiusMinor: 2, center: [0, 0, 0], direction: [0, 0, 1] }); |
| 92 | + const length = wire.getWireLength({ shape: w }).result; |
| 93 | + expect(length).toBe(23.07819782619483); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should create rectangle wire', async () => { |
| 97 | + const w = wire.createRectangleWire({ width: 5, length: 2, center: [0, 0, 0], direction: [0, 0, 1] }); |
| 98 | + const length = wire.getWireLength({ shape: w }).result; |
| 99 | + expect(length).toBe(14); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should create a parallelogram wire', async () => { |
| 103 | + const w = wire.createParallelogramWire({ width: 5, height: 2, center: [0, 0, 0], direction: [0, 1, 0], angle: 15, aroundCenter: true }); |
| 104 | + const length = wire.getWireLength({ shape: w }).result; |
| 105 | + expect(length).toBe(14.141104721640332); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should create a parallelogram wire of 0 angle', async () => { |
| 109 | + const w = wire.createParallelogramWire({ width: 5, height: 2, center: [0, 0, 0], direction: [0, 1, 0], angle: 0, aroundCenter: true }); |
| 110 | + const length = wire.getWireLength({ shape: w }).result; |
| 111 | + expect(length).toBe(14); |
| 112 | + }); |
| 113 | +}); |
| 114 | + |
0 commit comments