- Tons of addtions
This commit is contained in:
@@ -182,6 +182,60 @@ class TestOCCSketch:
|
||||
points = sketch.get_points()
|
||||
assert len(points) == 0
|
||||
|
||||
def test_workplane_extrude_along_normal(self):
|
||||
"""A sketch on a tilted plane extrudes along that plane's normal."""
|
||||
import math
|
||||
from OCP.GProp import GProp_GProps
|
||||
from OCP.BRepGProp import BRepGProp
|
||||
|
||||
ang = math.radians(35)
|
||||
normal = (math.sin(ang), 0.0, math.cos(ang))
|
||||
x_dir = (math.cos(ang), 0.0, -math.sin(ang))
|
||||
|
||||
sk = OCCSketch()
|
||||
sk.set_workplane((10.0, 0.0, 5.0), normal, x_dir)
|
||||
# 20x20 square in UV
|
||||
p0 = sk.add_point(-10, -10); p1 = sk.add_point(10, -10)
|
||||
p2 = sk.add_point(10, 10); p3 = sk.add_point(-10, 10)
|
||||
sk.add_line(p0, p1); sk.add_line(p1, p2)
|
||||
sk.add_line(p2, p3); sk.add_line(p3, p0)
|
||||
|
||||
geom = sk.get_geometry()
|
||||
# The face must carry the plane normal for the kernel.
|
||||
assert geom.metadata.get("normal") is not None
|
||||
|
||||
kernel = OCGeometryKernel()
|
||||
solid = kernel.extrude(geom, 15.0)
|
||||
s = kernel._get_shape(solid)
|
||||
g = GProp_GProps()
|
||||
BRepGProp.VolumeProperties_s(s, g)
|
||||
# 20 * 20 * 15 = 6000 regardless of plane orientation.
|
||||
assert abs(g.Mass() - 6000.0) < 0.1
|
||||
|
||||
def test_workplane_extrude_with_hole(self):
|
||||
"""A square with a circular hole on a custom plane extrudes correctly."""
|
||||
import math
|
||||
from OCP.GProp import GProp_GProps
|
||||
from OCP.BRepGProp import BRepGProp
|
||||
|
||||
sk = OCCSketch()
|
||||
sk.set_workplane((0, 0, 0), (0, 0, 1), (1, 0, 0))
|
||||
a = sk.add_point(-10, -10); b = sk.add_point(10, -10)
|
||||
c = sk.add_point(10, 10); d = sk.add_point(-10, 10)
|
||||
sk.add_line(a, b); sk.add_line(b, c)
|
||||
sk.add_line(c, d); sk.add_line(d, a)
|
||||
ctr = sk.add_point(0, 0)
|
||||
sk.add_circle(ctr, 3.0)
|
||||
|
||||
geom = sk.get_geometry()
|
||||
kernel = OCGeometryKernel()
|
||||
solid = kernel.extrude(geom, 5.0)
|
||||
s = kernel._get_shape(solid)
|
||||
g = GProp_GProps()
|
||||
BRepGProp.VolumeProperties_s(s, g)
|
||||
expected = 20 * 20 * 5 - math.pi * 3 * 3 * 5
|
||||
assert abs(g.Mass() - expected) < 0.1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-v"])
|
||||
|
||||
Reference in New Issue
Block a user