Skip to content

Commit 4ff5f1a

Browse files
Merge branch 'master' into cut_kw_arg
2 parents ee96ca7 + 4fcada6 commit 4ff5f1a

File tree

6 files changed

+53
-3
lines changed

6 files changed

+53
-3
lines changed

cadquery/occ_impl/geom.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ def __eq__(self, other):
582582
def __ne__(self, other):
583583
return not self.__eq__(other)
584584

585+
def __repr__(self):
586+
return f"Plane(origin={str(self.origin.toTuple())}, xDir={str(self.xDir.toTuple())}, normal={str(self.zDir.toTuple())})"
587+
585588
@property
586589
def origin(self) -> Vector:
587590
return self._origin

cadquery/occ_impl/shapes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
from io import BytesIO
1919

20-
from multimethod import multimethod
21-
2220
from vtkmodules.vtkCommonDataModel import vtkPolyData
2321
from vtkmodules.vtkFiltersCore import vtkTriangleFilter, vtkPolyDataNormals
2422

2523
from .geom import Vector, BoundBox, Plane, Location, Matrix
2624

25+
from ..utils import cqmultimethod as multimethod
26+
2727
import OCP.TopAbs as ta # Tolopolgy type enum
2828
import OCP.GeomAbs as ga # Geometry type enum
2929

conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ requirements:
1515
- setuptools
1616
run:
1717
- python {{ environ.get('PYTHON_VERSION') }}
18-
- ocp 7.5.2
18+
- ocp 7.5.3
1919
- hdf5 1.10.6 *1114
2020
- pyparsing >=2.1.9
2121
- ezdxf

doc/primer.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,19 @@ If you want to cast an OCCT object into a Direct API one you can just pass it as
352352
.. note::
353353
You can cast into the direct API the types found `here <https://dev.opencascade.org/doc/refman/html/class_topo_d_s___shape.html>`_
354354

355+
Multimethods
356+
------------
357+
358+
CadQuery uses `Multimethod <https://coady.github.io/multimethod/>`_ to allow a call to a method to
359+
be dispatched depending on the types of the arguments. An example is :meth:`~cadquery.Sketch.arc`,
360+
where ``a_sketch.arc((1, 2), (2, 3))`` would be dispatched to one method but ``a_sketch.arc((1, 2),
361+
(2, 3), (3, 4))`` would be dispatched to a different method. For multimethods to work, you should
362+
not use keyword arguments to specify positional parameters. For example, you **should not** write
363+
``a_sketch.arc(p1=(1, 2), p2=(2, 3), p3=(3, 4))``, instead you should use the previous example.
364+
Note CadQuery makes an attempt to fall back on the first registered multimethod in the event of a
365+
dispatch error, but it is still best practise to not use keyword arguments to specify positional
366+
arguments in CadQuery.
367+
355368
An Introspective Example
356369
------------------------
357370

tests/test_cadquery.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5279,3 +5279,10 @@ def test_MergeTags(self):
52795279
a = a.union(b)
52805280
a = a.workplaneFromTagged("zface").circle(0.2)
52815281
assert a.edges("%CIRCLE").val().Center().toTuple() == approx((0, 0, 0.5))
5282+
5283+
def test_plane_repr(self):
5284+
wp = Workplane("XY")
5285+
assert (
5286+
repr(wp.plane)
5287+
== "Plane(origin=(0.0, 0.0, 0.0), xDir=(1.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0))"
5288+
)

tests/test_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from cadquery.utils import cqmultimethod as multimethod
2+
3+
from pytest import raises
4+
5+
6+
def test_multimethod():
7+
class A:
8+
@multimethod
9+
def f(self, a: int, c: str = "s"):
10+
return 1
11+
12+
@f.register
13+
def f(self, a: int, b: int, c: str = "b"):
14+
return 2
15+
16+
assert A().f(0, "s") == 1
17+
assert A().f(0, c="s") == 1
18+
assert A().f(0) == 1
19+
20+
assert A().f(0, 1, c="s") == 2
21+
assert A().f(0, 1, "s") == 2
22+
assert A().f(0, 1) == 2
23+
24+
assert A().f(a=0, c="s") == 1
25+
26+
with raises(TypeError):
27+
A().f(a=0, b=1, c="s")

0 commit comments

Comments
 (0)