mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-05 18:20:46 -08:00
Improve length accuracy Issue #1136, minor typing fixes
This commit is contained in:
parent
26caed754c
commit
bc8d01dc7e
2 changed files with 15 additions and 12 deletions
|
|
@ -305,7 +305,9 @@ class Mixin1D(Shape[TOPODS]):
|
||||||
@property
|
@property
|
||||||
def length(self) -> float:
|
def length(self) -> float:
|
||||||
"""Edge or Wire length"""
|
"""Edge or Wire length"""
|
||||||
return GCPnts_AbscissaPoint.Length_s(self.geom_adaptor())
|
props = GProp_GProps()
|
||||||
|
BRepGProp.LinearProperties_s(self.wrapped, props)
|
||||||
|
return props.Mass()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def radius(self) -> float:
|
def radius(self) -> float:
|
||||||
|
|
@ -796,19 +798,20 @@ class Mixin1D(Shape[TOPODS]):
|
||||||
for obj in common_set:
|
for obj in common_set:
|
||||||
match (obj, target):
|
match (obj, target):
|
||||||
case (_, Plane()):
|
case (_, Plane()):
|
||||||
|
assert isinstance(other.wrapped, gp_Pln)
|
||||||
target = Shape(BRepBuilderAPI_MakeFace(other.wrapped).Face())
|
target = Shape(BRepBuilderAPI_MakeFace(other.wrapped).Face())
|
||||||
operation = BRepAlgoAPI_Section()
|
operation1 = BRepAlgoAPI_Section()
|
||||||
result = bool_op((obj,), (target,), operation)
|
result = bool_op((obj,), (target,), operation1)
|
||||||
operation = BRepAlgoAPI_Common()
|
operation2 = BRepAlgoAPI_Common()
|
||||||
result.extend(bool_op((obj,), (target,), operation))
|
result.extend(bool_op((obj,), (target,), operation2))
|
||||||
|
|
||||||
case (_, Vertex() | Edge() | Wire()):
|
case (_, Vertex() | Edge() | Wire()):
|
||||||
operation = BRepAlgoAPI_Section()
|
operation1 = BRepAlgoAPI_Section()
|
||||||
section = bool_op((obj,), (target,), operation)
|
section = bool_op((obj,), (target,), operation1)
|
||||||
result = section
|
result = section
|
||||||
if not section:
|
if not section:
|
||||||
operation = BRepAlgoAPI_Common()
|
operation2 = BRepAlgoAPI_Common()
|
||||||
result.extend(bool_op((obj,), (target,), operation))
|
result.extend(bool_op((obj,), (target,), operation2))
|
||||||
|
|
||||||
case _ if issubclass(type(target), Shape):
|
case _ if issubclass(type(target), Shape):
|
||||||
result = target.intersect(obj)
|
result = target.intersect(obj)
|
||||||
|
|
@ -2940,7 +2943,7 @@ class Edge(Mixin1D[TopoDS_Edge]):
|
||||||
topods_edge = BRepBuilderAPI_MakeEdge(curve.Reversed(), last, first).Edge()
|
topods_edge = BRepBuilderAPI_MakeEdge(curve.Reversed(), last, first).Edge()
|
||||||
reversed_edge.wrapped = topods_edge
|
reversed_edge.wrapped = topods_edge
|
||||||
else:
|
else:
|
||||||
reversed_edge.wrapped = downcast(self.wrapped.Reversed())
|
reversed_edge.wrapped = TopoDS.Edge_s(self.wrapped.Reversed())
|
||||||
return reversed_edge
|
return reversed_edge
|
||||||
|
|
||||||
def to_axis(self) -> Axis:
|
def to_axis(self) -> Axis:
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,14 @@ class BuildLineTests(unittest.TestCase):
|
||||||
powerup @ 0,
|
powerup @ 0,
|
||||||
tangents=(screw % 1, powerup % 0),
|
tangents=(screw % 1, powerup % 0),
|
||||||
)
|
)
|
||||||
self.assertAlmostEqual(roller_coaster.wires()[0].length, 678.983628932414, 5)
|
self.assertAlmostEqual(roller_coaster.wires()[0].length, 678.9785865257071, 5)
|
||||||
|
|
||||||
def test_bezier(self):
|
def test_bezier(self):
|
||||||
pts = [(0, 0), (20, 20), (40, 0), (0, -40), (-60, 0), (0, 100), (100, 0)]
|
pts = [(0, 0), (20, 20), (40, 0), (0, -40), (-60, 0), (0, 100), (100, 0)]
|
||||||
wts = [1.0, 1.0, 2.0, 3.0, 4.0, 2.0, 1.0]
|
wts = [1.0, 1.0, 2.0, 3.0, 4.0, 2.0, 1.0]
|
||||||
with BuildLine() as bz:
|
with BuildLine() as bz:
|
||||||
b1 = Bezier(*pts, weights=wts)
|
b1 = Bezier(*pts, weights=wts)
|
||||||
self.assertAlmostEqual(bz.wires()[0].length, 225.86389406824566, 5)
|
self.assertAlmostEqual(bz.wires()[0].length, 225.98661946375782, 5)
|
||||||
self.assertTrue(isinstance(b1, Edge))
|
self.assertTrue(isinstance(b1, Edge))
|
||||||
|
|
||||||
def test_double_tangent_arc(self):
|
def test_double_tangent_arc(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue