UNPKG

@shapediver/sdk.sdtf-geometry

Version:
242 lines 10.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SdtfGeometryTypeGuard = void 0; const sdk_sdtf_core_1 = require("@shapediver/sdk.sdtf-core"); class SdtfGeometryTypeGuard { static assertArc(value) { if (!this.isArc(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry arc type.'); } static isArc(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPlane(value.plane) && typeof value.radius === 'number' && typeof value.angle === 'number'); } static assertBoundingBox(value) { if (!this.isBoundingBox(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry bounding box type.'); } static isBoundingBox(value) { return (0, sdk_sdtf_core_1.isDataObject)(value) && this.isPoint3d(value.min) && this.isPoint3d(value.max); } static assertBox(value) { if (!this.isBox(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry box type.'); } static isBox(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPlane(value.plane) && Array.isArray(value.extents) && value.extents.length === 3 && value.extents.every((e) => (0, sdk_sdtf_core_1.isNumberArray)(e) && e.length === 2)); } static assertCircle(value) { if (!this.isCircle(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry circle type.'); } static isCircle(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPlane(value.plane) && typeof value.radius === 'number'); } static assertComplex(value) { if (!this.isComplex(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry complex type.'); } static isComplex(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 2; } static assertCone(value) { if (!this.isCone(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry cone type.'); } static isCone(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPlane(value.plane) && typeof value.radius === 'number' && typeof value.height === 'number'); } static assertCylinder(value) { if (!this.isCylinder(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry cylinder type.'); } static isCylinder(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isCircle(value.baseCircle) && typeof value.height === 'number'); } static assertEllipse(value) { if (!this.isEllipse(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry ellipse type.'); } static isEllipse(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPlane(value.plane) && typeof value.r1 === 'number' && typeof value.r2 === 'number'); } static assertInterval(value) { if (!this.isInterval(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry interval type.'); } static isInterval(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 2; } static assertInterval2(value) { if (!this.isInterval2(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry interval2 type.'); } static isInterval2(value) { return (0, sdk_sdtf_core_1.isDataObject)(value) && this.isInterval(value.u) && this.isInterval(value.v); } static assertLine(value) { if (!this.isLine(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry line type.'); } static isLine(value) { return (Array.isArray(value) && value.length === 2 && this.isPoint3d(value[0]) && this.isPoint3d(value[1])); } static assertMatrix(value) { if (!this.isMatrix(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry matrix type.'); } static isMatrix(value) { if (!Array.isArray(value)) return false; const nItems = value[0].length; return value.every((v) => (0, sdk_sdtf_core_1.isNumberArray)(v) && v.length === nItems); } static assertPlane(value) { if (!this.isPlane(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry plane type.'); } static isPlane(value) { return (Array.isArray(value) && value.length === 3 && this.isPoint3d(value[0]) && this.isVector3d(value[1]) && this.isVector3d(value[2])); } static assertPoint(value) { if (!this.isPoint(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry point type.'); } static isPoint(value) { return ((0, sdk_sdtf_core_1.isNumberArray)(value) && (value.length === 2 || value.length === 3 || value.length === 4)); } static assertPoint2d(value) { if (!this.isPoint2d(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry point type.'); } static isPoint2d(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 2; } static assertPoint3d(value) { if (!this.isPoint3d(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry point type.'); } static isPoint3d(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 3; } static assertPoint4d(value) { if (!this.isPoint4d(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry point type.'); } static isPoint4d(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 4; } static assertPolyline(value) { if (!this.isPolyline(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry polyline type.'); } static isPolyline(value) { return Array.isArray(value) && value.every((v) => this.isPoint3d(v)); } static assertRay(value) { if (!this.isRay(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry ray type.'); } static isRay(value) { return (Array.isArray(value) && value.length === 2 && this.isPoint3d(value[0]) && this.isVector3d(value[1])); } static assertRectangle(value) { if (!this.isRectangle(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry rectangle type.'); } static isRectangle(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPlane(value.plane) && this.isInterval(value.x) && this.isInterval(value.y)); } static assertSphere(value) { if (!this.isSphere(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry sphere type.'); } static isSphere(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPoint3d(value.center) && typeof value.radius === 'number'); } static assertTorus(value) { if (!this.isTorus(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry torus type.'); } static isTorus(value) { return ((0, sdk_sdtf_core_1.isDataObject)(value) && this.isPlane(value.plane) && typeof value.majorRadius === 'number' && typeof value.minorRadius === 'number'); } static assertTransform(value) { if (!this.isTransform(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry transform type.'); } static isTransform(value) { return (Array.isArray(value) && value.length === 4 && value.every((v) => (0, sdk_sdtf_core_1.isNumberArray)(v) && v.length === 4)); } static assertTransformList(value) { if (!this.isTransformList(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry transform-list type.'); } static isTransformList(value) { return Array.isArray(value) && value.every((v) => this.isTransform(v)); } static assertVector(value) { if (!this.isVector(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry vector type.'); } static isVector(value) { return ((0, sdk_sdtf_core_1.isNumberArray)(value) && (value.length === 2 || value.length === 3 || value.length === 4)); } static assertVector2d(value) { if (!this.isVector2d(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry vector type.'); } static isVector2d(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 2; } static assertVector3d(value) { if (!this.isVector3d(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry vector type.'); } static isVector3d(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 3; } static assertVector4d(value) { if (!this.isVector4d(value)) throw new sdk_sdtf_core_1.SdtfError('Assertion error: Value is not a geometry vector type.'); } static isVector4d(value) { return (0, sdk_sdtf_core_1.isNumberArray)(value) && value.length === 4; } } exports.SdtfGeometryTypeGuard = SdtfGeometryTypeGuard; //# sourceMappingURL=SdtfGeometryTypeGuard.js.map