RepliCAD

Форк
0
/
measureShape.ts 
76 строк · 2.0 Кб
1
import { getOC } from "./oclib";
2
import { AnyShape, Face, Shape3D } from "./shapes";
3

4
import type { GProp_GProps } from "replicad-opencascadejs";
5
import { GCWithScope, WrappingObj } from "./register";
6

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()];
12
  }
13
}
14

15
export class VolumePhysicalProperties extends PhysicalProperties {
16
  get volume(): number {
17
    return this.wrapped.Mass();
18
  }
19
}
20

21
export class SurfacePhysicalProperties extends PhysicalProperties {
22
  get area(): number {
23
    return this.wrapped.Mass();
24
  }
25
}
26

27
export class LinearPhysicalProperties extends PhysicalProperties {
28
  get length(): number {
29
    return this.wrapped.Mass();
30
  }
31
}
32

33
export function measureShapeSurfaceProperties(
34
  shape: Face | Shape3D
35
): SurfacePhysicalProperties {
36
  const oc = getOC();
37
  const properties = new oc.GProp_GProps_1();
38
  oc.BRepGProp.SurfaceProperties_1(shape.wrapped, properties, false, false);
39
  return new SurfacePhysicalProperties(properties);
40
}
41

42
export function measureShapeLinearProperties(
43
  shape: AnyShape
44
): LinearPhysicalProperties {
45
  const oc = getOC();
46
  const properties = new oc.GProp_GProps_1();
47
  oc.BRepGProp.LinearProperties(shape.wrapped, properties, false, false);
48
  return new LinearPhysicalProperties(properties);
49
}
50

51
export function measureShapeVolumeProperties(
52
  shape: Shape3D
53
): VolumePhysicalProperties {
54
  const oc = getOC();
55
  const properties = new oc.GProp_GProps_1();
56
  oc.BRepGProp.VolumeProperties_1(
57
    shape.wrapped,
58
    properties,
59
    false,
60
    false,
61
    false
62
  );
63
  return new VolumePhysicalProperties(properties);
64
}
65

66
export function measureVolume(shape: Shape3D) {
67
  return measureShapeVolumeProperties(shape).volume;
68
}
69

70
export function measureArea(shape: Face | Shape3D) {
71
  return measureShapeSurfaceProperties(shape).area;
72
}
73

74
export function measureLength(shape: AnyShape) {
75
  return measureShapeLinearProperties(shape).length;
76
}
77

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.