Skip to content

Commit d5bdf60

Browse files
authored
Merge pull request #11 from compas-dev/docs-and-types
Add type annotations and complete missing docstrings
2 parents 3037438 + fcbbee7 commit d5bdf60

File tree

15 files changed

+221
-154
lines changed

15 files changed

+221
-154
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
98
## Unreleased
109

1110
### Added
1211

1312
* Volume calculation of closed triangle mesh.
13+
* Added type annotations.
14+
* Added dimension checks to trimesh setters.
1415

1516
### Changed
1617

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nptyping
2+
typing_extensions

scripts/test_intersections.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

scripts/test_union.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

scripts/test_volume.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/booleans.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ namespace PMP = CGAL::Polygon_mesh_processing;
66
namespace params = PMP::parameters;
77
namespace py = pybind11;
88

9-
109
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
1110
pmp_boolean_union(
12-
Eigen::Ref<const compas::RowMatrixXd> & VA,
13-
Eigen::Ref<const compas::RowMatrixXi> & FA,
14-
Eigen::Ref<const compas::RowMatrixXd> & VB,
15-
Eigen::Ref<const compas::RowMatrixXi> & FB)
11+
Eigen::Ref<const compas::RowMatrixXd> &VA,
12+
Eigen::Ref<const compas::RowMatrixXi> &FA,
13+
Eigen::Ref<const compas::RowMatrixXd> &VB,
14+
Eigen::Ref<const compas::RowMatrixXi> &FB)
1615
{
1716
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
1817
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
@@ -29,10 +28,10 @@ pmp_boolean_union(
2928

3029
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
3130
pmp_boolean_difference(
32-
Eigen::Ref<const compas::RowMatrixXd> & VA,
33-
Eigen::Ref<const compas::RowMatrixXi> & FA,
34-
Eigen::Ref<const compas::RowMatrixXd> & VB,
35-
Eigen::Ref<const compas::RowMatrixXi> & FB)
31+
Eigen::Ref<const compas::RowMatrixXd> &VA,
32+
Eigen::Ref<const compas::RowMatrixXi> &FA,
33+
Eigen::Ref<const compas::RowMatrixXd> &VB,
34+
Eigen::Ref<const compas::RowMatrixXi> &FB)
3635
{
3736
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
3837
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
@@ -49,10 +48,10 @@ pmp_boolean_difference(
4948

5049
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
5150
pmp_boolean_intersection(
52-
Eigen::Ref<const compas::RowMatrixXd> & VA,
53-
Eigen::Ref<const compas::RowMatrixXi> & FA,
54-
Eigen::Ref<const compas::RowMatrixXd> & VB,
55-
Eigen::Ref<const compas::RowMatrixXi> & FB)
51+
Eigen::Ref<const compas::RowMatrixXd> &VA,
52+
Eigen::Ref<const compas::RowMatrixXi> &FA,
53+
Eigen::Ref<const compas::RowMatrixXd> &VB,
54+
Eigen::Ref<const compas::RowMatrixXi> &FB)
5655
{
5756
Mesh A = compas::mesh_from_vertices_and_faces(VA, FA);
5857
Mesh B = compas::mesh_from_vertices_and_faces(VB, FB);
@@ -67,7 +66,8 @@ pmp_boolean_intersection(
6766
return R;
6867
};
6968

70-
void init_booleans(py::module & m) {
69+
void init_booleans(py::module &m)
70+
{
7171
py::module submodule = m.def_submodule("booleans");
7272

7373
submodule.def(
@@ -76,24 +76,21 @@ void init_booleans(py::module & m) {
7676
py::arg("VA").noconvert(),
7777
py::arg("FA").noconvert(),
7878
py::arg("VB").noconvert(),
79-
py::arg("FB").noconvert()
80-
);
79+
py::arg("FB").noconvert());
8180

8281
submodule.def(
8382
"boolean_difference",
8483
&pmp_boolean_difference,
8584
py::arg("VA").noconvert(),
8685
py::arg("FA").noconvert(),
8786
py::arg("VB").noconvert(),
88-
py::arg("FB").noconvert()
89-
);
87+
py::arg("FB").noconvert());
9088

9189
submodule.def(
9290
"boolean_intersection",
9391
&pmp_boolean_intersection,
9492
py::arg("VA").noconvert(),
9593
py::arg("FA").noconvert(),
9694
py::arg("VB").noconvert(),
97-
py::arg("FB").noconvert()
98-
);
95+
py::arg("FB").noconvert());
9996
};

src/booleans.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
77
pmp_boolean_union(
8-
Eigen::Ref<const compas::RowMatrixXd> & VA,
9-
Eigen::Ref<const compas::RowMatrixXi> & FA,
10-
Eigen::Ref<const compas::RowMatrixXd> & VB,
11-
Eigen::Ref<const compas::RowMatrixXi> & FB);
8+
Eigen::Ref<const compas::RowMatrixXd> &VA,
9+
Eigen::Ref<const compas::RowMatrixXi> &FA,
10+
Eigen::Ref<const compas::RowMatrixXd> &VB,
11+
Eigen::Ref<const compas::RowMatrixXi> &FB);
1212

1313
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
1414
pmp_boolean_difference(
15-
Eigen::Ref<const compas::RowMatrixXd> & VA,
16-
Eigen::Ref<const compas::RowMatrixXi> & FA,
17-
Eigen::Ref<const compas::RowMatrixXd> & VB,
18-
Eigen::Ref<const compas::RowMatrixXi> & FB);
15+
Eigen::Ref<const compas::RowMatrixXd> &VA,
16+
Eigen::Ref<const compas::RowMatrixXi> &FA,
17+
Eigen::Ref<const compas::RowMatrixXd> &VB,
18+
Eigen::Ref<const compas::RowMatrixXi> &FB);
1919

2020
std::tuple<compas::RowMatrixXd, compas::RowMatrixXi>
2121
pmp_boolean_intersection(
22-
Eigen::Ref<const compas::RowMatrixXd> & VA,
23-
Eigen::Ref<const compas::RowMatrixXi> & FA,
24-
Eigen::Ref<const compas::RowMatrixXd> & VB,
25-
Eigen::Ref<const compas::RowMatrixXi> & FB);
22+
Eigen::Ref<const compas::RowMatrixXd> &VA,
23+
Eigen::Ref<const compas::RowMatrixXi> &FA,
24+
Eigen::Ref<const compas::RowMatrixXd> &VB,
25+
Eigen::Ref<const compas::RowMatrixXi> &FB);
2626

2727
#endif /* COMPAS_BOOLEANS_H */

src/compas_cgal/__init__.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@
55
66
.. currentmodule:: compas_cgal
77
8+
Classes
9+
=======
10+
11+
.. autosummary::
12+
:toctree: generated/
13+
:nosignatures:
14+
15+
trimesh.TriMesh
16+
17+
Functions
18+
=========
19+
820
Booleans
9-
========
21+
--------
1022
1123
.. autosummary::
1224
:toctree: generated/
@@ -17,16 +29,25 @@
1729
booleans.boolean_intersection
1830
1931
Intersections
20-
=============
32+
-------------
2133
2234
.. autosummary::
2335
:toctree: generated/
2436
:nosignatures:
2537
2638
intersections.intersection_mesh_mesh
2739
40+
Measure
41+
-------
42+
43+
.. autosummary::
44+
:toctree: generated/
45+
:nosignatures:
46+
47+
measure.volume
48+
2849
Meshing
29-
=======
50+
-------
3051
3152
.. autosummary::
3253
:toctree: generated/
@@ -35,7 +56,7 @@
3556
meshing.remesh
3657
3758
Slicer
38-
======
59+
------
3960
4061
.. autosummary::
4162
:toctree: generated/
@@ -55,7 +76,6 @@
5576
__email__ = "[email protected]"
5677
__version__ = "0.1.1"
5778

58-
5979
HERE = os.path.dirname(__file__)
6080

6181
HOME = os.path.abspath(os.path.join(HERE, "../../"))

src/compas_cgal/booleans.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
from compas.plugins import plugin
33
from compas_cgal._cgal import booleans
44

5+
from typing_extensions import Literal
6+
7+
from compas_cgal.types import VerticesFaces
8+
from compas_cgal.types import VerticesFacesNumpy
9+
510

611
__all__ = [
712
'boolean_union',
@@ -10,7 +15,9 @@
1015
]
1116

1217

13-
def _boolean(A, B, operation):
18+
def _boolean(A: VerticesFaces,
19+
B: VerticesFaces,
20+
operation: Literal['union', 'difference', 'intersection']) -> VerticesFacesNumpy:
1421
"""Wrapper for all boolean operations.
1522
1623
Parameters
@@ -55,15 +62,18 @@ def _boolean(A, B, operation):
5562

5663

5764
@plugin(category='booleans', pluggable_name='boolean_union_mesh_mesh')
58-
def boolean_union(A, B):
65+
def boolean_union(A: VerticesFaces,
66+
B: VerticesFaces) -> VerticesFacesNumpy:
5967
return _boolean(A, B, 'union')
6068

6169

6270
@plugin(category='booleans', pluggable_name='boolean_difference_mesh_mesh')
63-
def boolean_difference(A, B):
71+
def boolean_difference(A: VerticesFaces,
72+
B: VerticesFaces) -> VerticesFacesNumpy:
6473
return _boolean(A, B, 'difference')
6574

6675

6776
@plugin(category='booleans', pluggable_name='boolean_intersection_mesh_mesh')
68-
def boolean_intersection(A, B):
77+
def boolean_intersection(A: VerticesFaces,
78+
B: VerticesFaces) -> VerticesFacesNumpy:
6979
return _boolean(A, B, 'intersection')

src/compas_cgal/intersections.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
from compas_cgal._cgal import intersections
33
from compas.plugins import plugin
44

5+
from compas_cgal.types import VerticesFaces
6+
from compas_cgal.types import ListOfPolylinesNumpy
7+
58

69
__all__ = [
710
'intersection_mesh_mesh'
811
]
912

1013

1114
@plugin(category='intersections')
12-
def intersection_mesh_mesh(A, B):
15+
def intersection_mesh_mesh(A: VerticesFaces, B: VerticesFaces) -> ListOfPolylinesNumpy:
1316
"""Compute the intersection of tow meshes.
1417
1518
Parameters

0 commit comments

Comments
 (0)