UNPKG

@bitbybit-dev/core

Version:

Bit By Bit Developers Core CAD API to Program Geometry

78 lines (77 loc) 3.16 kB
export class DrawCore { detectPoint(entity) { return (Array.isArray(entity) && entity.length === 3 && this.checkIfElementsInArrayAreNumbers(entity)); } detectPoints(entity) { return Array.isArray(entity) && this.checkIfElementsInArrayAreArrays(entity) && this.arraysInChildrenArraysContainNumbers(entity) && this.arraysInChildrenArraysAreOfLength3(entity); } detectLine(entity) { return entity.start && entity.end && Array.isArray(entity.start) && Array.isArray(entity.end); } detectLines(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectLine(el)); } detectPolyline(entity) { return entity.points && Array.isArray(entity.points); } detectPolylines(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectPolyline(el)); } detectNode(entity) { return !Array.isArray(entity) && entity.id && entity.id.includes("node"); } detectNodes(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectNode(el)); } detectVerbCurve(entity) { return !Array.isArray(entity) && entity._data && entity._data.controlPoints && entity._data.knots && entity._data.degree; } detectVerbSurface(entity) { return !Array.isArray(entity) && entity._data && entity._data.controlPoints && entity._data.degreeU && entity._data.degreeV && entity._data.knotsU && entity._data.knotsV; } detectVerbCurves(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectVerbCurve(el)); } detectVerbSurfaces(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectVerbSurface(el)); } detectJscadMesh(entity) { return !Array.isArray(entity) && (entity.sides || entity.polygons); } detectJscadMeshes(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectJscadMesh(el)); } detectOcctShape(entity) { return (entity === null || entity === void 0 ? void 0 : entity.type) === "occ-shape"; } detectOcctShapes(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectOcctShape(el)); } detectManifoldShape(entity) { return (entity === null || entity === void 0 ? void 0 : entity.type) === "manifold-shape"; } detectManifoldShapes(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectManifoldShape(el)); } detectTag(entity) { return !Array.isArray(entity) && entity.text; } detectTags(entity) { return Array.isArray(entity) && !entity.some(el => !this.detectTag(el)); } checkIfElementsInArrayAreNumbers(array) { return !array.some(el => isNaN(el)); } checkIfElementsInArrayAreArrays(array) { return !array.some(el => !Array.isArray(el)); } arraysInChildrenArraysContainNumbers(array) { return !array.some(el => !this.checkIfElementsInArrayAreNumbers(el)); } arraysInChildrenArraysAreOfLength3(array) { return !array.some(el => el.length !== 3); } }