-
-
Notifications
You must be signed in to change notification settings - Fork 22
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 spade shape #195
Add spade shape #195
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 #195 +/- ##
==========================================
+ Coverage 98.42% 98.43% +0.01%
==========================================
Files 43 43
Lines 1775 1792 +17
Branches 358 360 +2
==========================================
+ Hits 1747 1764 +17
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.
Thank you for the PR, @kevinr1299 – I'm very excited for this shape!
from data_morph.data.loader import DataLoader | ||
from data_morph.shapes.points import Heart | ||
|
||
_ = Spade(DataLoader.load_dataset('panda')).plot() |
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 code gets executed while building the docs, so this won't work as is.
from data_morph.data.loader import DataLoader | |
from data_morph.shapes.points import Heart | |
_ = Spade(DataLoader.load_dataset('panda')).plot() | |
from data_morph.data.loader import DataLoader | |
from data_morph.shapes.points import Spade | |
_ = Spade(DataLoader.load_dataset('panda')).plot() |
# Graph heart curve | ||
x_shift = sum(x_bounds) / 2 | ||
y_shift = sum(y_bounds) / 2 | ||
|
||
t = np.linspace(-3, 3, num=90) | ||
|
||
heart_x = -(16 * np.sin(t) ** 3) | ||
heart_y = -( | ||
13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t) | ||
) |
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.
Since we are using the heart equations, we should share the logic rather than duplicate it.
# Graph left wing | ||
left_t = np.linspace(-6, 0, num=12) | ||
left_x = left_t | ||
left_y = [0.278 * math.pow(point + 6.0, 2) - 16.0 for point in left_t] |
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 use numpy
instead of math
and vectorize this. https://numpy.org/doc/stable/reference/generated/numpy.power.html
line_t = np.linspace(-6, 6, num=12) | ||
line_x = line_t | ||
line_y = [-16 for _ in line_t] |
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.
What about this?
line_t = np.linspace(-6, 6, num=12) | |
line_x = line_t | |
line_y = [-16 for _ in line_t] | |
line_x = np.linspace(-6, 6, num=12) | |
line_y = np.repeat(-16, 12) |
@@ -1,6 +1,7 @@ | |||
"""Shapes that are composed of points.""" | |||
|
|||
import itertools | |||
import math |
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 should be able to just use numpy here.
import math |
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.
I left some comments above around speeding up the shape creation and reducing the duplication with the heart.
This was completed in #225. |
Fixes #163
Describe your changes
Add the logic to morph into a spade shape
Checklist