-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Add infinity and figure eight target shapes #190
base: main
Are you sure you want to change the base?
Add infinity and figure eight target shapes #190
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations on making your first pull request to Data Morph! Please familiarize yourself with the contributing guidelines, if you haven't already.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #190 +/- ##
==========================================
+ Coverage 98.42% 98.44% +0.01%
==========================================
Files 43 43
Lines 1775 1795 +20
Branches 358 356 -2
==========================================
+ Hits 1747 1767 +20
Misses 25 25
Partials 3 3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @MauriceDeVr! We are off to a good start.
def __str__(self) -> str: | ||
return 'infinity' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need this if the name is different than the lowercased class name.
def __str__(self) -> str: | |
return 'infinity' |
data-morph/src/data_morph/shapes/bases/shape.py
Lines 25 to 34 in b6bebc9
def __str__(self) -> str: | |
""" | |
Return string representation of the shape. | |
Returns | |
------- | |
str | |
The human-readable string representation of the shape. | |
""" | |
return self.__class__.__name__.lower() |
# print(shape.points[67]) | ||
print(shape.distance(*test_point)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# print(shape.points[67]) | |
print(shape.distance(*test_point)) |
Notes | ||
----- | ||
The formula for the infinity shape is directly taken from Lemniscate of | ||
Bernoulli equation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels more like a see also section. Something like this, but figure out a good description:
Notes | |
----- | |
The formula for the infinity shape is directly taken from Lemniscate of | |
Bernoulli equation. | |
See Also | |
-------- | |
_LemniscateBernoulli : Write a description here |
Notes | ||
----- | ||
Implements the Lemniscate of Bernoulli Equation with a transform | ||
to draw a figure eight shape. | ||
|
||
See Base class for implementation specifice details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do a see also section here as well, but also link to the Infinity
class.
super().__init__( | ||
*np.stack( | ||
[ | ||
transformed_x * scale_factor + x_shift, | ||
transformed_y * scale_factor + y_shift, | ||
], | ||
axis=1, | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x_shift = sum(x_bounds) / 2 | ||
y_shift = sum(y_bounds) / 2 | ||
|
||
t = np.linspace(-3, 3, num=2000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using 2,000 points is a lot, the algorithm needs to calculate the distance to each point. Can we reduce this? For example, the heart only uses 80.
@@ -131,6 +132,150 @@ def __init__(self, dataset: Dataset) -> None: | |||
) | |||
|
|||
|
|||
class _LemniscateBernoulli(PointCollection): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this with the Infinity
class (calling it Infinity
). The docs have a broken link with this because they ignore anything prefixed with _
, and this class has all the functionality of the Infinity
class already.
x = (np.sqrt(2) * np.cos(t)) / (1 + np.square(np.sin(t))) | ||
y = (np.sqrt(2) * np.cos(t) * np.sin(t)) / (1 + np.square(np.sin(t))) | ||
|
||
scale_factor = (x_bounds[1] - x_shift) * 0.75 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the y information here? Maybe pick one using the data? With the sheep for example, it seems like the figure eight is being drawn too tall, so we should probably take the minimum of the x and y scale factors and use that.
Try plotting a dataset and the shape on top of each other and see how that looks.
Fixes: #179
Fixes: #178
Changes