Skip to content

Commit

Permalink
chore: auto fixes from pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Feb 6, 2025
1 parent d70a03a commit e7bb5e1
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 51 deletions.
18 changes: 9 additions & 9 deletions src/ansys/geometry/core/designer/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from ansys.api.geometry.v0.bodies_pb2 import (
BooleanRequest,
CopyRequest,
GetClosestSeparationRequest,
GetCollisionRequest,
MapRequest,
MirrorRequest,
Expand All @@ -46,7 +47,6 @@
SetNameRequest,
SetSuppressedRequest,
TranslateRequest,
GetClosestSeparationRequest,
)
from ansys.api.geometry.v0.bodies_pb2_grpc import BodiesStub
from ansys.api.geometry.v0.commands_pb2 import (
Expand All @@ -64,9 +64,9 @@
from ansys.geometry.core.connection.conversions import (
frame_to_grpc_frame,
grpc_material_to_material,
grpc_point_to_point3d,
plane_to_grpc_plane,
point3d_to_grpc_point,
grpc_point_to_point3d,
sketch_shapes_to_grpc_geometries,
tess_to_pd,
unit_vector_to_grpc_direction,
Expand Down Expand Up @@ -621,7 +621,7 @@ def remove_faces(self, selection: Face | Iterable[Face], offset: Real) -> bool:
``True`` when successful, ``False`` when failed.
"""
return

@abstractmethod
def get_closest_separation(self, other: "Body") -> tuple[Real, "Point3D", "Point3D"]:
"""Find the closest separation between two bodies.
Expand All @@ -630,7 +630,7 @@ def get_closest_separation(self, other: "Body") -> tuple[Real, "Point3D", "Point
----------
other: Body
other body to find the closest separation with.
Returns
-------
tuple[Real, Point3D, Point3D]
Expand Down Expand Up @@ -1310,10 +1310,10 @@ def remove_faces(self, selection: Face | Iterable[Face], offset: Real) -> bool:
self._grpc_client.log.warning(f"Failed to remove faces from body {self.id}.")

return result.success

@protect_grpc
@min_backend_version(25, 2, 0)
def get_closest_separation(self, other: "Body") -> tuple[Real, "Point3D", "Point3D"]: # noqa: D102
def get_closest_separation(self, other: "Body") -> tuple[Real, "Point3D", "Point3D"]: # noqa: D102
self._grpc_client.log.debug(f"Getting closest separation from {self.id} to {other._id}.")

result = self._bodies_stub.GetClosestSeparation(
Expand Down Expand Up @@ -1767,9 +1767,9 @@ def shell_body(self, offset: Real) -> bool: # noqa: D102
@ensure_design_is_active
def remove_faces(self, selection: Face | Iterable[Face], offset: Real) -> bool: # noqa: D102
return self._template.remove_faces(selection, offset)

@ensure_design_is_active
def get_closest_separation(self, other: "Body") -> tuple[Real, "Point3D", "Point3D"] : # noqa: D102
def get_closest_separation(self, other: "Body") -> tuple[Real, "Point3D", "Point3D"]: # noqa: D102
return self._template.get_closest_separation(other)

def plot( # noqa: D102
Expand Down Expand Up @@ -1820,7 +1820,7 @@ def export_gltf( # noqa: D102
if use_service_colors is not None
else pyansys_geometry.USE_SERVICE_COLORS
)

pl = GeometryPlotter(use_trame=use_trame, use_service_colors=use_service_colors)

faces = self.faces
Expand Down
4 changes: 3 additions & 1 deletion src/ansys/geometry/core/designer/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,9 @@ def delete_beam_profile(self, beam_profile: BeamProfile | str) -> None:
@check_input_types
@ensure_design_is_active
@min_backend_version(24, 2, 0)
def insert_file(self, file_location: Path | str, import_options: ImportOptions = ImportOptions()) -> Component:
def insert_file(
self, file_location: Path | str, import_options: ImportOptions = ImportOptions()
) -> Component:
"""Insert a file into the design.
Parameters
Expand Down
20 changes: 8 additions & 12 deletions src/ansys/geometry/core/designer/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from ansys.api.geometry.v0.models_pb2 import Edge as GRPCEdge
from ansys.geometry.core.connection.client import GrpcClient
from ansys.geometry.core.connection.conversions import (
grpc_curve_to_curve,
grpc_curve_to_curve,
grpc_surface_to_surface,
grpc_point_to_point3d,
)
Expand Down Expand Up @@ -309,9 +309,7 @@ def color(self) -> str:
self._color = Color.DEFAULT.value

# If color is not cached, retrieve from the server
response = self._faces_stub.GetColor(
EntityIdentifier(id=self.id)
)
response = self._faces_stub.GetColor(EntityIdentifier(id=self.id))

# Return if valid color returned
if response.color:
Expand All @@ -320,7 +318,7 @@ def color(self) -> str:
self._color = Color.DEFAULT.value

return self._color

@color.setter
def color(self, color: str | tuple[float, float, float]) -> None:
self.set_color(color)
Expand Down Expand Up @@ -585,7 +583,7 @@ def setup_offset_relationship(
@min_backend_version(25, 2, 0)
def get_bounding_box(self) -> BoundingBox2D:
"""Get the bounding box for the face.
Parameters
----------
None
Expand All @@ -597,9 +595,7 @@ def get_bounding_box(self) -> BoundingBox2D:
"""
self._grpc_client.log.debug(f"Getting bounding box for {self.id}.")

result = self._faces_stub.GetBoundingBox(
request=self._grpc_id
)
result = self._faces_stub.GetBoundingBox(request=self._grpc_id)

return BoundingBox2D(result.min.x, result.max.x, result.min.y, result.max.y)

Expand All @@ -612,11 +608,11 @@ def get_closest_separation(self, other: "Face") -> tuple[Real, "Point3D", "Point
----------
other: Body
other body to find the closest separation with.
Returns
-------
tuple[Real, Point3D, Point3D]
tuple with the distance between the faces, the point on the first face (self),
tuple with the distance between the faces, the point on the first face (self),
and the point on the second face.
"""
self._grpc_client.log.debug(f"Getting closest separation from {self.id} to {other._id}.")
Expand All @@ -630,4 +626,4 @@ def get_closest_separation(self, other: "Face") -> tuple[Real, "Point3D", "Point

point_a = grpc_point_to_point3d(result.point_a)
point_b = grpc_point_to_point3d(result.point_b)
return (result.distance, point_a, point_b)
return (result.distance, point_a, point_b)
12 changes: 4 additions & 8 deletions src/ansys/geometry/core/designer/geometry_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
RevolveFacesByHelixRequest,
RevolveFacesRequest,
RevolveFacesUpToRequest,
SplitBodyRequest,
RoundInfoRequest,
SplitBodyRequest,
)
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
from ansys.geometry.core.connection.client import GrpcClient
Expand Down Expand Up @@ -1157,10 +1157,6 @@ def get_round_info(self, face: "Face") -> tuple[bool, Real]:
Real
Radius of the round
"""
result = self._commands_stub.GetRoundInfo(
RoundInfoRequest(
face = face._grpc_id
)
)

return (result.along_u, result.radius)
result = self._commands_stub.GetRoundInfo(RoundInfoRequest(face=face._grpc_id))

return (result.along_u, result.radius)
18 changes: 11 additions & 7 deletions src/ansys/geometry/core/math/bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"""Provides for managing a bounding box."""

import sys
from typing import Union

from beartype import beartype as check_input_types
from typing import Union

from ansys.geometry.core.math.point import Point2D
from ansys.geometry.core.misc.accuracy import Accuracy
Expand Down Expand Up @@ -215,11 +215,15 @@ def __ne__(self, other: "BoundingBox2D") -> bool:
@check_input_types
def __and__(self, other: "BoundingBox2D") -> Union[None, "BoundingBox2D"]:
"""Bitwise and operator for the ``BoundingBox2D`` class."""
intersect, minX, maxX = self.intersect_interval(self.x_min, other.x_min, self.x_max, other.x_max)
intersect, minX, maxX = self.intersect_interval(
self.x_min, other.x_min, self.x_max, other.x_max
)
if not intersect:
return None

intersect, minY, maxY = self.intersect_interval(self.y_min, other.y_min, self.y_max, other.y_max)
intersect, minY, maxY = self.intersect_interval(
self.y_min, other.y_min, self.y_max, other.y_max
)
if not intersect:
return None

Expand All @@ -228,17 +232,17 @@ def __and__(self, other: "BoundingBox2D") -> Union[None, "BoundingBox2D"]:
@staticmethod
def intersect_interval(firstMin, secondMin, firstMax, secondMax) -> bool:
min = secondMin
if (firstMin > min):
if firstMin > min:
min = firstMin

max = secondMax
if (firstMax < max):
if firstMax < max:
max = firstMax

if (min > max):
if min > max:
if min - max > Accuracy.length_accuracy():
return False, 0, 0

max, min = min, max

return True, min, max
return True, min, max
2 changes: 1 addition & 1 deletion tests/integration/test_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -3097,4 +3097,4 @@ def test_set_face_color(modeler: Modeler):
# Assigning color object directly
blue_color = mcolors.to_rgba("#0000FF")
faces[2].color = blue_color
assert faces[2].color == "#0000ff"
assert faces[2].color == "#0000ff"
9 changes: 4 additions & 5 deletions tests/integration/test_geometry_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ def test_split_body_by_face(modeler: Modeler):
Quantity(0.5, UNITS.m**3).m, rel=1e-6, abs=1e-8
)


def test_get_round_info(modeler: Modeler):
"""Test getting the round info from a face"""
design = modeler.create_design("full_fillet")
Expand All @@ -774,9 +775,7 @@ def test_get_round_info(modeler: Modeler):
)

_, radius = modeler.geometry_commands.get_round_info(body.faces[6])
assert radius == pytest.approx(
Quantity(0.1, UNITS.m).m, rel=1e-6, abs=1e-8
)
assert radius == pytest.approx(Quantity(0.1, UNITS.m).m, rel=1e-6, abs=1e-8)


def test_get_empty_round_info(modeler: Modeler):
Expand Down Expand Up @@ -820,7 +819,7 @@ def test_get_face_bounding_box(modeler: Modeler):
assert bounding_box.x_min == bounding_box.y_min == -0.5
assert bounding_box.x_max == bounding_box.y_max == 0.5


def test_linear_pattern_on_imported_geometry_faces(modeler: Modeler):
"""Test create a linear pattern on imported geometry"""
design = modeler.open_file(FILES_DIR / "LinearPatterns.scdocx")
Expand Down Expand Up @@ -968,4 +967,4 @@ def test_update_fill_pattern_on_imported_geometry_faces(modeler: Modeler):
assert len(design.bodies[0].faces) == 342
assert design.bodies[0].volume.m == pytest.approx(
Quantity(4.70663693e-6, UNITS.m**3).m, rel=1e-6, abs=1e-8
)
)
18 changes: 11 additions & 7 deletions tests/integration/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,10 @@ def test_plot_design_face_colors(modeler: Modeler, verify_image_cache):
"""Test plotting of design with/without multi_colors."""
design = modeler.create_design("DesignFaceColors")
# Create a sketch of a box
sketch_box = Sketch().box(Point2D([0, 0], unit=UNITS.m), width=10 * UNITS.m, height=10 * UNITS.m)

sketch_box = Sketch().box(
Point2D([0, 0], unit=UNITS.m), width=10 * UNITS.m, height=10 * UNITS.m
)

# Extrude both sketches to get a prism and change face colors
design.extrude_sketch("Prism", sketch_box, 10 * UNITS.m)
design.bodies[0].faces[0].set_color((255, 0, 0))
Expand All @@ -922,9 +924,10 @@ def test_plot_design_face_colors(modeler: Modeler, verify_image_cache):
design.bodies[0].plot(
screenshot=Path(IMAGE_RESULTS_DIR, "plot_design_face_colors.png"),
merge=False,
multi_colors=True
multi_colors=True,
)


@skip_no_xserver
def test_export_gltf(modeler: Modeler, verify_image_cache):
"""Test exporting a box to gltf."""
Expand All @@ -937,8 +940,9 @@ def test_export_gltf(modeler: Modeler, verify_image_cache):

# Extrude the sketch to create a body
box_body = design.extrude_sketch("JustABox", sketch, Quantity(10, UNITS.mm))

from ansys.tools.visualization_interface.types.mesh_object_plot import MeshObjectPlot

mesh_object = MeshObjectPlot(box_body, box_body.tessellate(merge=True))
pl = GeometryPlotter()
pl.plot(mesh_object)
Expand Down Expand Up @@ -993,7 +997,7 @@ def test_export_gltf_with_face_color(modeler: Modeler, verify_image_cache):

output_gltf_path = Path(IMAGE_RESULTS_DIR, "plot_box_gltf_face_colored.gltf")
box_body.export_gltf(screenshot=output_gltf_path, use_service_colors=True)

output_png_path = Path(IMAGE_RESULTS_DIR, "plot_box_gltf_face_colored.png")
box_body.plot(merge=False, screenshot=output_png_path, multi_colors=True)

Expand All @@ -1003,7 +1007,7 @@ def test_export_gltf_cylinder_with_face_color(modeler: Modeler, verify_image_cac
"""Test exporting a cylinder to gltf."""
# Create your design on the server side
design = modeler.create_design("BoxExtrusions")

# Create a sketch of a circle (overlapping the box slightly)
sketch_circle = Sketch().circle(Point2D([20, 0], unit=UNITS.m), radius=3 * UNITS.m)
cyl = design.extrude_sketch("Cylinder", sketch_circle, 50 * UNITS.m)
Expand All @@ -1014,6 +1018,6 @@ def test_export_gltf_cylinder_with_face_color(modeler: Modeler, verify_image_cac

output_gltf_path = Path(IMAGE_RESULTS_DIR, "plot_cylinder_gltf_face_colored.gltf")
cyl.export_gltf(screenshot=output_gltf_path, use_service_colors=True)

output_png_path = Path(IMAGE_RESULTS_DIR, "plot_cylinder_gltf_face_colored.png")
cyl.plot(merge=False, screenshot=output_png_path, multi_colors=True)
2 changes: 1 addition & 1 deletion tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,4 +1241,4 @@ def test_bounding_box_bitwise_and_no_intersection():

# Get intersection and check
intersection = box1 & box2
assert intersection is None
assert intersection is None

0 comments on commit e7bb5e1

Please sign in to comment.