Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitbybit-occt

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitbybit-occt - npm Package Compare versions

Comparing version 0.9.27 to 0.9.28

lib/services/shapes/shell.test.d.ts

18

lib/api/inputs/occ-inputs.d.ts

@@ -1414,2 +1414,20 @@ import { Base } from "./inputs";

}
class NGonWireDto {
/**
* Center of the circle
*/
center: Base.Point3;
/**
* Direction
*/
direction: Base.Vector3;
/**
* How many corners to create.
*/
nrCorners: number;
/**
* Radius of nGon
*/
radius: number;
}
class EllipseDto {

@@ -1416,0 +1434,0 @@ /**

3

lib/api/inputs/occ-inputs.js

@@ -877,2 +877,5 @@ // tslint:disable-next-line: no-namespace

OCCT.ParallelogramDto = ParallelogramDto;
class NGonWireDto {
}
OCCT.NGonWireDto = NGonWireDto;
class EllipseDto {

@@ -879,0 +882,0 @@ }

@@ -5,2 +5,3 @@ import { Base } from "./inputs";

parallelogram(width: number, height: number, angle: number, center: boolean): Base.Line3[];
ngon(n: number, radius: number, center: Base.Point2): Base.Line3[];
}

@@ -68,2 +68,12 @@ export class ShapesHelperService {

}
ngon(n, radius, center) {
const angle = (2 * Math.PI) / n;
const edges = [];
for (let i = 0; i < n; i++) {
const start = [center[0] + radius * Math.cos(i * angle), 0, center[1] + radius * Math.sin(i * angle)];
const end = [center[0] + radius * Math.cos((i + 1) * angle), 0, center[1] + radius * Math.sin((i + 1) * angle)];
edges.push({ start, end });
}
return edges;
}
}

5

lib/occ-helper.d.ts

@@ -64,4 +64,4 @@ import { Adaptor3d_Curve, BRepAdaptor_CompCurve_2, Geom2d_Curve, TopoDS_Shell, TopoDS_Solid, Geom_Circle, Geom_Curve, Geom_Ellipse, Geom_Surface, gp_Ax1, gp_Ax2, gp_Ax22d_2, gp_Ax2d_2, gp_Ax3, gp_Dir2d_4, gp_Dir_4, gp_Pln_3, gp_Pnt2d_3, gp_Pnt_3, gp_Vec2d_4, gp_Vec_4, gp_XYZ_2, Handle_Geom_Curve, OpenCascadeInstance, TopoDS_Compound, TopoDS_Edge, TopoDS_Face, TopoDS_Shape, TopoDS_Vertex, TopoDS_Wire } from '../bitbybit-dev-occt/bitbybit-dev-occt';

getEdgesLengths(inputs: Inputs.OCCT.ShapesDto<TopoDS_Edge>): number[];
getEdgeCenterOfMass(inputs: Inputs.OCCT.ShapeDto<TopoDS_Edge>): Base.Point3;
getEdgesCentersOfMass(inputs: Inputs.OCCT.ShapesDto<TopoDS_Edge>): Base.Point3[];
getLinearCenterOfMass(inputs: Inputs.OCCT.ShapeDto<TopoDS_Shape>): Base.Point3;
getShapesCentersOfMass(inputs: Inputs.OCCT.ShapesDto<TopoDS_Edge>): Base.Point3[];
getWireLength(inputs: Inputs.OCCT.ShapeDto<TopoDS_Wire>): number;

@@ -96,2 +96,3 @@ getWiresLengths(inputs: Inputs.OCCT.ShapesDto<TopoDS_Wire>): number[];

createParallelogramWire(inputs: Inputs.OCCT.ParallelogramDto): TopoDS_Edge | TopoDS_Compound | TopoDS_Wire | TopoDS_Vertex | TopoDS_Face | TopoDS_Shell | TopoDS_Solid;
createNGonWire(inputs: Inputs.OCCT.NGonWireDto): TopoDS_Edge | TopoDS_Compound | TopoDS_Wire | TopoDS_Vertex | TopoDS_Face | TopoDS_Shell | TopoDS_Solid;
createPolygonWire(inputs: Inputs.OCCT.PolygonDto): TopoDS_Wire;

@@ -98,0 +99,0 @@ private makeWireBetweenTwoPoints;

@@ -296,3 +296,3 @@ export var typeSpecificityEnum;

}
getEdgeCenterOfMass(inputs) {
getLinearCenterOfMass(inputs) {
const edge = inputs.shape;

@@ -306,4 +306,4 @@ const gprops = new this.occ.GProp_GProps_1();

}
getEdgesCentersOfMass(inputs) {
return inputs.shapes.map(edge => this.getEdgeCenterOfMass({ shape: edge }));
getShapesCentersOfMass(inputs) {
return inputs.shapes.map(edge => this.getLinearCenterOfMass({ shape: edge }));
}

@@ -562,2 +562,13 @@ getWireLength(inputs) {

}
createNGonWire(inputs) {
const lines = this.shapesHelperServide.ngon(inputs.nrCorners, inputs.radius, [0, 0]);
const edges = [];
lines.forEach(line => {
edges.push(this.lineEdge(line));
});
let wire = this.combineEdgesAndWiresIntoAWire({ shapes: edges });
let aligned = this.alignAndTranslateShape({ shape: wire, direction: inputs.direction, center: inputs.center });
wire.delete();
return aligned;
}
createPolygonWire(inputs) {

@@ -564,0 +575,0 @@ const gpPoints = [];

@@ -109,6 +109,6 @@ import { typeSpecificityEnum } from '../../occ-helper';

getEdgeCenterOfMass(inputs) {
return this.och.getEdgeCenterOfMass(inputs);
return this.och.getLinearCenterOfMass(inputs);
}
getEdgesCentersOfMass(inputs) {
return this.och.getEdgesCentersOfMass(inputs);
return this.och.getShapesCentersOfMass(inputs);
}

@@ -115,0 +115,0 @@ getCornerPointsOfEdgesForShape(inputs) {

@@ -355,3 +355,8 @@ import { shapeTypeEnum, typeSpecificityEnum } from '../../occ-helper';

});
return innerFace;
if (facesFound < inputs.index || inputs.index < 0) {
throw (new Error('Face index is out of range'));
}
else {
return innerFace;
}
}

@@ -358,0 +363,0 @@ getFaces(inputs) {

@@ -82,2 +82,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

expect(area).toBeCloseTo(2e+100);
srf.delete();
f.delete();
}));

@@ -91,2 +93,6 @@ it('should create an face from surface and wire', () => __awaiter(void 0, void 0, void 0, function* () {

expect(area).toBeCloseTo(12.566370614359167);
f1.delete();
srf.delete();
w.delete();
f.delete();
}));

@@ -97,2 +103,3 @@ it('should get u min bound', () => {

expect(uMin).toBe(-1);
f.delete();
});

@@ -103,2 +110,3 @@ it('should get u max bound', () => {

expect(uMax).toBe(1);
f.delete();
});

@@ -109,2 +117,3 @@ it('should get v min bound', () => {

expect(vMin).toBe(-0.5);
f.delete();
});

@@ -115,2 +124,3 @@ it('should get v max bound', () => {

expect(vMax).toBe(0.5);
f.delete();
});

@@ -164,2 +174,4 @@ it('should subdivide face into points', () => {

]);
sph.delete();
f.delete();
});

@@ -195,2 +207,4 @@ it('should subdivide face into points', () => {

]);
sph.delete();
f.delete();
});

@@ -220,2 +234,4 @@ it('should subdivide face into points, remove end edges and shift u and v directions', () => {

]);
sph.delete();
f.delete();
});

@@ -251,2 +267,4 @@ it('should subdivide into normals', () => {

]);
sph.delete();
f.delete();
});

@@ -276,2 +294,4 @@ it('should subdivide face into normals, remove end edges and shift u and v directions', () => {

]);
sph.delete();
f.delete();
});

@@ -297,2 +317,4 @@ it('should subdivide to points on param on u', () => {

]);
sph.delete();
f.delete();
});

@@ -318,2 +340,4 @@ it('should subdivide to points on param on v', () => {

]);
sph.delete();
f.delete();
});

@@ -340,2 +364,4 @@ it('should subdivide to points on param, remove start and end points and shift half step on v', () => {

]);
sph.delete();
f.delete();
});

@@ -362,2 +388,4 @@ it('should subdivide to points on param, remove start and end points and shift half step on u', () => {

]);
sph.delete();
f.delete();
});

@@ -383,2 +411,4 @@ it('should subdivide to points on param on u', () => {

]);
sph.delete();
f.delete();
});

@@ -404,2 +434,4 @@ it('should subdivide to points on param on u', () => {

]);
sph.delete();
f.delete();
});

@@ -425,2 +457,4 @@ it('should subdivide to points on param on v', () => {

]);
sph.delete();
f.delete();
});

@@ -448,2 +482,4 @@ it('should subdivide to points on param on u and remove edge points and shift step', () => {

]);
sph.delete();
f.delete();
});

@@ -471,3 +507,258 @@ it('should subdivide to points on param on v and remove edge points and shift step', () => {

]);
sph.delete();
f.delete();
});
it('should subdivide face into uvs', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const uvs = face.subdivideToUV({
shape: f,
nrDivisionsU: 5,
nrDivisionsV: 6,
removeEndEdgeU: false,
removeEndEdgeV: false,
removeStartEdgeU: false,
removeStartEdgeV: false,
shiftHalfStepU: false,
shiftHalfStepV: false,
});
expect(uvs.length).toBe(30);
expect(uvs).toEqual([
[0, -1.5707963267948966],
[0, -0.9424777960769379],
[0, -0.3141592653589793],
[0, 0.3141592653589793],
[0, 0.9424777960769379],
[0, 1.5707963267948966],
[1.5707963267948966, -1.5707963267948966],
[1.5707963267948966, -0.9424777960769379],
[1.5707963267948966, -0.3141592653589793],
[1.5707963267948966, 0.3141592653589793],
[1.5707963267948966, 0.9424777960769379],
[1.5707963267948966, 1.5707963267948966],
[3.141592653589793, -1.5707963267948966],
[3.141592653589793, -0.9424777960769379],
[3.141592653589793, -0.3141592653589793],
[3.141592653589793, 0.3141592653589793],
[3.141592653589793, 0.9424777960769379],
[3.141592653589793, 1.5707963267948966],
[4.71238898038469, -1.5707963267948966],
[4.71238898038469, -0.9424777960769379],
[4.71238898038469, -0.3141592653589793],
[4.71238898038469, 0.3141592653589793],
[4.71238898038469, 0.9424777960769379],
[4.71238898038469, 1.5707963267948966],
[6.283185307179586, -1.5707963267948966],
[6.283185307179586, -0.9424777960769379],
[6.283185307179586, -0.3141592653589793],
[6.283185307179586, 0.3141592653589793],
[6.283185307179586, 0.9424777960769379],
[6.283185307179586, 1.5707963267948966]
]);
sph.delete();
f.delete();
});
it('should subdivide face into uvs', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const uvs = face.subdivideToUV({
shape: f,
nrDivisionsU: 4,
nrDivisionsV: 3,
removeEndEdgeU: false,
removeEndEdgeV: false,
removeStartEdgeU: false,
removeStartEdgeV: false,
shiftHalfStepU: false,
shiftHalfStepV: false,
});
expect(uvs.length).toBe(12);
expect(uvs).toEqual([
[0, -1.5707963267948966],
[0, 0],
[0, 1.5707963267948966],
[2.0943951023931953, -1.5707963267948966],
[2.0943951023931953, 0],
[2.0943951023931953, 1.5707963267948966],
[4.1887902047863905, -1.5707963267948966],
[4.1887902047863905, 0],
[4.1887902047863905, 1.5707963267948966],
[6.283185307179586, -1.5707963267948966],
[6.283185307179586, 0],
[6.283185307179586, 1.5707963267948966]
]);
sph.delete();
f.delete();
});
it('should subdivide face into uvs remove end and start edges and shift half step both on u and v', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const uvs = face.subdivideToUV({
shape: f,
nrDivisionsU: 6,
nrDivisionsV: 5,
removeEndEdgeU: true,
removeEndEdgeV: true,
removeStartEdgeU: true,
removeStartEdgeV: true,
shiftHalfStepU: true,
shiftHalfStepV: true,
});
expect(uvs.length).toBe(12);
expect(uvs).toEqual([
[1.8849555921538759, -0.39269908169872414],
[1.8849555921538759, 0.39269908169872414],
[1.8849555921538759, 1.1780972450961724],
[3.141592653589793, -0.39269908169872414],
[3.141592653589793, 0.39269908169872414],
[3.141592653589793, 1.1780972450961724],
[4.39822971502571, -0.39269908169872414],
[4.39822971502571, 0.39269908169872414],
[4.39822971502571, 1.1780972450961724],
[5.654866776461628, -0.39269908169872414],
[5.654866776461628, 0.39269908169872414],
[5.654866776461628, 1.1780972450961724]
]);
sph.delete();
f.delete();
});
it('should get uv on face', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const uv = face.uvOnFace({ shape: f, paramU: 0.2, paramV: 0.3 });
expect(uv.length).toBe(2);
expect(uv).toEqual([
1.2566370614359172, -0.6283185307179586
]);
sph.delete();
f.delete();
});
it('should get points on uvs', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const points = face.pointsOnUVs({ shape: f, paramsUV: [[0.2, 0.3], [0, 0], [0.5, 0.4]] });
expect(points.length).toBe(3);
expect(points).toEqual([
[1.5388417685876268, -1.1755705045849463, 0.5000000000000001],
[0, -2, 1.2246467991473532e-16],
[2.3294166369781847e-16, -0.6180339887498948, -1.902113032590307]
]);
sph.delete();
f.delete();
});
it('should get normals on uvs', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const normals = face.normalsOnUVs({ shape: f, paramsUV: [[0.2, 0.3], [0, 0], [0.5, 0.4]] });
expect(normals.length).toBe(3);
expect(normals).toEqual([
[0.7694208842938133, -0.5877852522924731, 0.25000000000000006],
[0, -1, 1.2246467991473532e-16],
[1.1647083184890923e-16, -0.3090169943749474, -0.9510565162951536]
]);
sph.delete();
f.delete();
});
it('should get point on uv', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const point = face.pointOnUV({ shape: f, paramU: 0.2, paramV: 0.3 });
expect(point.length).toBe(3);
expect(point).toEqual([1.5388417685876268, -1.1755705045849463, 0.5000000000000001]);
sph.delete();
f.delete();
});
it('should get normal on uv', () => {
const sph = occHelper.bRepPrimAPIMakeSphere([0, 0, 0], [0, 1, 0], 2);
const f = face.getFace({ shape: sph, index: 0 });
const normal = face.normalOnUV({ shape: f, paramU: 0.2, paramV: 0.3 });
expect(normal.length).toBe(3);
expect(normal).toEqual([0.7694208842938133, -0.5877852522924731, 0.25000000000000006]);
sph.delete();
f.delete();
});
it('should create polygon face', () => {
const f = face.createPolygonFace({ points: [[0, 0, 0], [1, 0, -2], [1, 0, 0], [0, 0, 1]] });
const area = face.getFaceArea({ shape: f });
expect(area).toBe(1.5);
f.delete();
});
it('should create ellipse face', () => {
const f = face.createEllipseFace({ center: [0, 0, 0], radiusMinor: 1, radiusMajor: 2, direction: [0, 1, 0] });
const area = face.getFaceArea({ shape: f });
expect(area).toBe(6.283185307179584);
f.delete();
});
it('should not create ellipse face when radius major is smaller then minor', () => {
expect(() => face.createEllipseFace({ center: [0, 0, 0], radiusMinor: 2, radiusMajor: 1, direction: [0, 1, 0] }))
.toThrowError('Ellipse could not be created');
});
it('should create square face', () => {
const f = face.createSquareFace({ center: [0, 0, 0], size: 2, direction: [0, 1, 0] });
const area = face.getFaceArea({ shape: f });
expect(area).toBe(4);
f.delete();
});
it('should not get a face of a shape that does not have faces', () => __awaiter(void 0, void 0, void 0, function* () {
const d = occHelper.lineEdge({ start: [0, 0, 0], end: [1, 1, 1] });
expect(() => face.getFace({ shape: d, index: 22 })).toThrowError('Shape is not provided or is of incorrect type');
d.delete();
}));
it('should not get a face of a shape that does not have particular index', () => __awaiter(void 0, void 0, void 0, function* () {
const b = occHelper.bRepPrimAPIMakeBox(1, 1, 1, [0, 0, 0]);
expect(() => face.getFace({ shape: b, index: 22 })).toThrowError('Face index is out of range');
b.delete();
}));
it('should not get a face of a shape that does not have particular index', () => __awaiter(void 0, void 0, void 0, function* () {
const b = occHelper.bRepPrimAPIMakeBox(1, 1, 1, [0, 0, 0]);
expect(() => face.getFace({ shape: b, index: -22 })).toThrowError('Face index is out of range');
b.delete();
}));
it('should get faces', () => __awaiter(void 0, void 0, void 0, function* () {
const b = occHelper.bRepPrimAPIMakeBox(1, 1, 1, [0, 0, 0]);
const faces = face.getFaces({ shape: b });
expect(faces.length).toBe(6);
b.delete();
faces.forEach(f => f.delete());
}));
it('should reverse a face', () => __awaiter(void 0, void 0, void 0, function* () {
const f = face.createRectangleFace({ center: [0, 0, 0], width: 2, length: 1, direction: [0, 1, 0] });
const w = wire.getWire({ shape: f, index: 0 });
const fr = face.reversedFace({ shape: f });
const wr = wire.getWire({ shape: fr, index: 0 });
const pt1 = wire.pointOnWireAtLength({ shape: w, length: 0.1 });
const pt2 = wire.pointOnWireAtLength({ shape: wr, length: 0.1 });
expect(pt1).not.toEqual(pt2);
f.delete();
fr.delete();
w.delete();
wr.delete();
}));
it('should get faces areas', () => __awaiter(void 0, void 0, void 0, function* () {
const f1 = face.createRectangleFace({ center: [0, 0, 0], width: 2, length: 1, direction: [0, 1, 0] });
const f2 = face.createCircleFace({ radius: 3, center: [0, 0, 0], direction: [0, 0, 1] });
const areas = face.getFacesAreas({ shapes: [f1, f2] });
expect(areas.length).toBe(2);
expect(areas[0]).toBe(2);
expect(areas[1]).toBe(28.274333882308138);
f1.delete();
f2.delete();
}));
it('should get faces centers of mass', () => __awaiter(void 0, void 0, void 0, function* () {
const f1 = face.createRectangleFace({ center: [0, 1, 0], width: 2, length: 1, direction: [0, 1, 0] });
const f2 = face.createCircleFace({ radius: 3, center: [0, 3, 3], direction: [0, 0, 1] });
const centers = face.getFacesCentersOfMass({ shapes: [f1, f2] });
expect(centers).toEqual([
[2.0816681711721685e-17, 1, -8.023096076392733e-18],
[4.440892098500626e-16, 2.9999999999999996, 3]
]);
f1.delete();
f2.delete();
}));
it('should get face center of mass', () => __awaiter(void 0, void 0, void 0, function* () {
const f1 = face.createRectangleFace({ center: [0, 1, 0], width: 2, length: 1, direction: [0, 1, 0] });
const center = face.getFaceCenterOfMass({ shape: f1 });
expect(center).toEqual([2.0816681711721685e-17, 1, -8.023096076392733e-18]);
f1.delete();
}));
});

@@ -29,2 +29,3 @@ import { TopoDS_Face, OpenCascadeInstance, TopoDS_Wire, TopoDS_Shape, TopoDS_Edge } from '../../../bitbybit-dev-occt/bitbybit-dev-occt';

createParallelogramWire(inputs: Inputs.OCCT.ParallelogramDto): TopoDS_Wire;
createNGonWire(inputs: Inputs.OCCT.NGonWireDto): TopoDS_Wire;
createRectangleWire(inputs: Inputs.OCCT.RectangleDto): TopoDS_Wire;

@@ -31,0 +32,0 @@ getWire(inputs: Inputs.OCCT.ShapeIndexDto<TopoDS_Shape>): TopoDS_Wire;

@@ -136,2 +136,5 @@ import { shapeTypeEnum, typeSpecificityEnum } from '../../occ-helper';

}
createNGonWire(inputs) {
return this.och.createNGonWire(inputs);
}
createRectangleWire(inputs) {

@@ -138,0 +141,0 @@ return this.och.createRectangleWire(inputs);

{
"name": "bitbybit-occt",
"version": "0.9.27",
"version": "0.9.28",
"description": "Bit By Bit Developers CAD algorithms using OpenCascade Technology kernel. Run in Node and in Browser.",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc