From 0b3390250fdc3cd451b2cef33f7256d21ca17ec7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 23:23:47 +0000 Subject: [PATCH 1/3] Initial plan From eb9d62e46b9807d4fea611561126a77f1f41d3cc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Oct 2025 23:31:58 +0000 Subject: [PATCH 2/3] Add scaled() method overrides for Sphere, Cylinder, and Capsule shapes Co-authored-by: gonzalocasas <933277+gonzalocasas@users.noreply.github.com> --- src/compas/geometry/shapes/capsule.py | 18 +++++++++++++ src/compas/geometry/shapes/cylinder.py | 18 +++++++++++++ src/compas/geometry/shapes/sphere.py | 18 +++++++++++++ tests/compas/geometry/test_capsule.py | 36 ++++++++++++++++++++++++++ tests/compas/geometry/test_cylinder.py | 36 ++++++++++++++++++++++++++ tests/compas/geometry/test_shpere.py | 31 ++++++++++++++++++++++ 6 files changed, 157 insertions(+) diff --git a/src/compas/geometry/shapes/capsule.py b/src/compas/geometry/shapes/capsule.py index 8ba87f97cd4..584d0299ffd 100644 --- a/src/compas/geometry/shapes/capsule.py +++ b/src/compas/geometry/shapes/capsule.py @@ -348,6 +348,24 @@ def scale(self, factor): self.radius *= factor self.height *= factor + def scaled(self, factor): + """Returns a scaled copy of the capsule. + + Parameters + ---------- + factor : float + The scaling factor. + + Returns + ------- + :class:`compas.geometry.Capsule` + The scaled capsule. + + """ + capsule = self.copy() + capsule.scale(factor) + return capsule + # ============================================================================= # Methods # ============================================================================= diff --git a/src/compas/geometry/shapes/cylinder.py b/src/compas/geometry/shapes/cylinder.py index 29857a3743e..489c1dcb1e5 100644 --- a/src/compas/geometry/shapes/cylinder.py +++ b/src/compas/geometry/shapes/cylinder.py @@ -318,6 +318,24 @@ def scale(self, factor): self.radius *= factor self.height *= factor + def scaled(self, factor): + """Returns a scaled copy of the cylinder. + + Parameters + ---------- + factor : float + The scaling factor. + + Returns + ------- + :class:`compas.geometry.Cylinder` + The scaled cylinder. + + """ + cylinder = self.copy() + cylinder.scale(factor) + return cylinder + # ============================================================================= # Methods # ============================================================================= diff --git a/src/compas/geometry/shapes/sphere.py b/src/compas/geometry/shapes/sphere.py index 19007ba954b..019d430bb62 100644 --- a/src/compas/geometry/shapes/sphere.py +++ b/src/compas/geometry/shapes/sphere.py @@ -280,6 +280,24 @@ def scale(self, factor): """ self.radius *= factor + def scaled(self, factor): + """Returns a scaled copy of the sphere. + + Parameters + ---------- + factor : float + The scaling factor. + + Returns + ------- + :class:`compas.geometry.Sphere` + The scaled sphere. + + """ + sphere = self.copy() + sphere.scale(factor) + return sphere + # ============================================================================= # Methods # ============================================================================= diff --git a/tests/compas/geometry/test_capsule.py b/tests/compas/geometry/test_capsule.py index 51ebac0ea66..e45b5378c18 100644 --- a/tests/compas/geometry/test_capsule.py +++ b/tests/compas/geometry/test_capsule.py @@ -14,3 +14,39 @@ def test_capsule_discretization(capsule): assert capsule.edges assert capsule.faces assert capsule.vertices + + +def test_capsule_scaled(): + """Test that Capsule.scaled() returns a scaled copy without modifying the original.""" + capsule = Capsule(radius=5.0, height=10.0) + + # Test uniform scaling + scaled_capsule = capsule.scaled(0.5) + + # Original should be unchanged + assert capsule.radius == 5.0 + assert capsule.height == 10.0 + + # Scaled copy should have scaled dimensions + assert scaled_capsule.radius == 2.5 + assert scaled_capsule.height == 5.0 + + # Test scaling with factor > 1 + scaled_capsule_2 = capsule.scaled(2.0) + assert scaled_capsule_2.radius == 10.0 + assert scaled_capsule_2.height == 20.0 + assert capsule.radius == 5.0 # Original still unchanged + assert capsule.height == 10.0 + + +def test_capsule_scale(): + """Test that Capsule.scale() modifies the capsule in place.""" + capsule = Capsule(radius=5.0, height=10.0) + + # Test uniform scaling + capsule.scale(0.5) + + # Capsule should be modified + assert capsule.radius == 2.5 + assert capsule.height == 5.0 + diff --git a/tests/compas/geometry/test_cylinder.py b/tests/compas/geometry/test_cylinder.py index 56ce885efeb..b828062ee61 100644 --- a/tests/compas/geometry/test_cylinder.py +++ b/tests/compas/geometry/test_cylinder.py @@ -13,3 +13,39 @@ def test_cylinder_discretization(cylinder): assert cylinder.edges assert cylinder.faces assert cylinder.vertices + + +def test_cylinder_scaled(): + """Test that Cylinder.scaled() returns a scaled copy without modifying the original.""" + cylinder = Cylinder(radius=5.0, height=10.0) + + # Test uniform scaling + scaled_cylinder = cylinder.scaled(0.5) + + # Original should be unchanged + assert cylinder.radius == 5.0 + assert cylinder.height == 10.0 + + # Scaled copy should have scaled dimensions + assert scaled_cylinder.radius == 2.5 + assert scaled_cylinder.height == 5.0 + + # Test scaling with factor > 1 + scaled_cylinder_2 = cylinder.scaled(2.0) + assert scaled_cylinder_2.radius == 10.0 + assert scaled_cylinder_2.height == 20.0 + assert cylinder.radius == 5.0 # Original still unchanged + assert cylinder.height == 10.0 + + +def test_cylinder_scale(): + """Test that Cylinder.scale() modifies the cylinder in place.""" + cylinder = Cylinder(radius=5.0, height=10.0) + + # Test uniform scaling + cylinder.scale(0.5) + + # Cylinder should be modified + assert cylinder.radius == 2.5 + assert cylinder.height == 5.0 + diff --git a/tests/compas/geometry/test_shpere.py b/tests/compas/geometry/test_shpere.py index 1be9ba4941d..68f42e9272d 100644 --- a/tests/compas/geometry/test_shpere.py +++ b/tests/compas/geometry/test_shpere.py @@ -17,3 +17,34 @@ def test_sphere_discretization(sphere): assert len(sphere.edges) == expected_edge_count assert len(sphere.faces) == expected_face_count assert len(sphere.vertices) == expected_vertex_count + + +def test_sphere_scaled(): + """Test that Sphere.scaled() returns a scaled copy without modifying the original.""" + sphere = Sphere(radius=10.0) + + # Test uniform scaling + scaled_sphere = sphere.scaled(0.5) + + # Original should be unchanged + assert sphere.radius == 10.0 + + # Scaled copy should have scaled radius + assert scaled_sphere.radius == 5.0 + + # Test scaling with factor > 1 + scaled_sphere_2 = sphere.scaled(2.0) + assert scaled_sphere_2.radius == 20.0 + assert sphere.radius == 10.0 # Original still unchanged + + +def test_sphere_scale(): + """Test that Sphere.scale() modifies the sphere in place.""" + sphere = Sphere(radius=10.0) + + # Test uniform scaling + sphere.scale(0.5) + + # Sphere should be modified + assert sphere.radius == 5.0 + From bd0252b6c719965eda722d50be9745bc1bbe450e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Oct 2025 00:10:20 +0000 Subject: [PATCH 3/3] Add CHANGELOG.md entry for scaled() method fix Co-authored-by: gonzalocasas <933277+gonzalocasas@users.noreply.github.com> --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e5db937c4..d1c30e2e8f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Updated minimum library version to `2.14.1` in Rhino8 GH components. * Changed name of YAK package from `bluejay` to `compas`. +* Fixed broken `scaled()` method in `Sphere`, `Cylinder`, and `Capsule` classes by overriding to accept uniform scaling factor. ### Removed