Repository: sympy/sympy
Pull request: Modified Ellipse to return segment when h or v radius is zero
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234". See
https://github.com/blog/1506-closing-issues-via-pull-requests .-->
Fixes #15268 

#### Brief description of what is fixed or changed


#### Other comments


#### Release Notes

<!-- Write the release notes for this release below. See
https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more information
on how to write release notes. The bot will check your release notes
automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
* geometry
  * Modified Ellipse to return Segment when either hradius or vradius is zero
<!-- END RELEASE NOTES -->


Problem statement:
Ellipse with 0 h or v radius is Segment
```
>>> Ellipse((a, b),3,0)
Ellipse(Point2D(0, 0), 3, 0)
>>> _.equation()
x**2/9 + zoo*y**2 - 1
```
This could be
```
Segment((a-3,b),(a+3,b))
```
and similar for the case when hradius is 0. When both are zero, a Point should be obtained.

Hints from issue discussion:

Commit message: Remove trailing whitespace in geometry/test_ellipse.py

Patch to review:
diff --git a/sympy/geometry/ellipse.py b/sympy/geometry/ellipse.py
index 93766e25d358..93d9a2217051 100644
--- a/sympy/geometry/ellipse.py
+++ b/sympy/geometry/ellipse.py
@@ -26,7 +26,7 @@
 
 from .entity import GeometryEntity, GeometrySet
 from .point import Point, Point2D, Point3D
-from .line import Line, LinearEntity
+from .line import Line, LinearEntity, Segment
 from .util import idiff
 
 import random
@@ -147,6 +147,15 @@ def __new__(
         if hradius == vradius:
             return Circle(center, hradius, **kwargs)
 
+        if hradius == 0 and vradius == 0:
+            return center
+
+        if hradius == 0:
+            return Segment(Point(center[0], center[1]-vradius), Point(center[0], center[1]+vradius))
+
+        if vradius == 0:
+            return Segment(Point(center[0]-hradius, center[1]), Point(center[0]+hradius, center[1]))
+
         return GeometryEntity.__new__(cls, center, hradius, vradius, **kwargs)
 
     def _svg(self, scale_factor=1., fill_color="#66cc99"):
diff --git a/sympy/geometry/tests/test_ellipse.py b/sympy/geometry/tests/test_ellipse.py
index 01756ff84232..10658a6d7079 100644
--- a/sympy/geometry/tests/test_ellipse.py
+++ b/sympy/geometry/tests/test_ellipse.py
@@ -58,6 +58,10 @@ def test_ellipse_geom():
     assert c1.hradius == 1
     assert c1.vradius == 1
 
+    assert Ellipse((1, 1), 0, 0) == Point(1, 1)
+    assert Ellipse((1, 1), 1, 0) == Segment(Point(0, 1), Point(2, 1))
+    assert Ellipse((1, 1), 0, 1) == Segment(Point(1, 0), Point(1, 2))
+
     # Private Functions
     assert hash(c1) == hash(Circle(Point(1, 0), Point(0, 1), Point(0, -1)))
     assert c1 in e1


Code review comments:
diff_hunk: @@ -147,6 +147,15 @@ def __new__(
         if hradius == vradius:
             return Circle(center, hradius, **kwargs)
 
+        if hradius == 0 and vradius == 0:
+            return center
+
+        if hradius == 0:
+            return Segment(Point(center[0], center[1]-vradius), Point(center[0], center[1]+vradius))
+
+        if vradius == 0:
+            return Segment(Point(center[0]-hradius, center[1]), Point(center[0]+hradius, center[1]))
path: sympy/geometry/ellipse.py
text: @user1:
How about:
```
if hradius == vradius:
	return center if hradius == 0 else Circle(center, hradius, **kwargs)

if hradius == 0 or vradius == 0:
	return Segment(Point(center[0] - hradius, center[1] - vradius),
						Point(center[0] + hradius, center[1] + vradius))
``` 

@author:
Thanks! I'll make these changes. But I'm having a problem: There is a test case for calculating the circumference of a degenerate ellipse. But now since we are returning it as a Segment, this test case fails as Segment does not have circumference method. So, should I remove this test case?

@user1:
You could possibly use `length` for the test case where a `Segment` is returned by a degenerate `Ellipse`.