1
import { getOC } from "./oclib";
2
import { AnyShape, Face, Shape3D } from "./shapes";
4
import type { GProp_GProps } from "replicad-opencascadejs";
5
import { GCWithScope, WrappingObj } from "./register";
7
class PhysicalProperties extends WrappingObj<GProp_GProps> {
8
get centerOfMass(): [number, number, number] {
9
const r = GCWithScope();
10
const pnt = r(this.wrapped.CentreOfMass());
11
return [pnt.X(), pnt.Y(), pnt.Z()];
15
export class VolumePhysicalProperties extends PhysicalProperties {
16
get volume(): number {
17
return this.wrapped.Mass();
21
export class SurfacePhysicalProperties extends PhysicalProperties {
23
return this.wrapped.Mass();
27
export class LinearPhysicalProperties extends PhysicalProperties {
28
get length(): number {
29
return this.wrapped.Mass();
33
export function measureShapeSurfaceProperties(
35
): SurfacePhysicalProperties {
37
const properties = new oc.GProp_GProps_1();
38
oc.BRepGProp.SurfaceProperties_1(shape.wrapped, properties, false, false);
39
return new SurfacePhysicalProperties(properties);
42
export function measureShapeLinearProperties(
44
): LinearPhysicalProperties {
46
const properties = new oc.GProp_GProps_1();
47
oc.BRepGProp.LinearProperties(shape.wrapped, properties, false, false);
48
return new LinearPhysicalProperties(properties);
51
export function measureShapeVolumeProperties(
53
): VolumePhysicalProperties {
55
const properties = new oc.GProp_GProps_1();
56
oc.BRepGProp.VolumeProperties_1(
63
return new VolumePhysicalProperties(properties);
66
export function measureVolume(shape: Shape3D) {
67
return measureShapeVolumeProperties(shape).volume;
70
export function measureArea(shape: Face | Shape3D) {
71
return measureShapeSurfaceProperties(shape).area;
74
export function measureLength(shape: AnyShape) {
75
return measureShapeLinearProperties(shape).length;