Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bounded geometry #655

Merged
merged 91 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
dadd8fb
re-org primitives folder to geometry
jonahrb May 30, 2023
545626c
add surface and curve ABC's
jonahrb May 30, 2023
40c9bd7
curves and surfaces now inherit from ABC's
jonahrb Jun 14, 2023
58ab305
fix component instance bug
jonahrb Jun 16, 2023
89eeb6f
temp changes to get hedgehog working
jonahrb Jun 26, 2023
b0f9525
surface and curve evaluation with respect to direction
dastan-ansys Aug 15, 2023
cffea95
resolved surface and curve conflicts
dastan-ansys Aug 15, 2023
46afca0
minor fix in component.py
dastan-ansys Aug 15, 2023
2543d06
styling
dastan-ansys Aug 15, 2023
4d251ec
Merge branch 'main' into feat/bounded-geometry
RobPasMue Aug 16, 2023
da8b1f0
fixed design tests
dastan-ansys Aug 16, 2023
896d40f
Merge branch 'feat/bounded-geometry' of https://github.com/pyansys/py…
dastan-ansys Aug 16, 2023
3d1702e
Merge branch 'main' into feat/bounded-geometry
RobPasMue Aug 17, 2023
38d1958
fixed some EvaluateRequest import issue
dastan-ansys Aug 17, 2023
c690d73
fixed ProjectPoint request
dastan-ansys Aug 17, 2023
7cd47dd
Merge branch 'main' into feat/bounded-geometry
RobPasMue Aug 21, 2023
ed065cb
full face/surface refactor of Dastan's work
jonahrb Sep 12, 2023
e4b69cb
Refactor edge/trimmedcurve
jonahrb Sep 19, 2023
5956499
Merge branch 'main' into feat/bounded-geometry
jonahrb Sep 25, 2023
5af0e5a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 25, 2023
71c9205
refactor TrimmedCurve
jonahrb Oct 4, 2023
65266f2
Merge branch 'feat/bounded-geometry' of https://github.com/ansys/pyan…
jonahrb Oct 4, 2023
e240252
fix tests, face.point was never proportional..
jonahrb Oct 4, 2023
3a29f25
Merge branch 'main' into feat/bounded-geometry
jonahrb Nov 20, 2023
8e4a469
added trimmed surface and curve tests for hedgehog
dastan-ansys Jan 31, 2024
1ec9f45
Merge branch 'main' into feat/bounded-geometry
jonahrb Feb 9, 2024
7863a5f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 9, 2024
9c6657b
Update test_design.py
jonahrb Feb 12, 2024
3a207ae
cleanup some errors
jonahrb Feb 12, 2024
ad2ec20
formatted comment block for interval
dastan-ansys Feb 20, 2024
b8ed01c
fixed 'title underline too short issue for interval'
dastan-ansys Feb 20, 2024
9432f94
resolving the duplicate contains docstring
dastan-ansys Feb 20, 2024
4d2e2ed
giving the contain functions different names
dastan-ansys Feb 20, 2024
8d633e4
resolving plane conflict doc
dastan-ansys Feb 20, 2024
f0b11da
changed Plane to PlaneSurface
dastan-ansys Feb 22, 2024
11be80a
updated the import location for Sphere and SphereEvaluation
dastan-ansys Feb 22, 2024
36084da
added init files for curves and surface directory
dastan-ansys Feb 22, 2024
0b20063
Merge branch 'main' into feat/bounded-geometry
RobPasMue Feb 23, 2024
6f4ed37
Update src/ansys/geometry/core/geometry/parameterization.py
dastan-ansys Feb 26, 2024
a0e1e2f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 26, 2024
90eb553
Update src/ansys/geometry/core/geometry/surfaces/cone.py
dastan-ansys Feb 26, 2024
844486a
Update src/ansys/geometry/core/geometry/surfaces/cylinder.py
dastan-ansys Feb 26, 2024
8843296
Update src/ansys/geometry/core/geometry/surfaces/plane.py
dastan-ansys Feb 26, 2024
dd3a421
Update src/ansys/geometry/core/geometry/surfaces/plane.py
dastan-ansys Feb 26, 2024
360c83e
Update src/ansys/geometry/core/geometry/surfaces/plane.py
dastan-ansys Feb 26, 2024
234de70
Update src/ansys/geometry/core/geometry/surfaces/plane.py
dastan-ansys Feb 26, 2024
8c404a8
Update src/ansys/geometry/core/geometry/surfaces/plane.py
dastan-ansys Feb 26, 2024
ef73f26
Update src/ansys/geometry/core/geometry/surfaces/sphere.py
dastan-ansys Feb 26, 2024
16ee6d4
Update src/ansys/geometry/core/geometry/surfaces/surface.py
dastan-ansys Feb 26, 2024
c057f1f
Update src/ansys/geometry/core/geometry/surfaces/surface.py
dastan-ansys Feb 26, 2024
af1fd8c
Update src/ansys/geometry/core/geometry/surfaces/surface.py
dastan-ansys Feb 26, 2024
fb15879
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 26, 2024
376191f
Update src/ansys/geometry/core/geometry/surfaces/surface.py
dastan-ansys Feb 26, 2024
aa508a3
Update src/ansys/geometry/core/geometry/surfaces/torus.py
dastan-ansys Feb 26, 2024
d14d083
Update src/ansys/geometry/core/geometry/surfaces/torus.py
dastan-ansys Feb 26, 2024
458aa6a
Update src/ansys/geometry/core/geometry/surfaces/trimmed_surface.py
dastan-ansys Feb 26, 2024
309fbec
Update src/ansys/geometry/core/geometry/surfaces/trimmed_surface.py
dastan-ansys Feb 26, 2024
f764f57
Update src/ansys/geometry/core/geometry/surfaces/trimmed_surface.py
dastan-ansys Feb 26, 2024
6c6bae2
Update src/ansys/geometry/core/geometry/surfaces/trimmed_surface.py
dastan-ansys Feb 26, 2024
a1b0220
Update src/ansys/geometry/core/misc/accuracy.py
dastan-ansys Feb 26, 2024
61c4815
Update src/ansys/geometry/core/geometry/surfaces/trimmed_surface.py
dastan-ansys Feb 26, 2024
afb1d42
Update src/ansys/geometry/core/geometry/surfaces/trimmed_surface.py
dastan-ansys Feb 26, 2024
db4bd99
Update src/ansys/geometry/core/connection/conversions.py
dastan-ansys Feb 26, 2024
62dd820
Update src/ansys/geometry/core/connection/conversions.py
dastan-ansys Feb 26, 2024
f68cc3b
Apply suggestions from code review
dastan-ansys Feb 26, 2024
63f8973
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 26, 2024
98dd20c
Addressed the comments that required manually changing the files
dastan-ansys Feb 29, 2024
28fcae0
cleaned up BoxUV
dastan-ansys Feb 29, 2024
b6f9683
Merge branch 'main' into feat/bounded-geometry
dastan-ansys Feb 29, 2024
343434e
Apply suggestions from code review
dastan-ansys Mar 3, 2024
d0c3edd
implemented Rob's recommended changes
dastan-ansys Mar 3, 2024
c37756f
Merge branch 'feat/bounded-geometry' of https://github.com/pyansys/py…
dastan-ansys Mar 3, 2024
fa8c4b8
renamed geometry submodule to shapes to avoid conflicts
dastan-ansys Mar 3, 2024
f8c1501
Merge branch 'main' into feat/bounded-geometry
RobPasMue Mar 3, 2024
748c416
Apply suggestions from code review
dastan-ansys Mar 12, 2024
294da85
Update src/ansys/geometry/core/designer/edge.py
dastan-ansys Mar 12, 2024
9adf944
added implemented changes manually
dastan-ansys Mar 12, 2024
c222f18
Merge branch 'feat/bounded-geometry' of https://github.com/pyansys/py…
dastan-ansys Mar 12, 2024
5db8117
Merge branch 'main' into feat/bounded-geometry
RobPasMue Mar 12, 2024
d463fca
updated docstring in plane
dastan-ansys Mar 12, 2024
05e7eb0
changed face_normal() to normal() in test_design.py
dastan-ansys Mar 12, 2024
5bc34f2
changed ansys.geometry.core.geometry to ansys.geometry.core.shapes in…
dastan-ansys Mar 12, 2024
856770f
feat: validate also accept args
RobPasMue Mar 12, 2024
a4d5d20
feat: accuracy independent tests and changes
RobPasMue Mar 12, 2024
76f248f
fix: library imports
RobPasMue Mar 12, 2024
7c2a6e6
fix: various old primitives references
RobPasMue Mar 12, 2024
2470125
fix: no circular import on face module
RobPasMue Mar 12, 2024
a222feb
fix: typo
RobPasMue Mar 12, 2024
4afe6e9
fix: remove unnecessary TODO - already reported as an issue
RobPasMue Mar 12, 2024
0ec22b2
feat: adding self_unite and self_intersect
RobPasMue Mar 12, 2024
de18487
fix: remove unnecessary todos
RobPasMue Mar 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/examples/01_getting_started/01_math.mystnb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ PyAnsys Geometry implements parametric evaluations for some curves and surfaces.
Evaluate a sphere.

```{code-cell} ipython3
from ansys.geometry.core.primitives.sphere import Sphere, SphereEvaluation
from ansys.geometry.core.shapes import Sphere, SphereEvaluation
from ansys.geometry.core.math import Point3D
from ansys.geometry.core.misc import Distance

Expand Down
4 changes: 2 additions & 2 deletions doc/source/user_guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ Create geometry model
---------------------

Once an instance has started, you can create a
geometry model by initializing the :ref:`Sketch <ref_sketch>` subpackage and using the
:ref:`Primitives <ref_primitives>` subpackage.
geometry model by initializing the :ref:`sketch <ref_sketch>` subpackage and using the
:ref:`shapes <ref_primitives>` subpackage.

.. code:: python

Expand Down
6 changes: 4 additions & 2 deletions doc/source/user_guide/primitives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
Primitives
**********

The PyAnsys Geometry :class:`primitives <ansys.geometry.core.primitives>` subpackage consists
The PyAnsys Geometry :class:`math <ansys.geometry.core.math>` subpackage consists
of primitive representations of basic geometric objects, such as a point, vector, and
matrix. To operate and manipulate physical quantities, this subpackage uses
`Pint <https://github.com/hgrecco/pint>`_, a third-party open source software
that other PyAnsys libraries also use.
that other PyAnsys libraries also use. It also uses its :class:`shapes <ansys.geometry.core.shapes>`
subpackage to evaluate and represent geometric shapes (both curves and surfaces),
such as lines, circles, cones, spheres and torus.

This table shows PyAnsys Geometry names and base values for the physical quantities:

Expand Down
4 changes: 4 additions & 0 deletions src/ansys/geometry/core/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
from ansys.geometry.core.connection.backend import ApiVersions, BackendType
from ansys.geometry.core.connection.client import GrpcClient
from ansys.geometry.core.connection.conversions import (
curve_to_grpc_curve,
frame_to_grpc_frame,
grpc_curve_to_curve,
grpc_frame_to_frame,
grpc_matrix_to_matrix,
grpc_surface_to_surface,
plane_to_grpc_plane,
point3d_to_grpc_point,
sketch_shapes_to_grpc_geometries,
tess_to_pd,
trimmed_curve_to_grpc_trimmed_curve,
unit_vector_to_grpc_direction,
)
from ansys.geometry.core.connection.defaults import (
Expand Down
165 changes: 165 additions & 0 deletions src/ansys/geometry/core/connection/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from ansys.api.geometry.v0.models_pb2 import Arc as GRPCArc
from ansys.api.geometry.v0.models_pb2 import Circle as GRPCCircle
from ansys.api.geometry.v0.models_pb2 import CurveGeometry as GRPCCurve
from ansys.api.geometry.v0.models_pb2 import Direction as GRPCDirection
from ansys.api.geometry.v0.models_pb2 import Ellipse as GRPCEllipse
from ansys.api.geometry.v0.models_pb2 import Frame as GRPCFrame
Expand All @@ -32,7 +33,9 @@
from ansys.api.geometry.v0.models_pb2 import Plane as GRPCPlane
from ansys.api.geometry.v0.models_pb2 import Point as GRPCPoint
from ansys.api.geometry.v0.models_pb2 import Polygon as GRPCPolygon
from ansys.api.geometry.v0.models_pb2 import Surface as GRPCSurface
from ansys.api.geometry.v0.models_pb2 import Tessellation
from ansys.api.geometry.v0.models_pb2 import TrimmedCurve as GRPCTrimmedCurve
from beartype.typing import TYPE_CHECKING, List, Optional, Tuple

from ansys.geometry.core.math.frame import Frame
Expand All @@ -41,6 +44,16 @@
from ansys.geometry.core.math.point import Point2D, Point3D
from ansys.geometry.core.math.vector import UnitVector3D
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS
from ansys.geometry.core.shapes.curves.circle import Circle
from ansys.geometry.core.shapes.curves.curve import Curve
from ansys.geometry.core.shapes.curves.ellipse import Ellipse
from ansys.geometry.core.shapes.curves.line import Line
from ansys.geometry.core.shapes.surfaces.cone import Cone
from ansys.geometry.core.shapes.surfaces.cylinder import Cylinder
from ansys.geometry.core.shapes.surfaces.plane import PlaneSurface
from ansys.geometry.core.shapes.surfaces.sphere import Sphere
from ansys.geometry.core.shapes.surfaces.surface import Surface
from ansys.geometry.core.shapes.surfaces.torus import Torus
from ansys.geometry.core.sketch.arc import Arc
from ansys.geometry.core.sketch.circle import SketchCircle
from ansys.geometry.core.sketch.edge import SketchEdge
Expand All @@ -52,6 +65,9 @@
if TYPE_CHECKING: # pragma: no cover
from pyvista import PolyData

from ansys.geometry.core.designer.face import SurfaceType
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve


def unit_vector_to_grpc_direction(unit_vector: UnitVector3D) -> GRPCDirection:
"""
Expand Down Expand Up @@ -431,3 +447,152 @@ def grpc_frame_to_frame(frame: GRPCFrame) -> Frame:
]
),
)


def grpc_surface_to_surface(surface: GRPCSurface, surface_type: "SurfaceType") -> Surface:
"""
Convert an ``ansys.api.geometry.Surface`` gRPC message to a ``Surface`` class.
jonahrb marked this conversation as resolved.
Show resolved Hide resolved

Parameters
----------
surface : GRPCSurface
Geometry service gRPC surface message.

Returns
-------
Surface
Resulting converted surface.
"""
from ansys.geometry.core.designer.face import SurfaceType

origin = Point3D(
[surface.origin.x, surface.origin.y, surface.origin.z], DEFAULT_UNITS.SERVER_LENGTH
)
axis = UnitVector3D([surface.axis.x, surface.axis.y, surface.axis.z])
reference = UnitVector3D([surface.reference.x, surface.reference.y, surface.reference.z])

if surface_type == SurfaceType.SURFACETYPE_CONE:
result = Cone(origin, surface.radius, surface.half_angle, reference, axis)
elif surface_type == SurfaceType.SURFACETYPE_CYLINDER:
result = Cylinder(origin, surface.radius, reference, axis)
elif surface_type == SurfaceType.SURFACETYPE_SPHERE:
result = Sphere(origin, surface.radius, reference, axis)
elif surface_type == SurfaceType.SURFACETYPE_TORUS:
result = Torus(origin, surface.major_radius, surface.minor_radius, reference, axis)
elif surface_type == SurfaceType.SURFACETYPE_PLANE:
result = PlaneSurface(origin, reference, axis)
else:
result = None
return result


def grpc_curve_to_curve(curve: GRPCCurve) -> Curve:
"""
Convert an ``ansys.api.geometry.CurveGeometry`` gRPC message to a ``Curve``.

Parameters
----------
curve : GRPCCurve
Geometry service gRPC curve message.

Returns
-------
Curve
Resulting converted curve.
"""
origin = Point3D([curve.origin.x, curve.origin.y, curve.origin.z])
try:
reference = UnitVector3D([curve.reference.x, curve.reference.y, curve.reference.z])
axis = UnitVector3D([curve.axis.x, curve.axis.y, curve.axis.z])
except ValueError:
# curve will be a line
pass
if curve.radius != 0:
result = Circle(origin, curve.radius, reference, axis)
elif curve.major_radius != 0 and curve.minor_radius != 0:
result = Ellipse(origin, curve.major_radius, curve.minor_radius, reference, axis)
elif curve.direction is not None:
result = Line(
origin,
UnitVector3D(
[
curve.direction.x,
curve.direction.y,
curve.direction.z,
]
),
)
else:
result = None

return result


def curve_to_grpc_curve(curve: Curve) -> GRPCCurve:
"""
Convert a ``Curve`` to an ``ansys.api.geometry.CurveGeometry`` gRPC message.

Parameters
----------
curve : Curve
Curve to convert.

Returns
-------
GRPCCurve
Return ``Curve`` as a ``ansys.api.geometry.CurveGeometry`` message.
"""
grpc_curve = None
origin = point3d_to_grpc_point(curve.origin)

if isinstance(curve, Line):
direction = unit_vector_to_grpc_direction(curve.direction)
grpc_curve = GRPCCurve(origin=origin, direction=direction)
else:
reference = unit_vector_to_grpc_direction(curve.dir_x)
axis = unit_vector_to_grpc_direction(curve.dir_z)

if isinstance(curve, Circle):
grpc_curve = GRPCCurve(
origin=origin, reference=reference, axis=axis, radius=curve.radius.m
)
elif isinstance(curve, Ellipse):
grpc_curve = GRPCCurve(
origin=origin,
reference=reference,
axis=axis,
major_radius=curve.major_radius.m,
minor_radius=curve.minor_radius.m,
)

return grpc_curve


def trimmed_curve_to_grpc_trimmed_curve(curve: "TrimmedCurve") -> GRPCTrimmedCurve:
"""
Convert a ``TrimmedCurve``to an ``ansys.api.geometry.TrimmedCurve`` gRPC message.

Parameters
----------
curve : TrimmedCurve
Curve to convert.

Returns
-------
GRPCTrimmedCurve
Geometry service gRPC ``TrimmedCurve`` message.
"""
curve_geometry = curve_to_grpc_curve(curve.geometry)
start = point3d_to_grpc_point(curve.start)
end = point3d_to_grpc_point(curve.end)
i_start = curve.interval.start
i_end = curve.interval.end

return GRPCTrimmedCurve(
curve=curve_geometry,
start=start,
end=end,
interval_start=i_start,
interval_end=i_end,
length=curve.length.m,
)
4 changes: 2 additions & 2 deletions src/ansys/geometry/core/connection/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ansys.geometry.core.connection.client import GrpcClient


def validate(): # pragma: no cover
def validate(*args, **kwargs): # pragma: no cover
"""Create a client using the default settings and validate it."""
print(GrpcClient())
print(GrpcClient(*args, **kwargs))
# TODO: consider adding additional server stat reporting
25 changes: 22 additions & 3 deletions src/ansys/geometry/core/designer/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,13 @@ def faces(self) -> List[Face]: # noqa: D102
self._grpc_client.log.debug(f"Retrieving faces for body {self.id} from server.")
grpc_faces = self._bodies_stub.GetFaces(self._grpc_id)
return [
Face(grpc_face.id, SurfaceType(grpc_face.surface_type), self, self._grpc_client)
Face(
grpc_face.id,
SurfaceType(grpc_face.surface_type),
self,
self._grpc_client,
grpc_face.is_reversed,
)
for grpc_face in grpc_faces.faces
]

Expand All @@ -675,7 +681,13 @@ def edges(self) -> List[Edge]: # noqa: D102
self._grpc_client.log.debug(f"Retrieving edges for body {self.id} from server.")
grpc_edges = self._bodies_stub.GetEdges(self._grpc_id)
return [
Edge(grpc_edge.id, CurveType(grpc_edge.curve_type), self, self._grpc_client)
Edge(
grpc_edge.id,
CurveType(grpc_edge.curve_type),
self,
self._grpc_client,
grpc_edge.is_reversed,
)
for grpc_edge in grpc_edges.edges
]

Expand Down Expand Up @@ -993,6 +1005,7 @@ def faces(self) -> List[Face]: # noqa: D102
SurfaceType(grpc_face.surface_type),
self,
self._template._grpc_client,
grpc_face.is_reversed,
)
for grpc_face in grpc_faces.faces
]
Expand All @@ -1004,7 +1017,13 @@ def edges(self) -> List[Edge]: # noqa: D102
self._template._grpc_client.log.debug(f"Retrieving edges for body {self.id} from server.")
grpc_edges = self._template._bodies_stub.GetEdges(EntityIdentifier(id=self.id))
return [
Edge(grpc_edge.id, CurveType(grpc_edge.curve_type), self, self._template._grpc_client)
Edge(
grpc_edge.id,
CurveType(grpc_edge.curve_type),
self,
self._template._grpc_client,
grpc_edge.is_reversed,
)
for grpc_edge in grpc_edges.edges
]

Expand Down
Loading
Loading