Skip to content

Commit ba24069

Browse files
committed
more methods
1 parent 4025730 commit ba24069

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

src/compas_rhino/geometry/brep/brep.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from compas_rhino.conversions import mesh_to_compas
2828
from compas_rhino.conversions import mesh_to_rhino
2929
from compas_rhino.conversions import plane_to_rhino
30+
from compas_rhino.conversions import point_to_compas
3031
from compas_rhino.conversions import point_to_rhino
3132
from compas_rhino.conversions import polyline_to_rhino_curve
3233
from compas_rhino.conversions import sphere_to_rhino
@@ -1106,3 +1107,21 @@ def cap_planar_holes(self, tolerance=None):
11061107
self._brep = result
11071108
else:
11081109
raise BrepError("Failed to cap planar holes")
1110+
1111+
def closest_point(self, point):
1112+
"""
1113+
Returns the closest point on the Brep to the given point.
1114+
1115+
Parameters
1116+
----------
1117+
point : :class:`compas.geometry.Point`
1118+
The point to find the closest point on the Brep to.
1119+
1120+
Returns
1121+
-------
1122+
:class:`compas.geometry.Point`
1123+
The closest point on the Brep to the given point.
1124+
1125+
"""
1126+
rgpoint = self._brep.ClosestPoint(point_to_rhino(point))
1127+
return point_to_compas(rgpoint)

src/compas_rhino/geometry/brep/edge.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from __future__ import division
33
from __future__ import print_function
44

5+
from this import d
6+
57
import Rhino # type: ignore
68

79
from compas.geometry import Arc
@@ -153,6 +155,17 @@ def is_ellipse(self):
153155
def length(self):
154156
return self._mass_props.Length
155157

158+
@property
159+
def domain(self):
160+
rhino_domain = self._edge.Domain
161+
min = rhino_domain.Min
162+
max = rhino_domain.Max
163+
return (min, max)
164+
165+
@property
166+
def index(self):
167+
return self._edge.EdgeIndex
168+
156169
# ==============================================================================
157170
# Methods
158171
# ==============================================================================
@@ -200,3 +213,40 @@ def _create_curve__from_data__(curve_type, curve_data, frame_data, domain):
200213
raise ValueError("Unknown curve type: {}".format(curve_type))
201214
curve.Domain = Rhino.Geometry.Interval(*domain)
202215
return curve
216+
217+
def closest_point(self, point):
218+
"""
219+
Returns the parameter of the closest point on the edge to the given point.
220+
221+
Parameters
222+
----------
223+
point : :class:`compas.geometry.Point`
224+
The point to project onto the edge.
225+
226+
Returns
227+
-------
228+
float
229+
The parameter of the closest point on the edge.
230+
"""
231+
rgpoint = Rhino.Geometry.Point3d(point.x, point.y, point.z)
232+
success, parameter = self._edge.ClosestPoint(rgpoint)
233+
if not success:
234+
raise ValueError("Failed to find closest point on edge")
235+
return parameter
236+
237+
def point_at(self, parameter):
238+
"""
239+
Returns the point on the edge at the given parameter.
240+
241+
Parameters
242+
----------
243+
parameter : float
244+
The parameter of the point on the edge.
245+
246+
Returns
247+
-------
248+
:class:`compas.geometry.Point`
249+
The point on the edge at the given parameter.
250+
"""
251+
rgpoint = self._edge.PointAt(parameter)
252+
return point_to_compas(rgpoint)

src/compas_rhino/geometry/brep/trim.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from compas.geometry import BrepTrim
88
from compas_rhino.geometry import RhinoNurbsCurve
9+
from compas_rhino.geometry.brep.edge import RhinoBrepEdge
910

1011
from .vertex import RhinoBrepVertex
1112

@@ -118,6 +119,10 @@ def iso_status(self):
118119
def native_trim(self):
119120
return self._trim
120121

122+
@property
123+
def edge(self):
124+
return RhinoBrepEdge(self._trim.Edge)
125+
121126
@native_trim.setter
122127
def native_trim(self, rhino_trim):
123128
self._trim = rhino_trim

src/compas_rhino/geometry/brep/vertex.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def __from_data__(cls, data, builder):
6666
def point(self):
6767
return self._point
6868

69+
@property
70+
def index(self):
71+
return self._vertex.VertexIndex
72+
6973
@property
7074
def native_vertex(self):
7175
return self._vertex

0 commit comments

Comments
 (0)