Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

MauriceDeVr
Copy link

@MauriceDeVr MauriceDeVr commented Jul 13, 2024

Fixes: #179
Fixes: #178

Changes

  • Added infinity Target Shape
  • Added Figure Eight Shape

@github-actions github-actions bot added the shapes Work relating to shapes module label Jul 13, 2024
Copy link

@github-actions github-actions bot left a 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.

@stefmolin stefmolin added this to the 0.3.0 milestone Jul 13, 2024
@github-actions github-actions bot added the testing Relating to the testing suite label Jul 13, 2024
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.44%. Comparing base (51b8d26) to head (0853d0a).
Report is 7 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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              
Files Coverage Δ
src/data_morph/shapes/factory.py 100.00% <ø> (ø)
src/data_morph/shapes/points.py 100.00% <100.00%> (ø)
tests/shapes/test_points.py 100.00% <100.00%> (ø)

@stefmolin stefmolin changed the title Add infinity target shape #179 Add infinity and figure eight target shapes Jul 16, 2024
Copy link
Owner

@stefmolin stefmolin left a 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.

Comment on lines +225 to +227
def __str__(self) -> str:
return 'infinity'

Copy link
Owner

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.

Suggested change
def __str__(self) -> str:
return 'infinity'

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()

Comment on lines +28 to +29
# print(shape.points[67])
print(shape.distance(*test_point))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# print(shape.points[67])
print(shape.distance(*test_point))

Comment on lines +219 to +222
Notes
-----
The formula for the infinity shape is directly taken from Lemniscate of
Bernoulli equation.
Copy link
Owner

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:

Suggested change
Notes
-----
The formula for the infinity shape is directly taken from Lemniscate of
Bernoulli equation.
See Also
--------
_LemniscateBernoulli : Write a description here

Comment on lines +244 to +249
Notes
-----
Implements the Lemniscate of Bernoulli Equation with a transform
to draw a figure eight shape.

See Base class for implementation specifice details.
Copy link
Owner

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.

Comment on lines +170 to +178
super().__init__(
*np.stack(
[
transformed_x * scale_factor + x_shift,
transformed_y * scale_factor + y_shift,
],
axis=1,
)
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shapes both have a gap. Let's make it a closed shape:

image

x_shift = sum(x_bounds) / 2
y_shift = sum(y_bounds) / 2

t = np.linspace(-3, 3, num=2000)
Copy link
Owner

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):
Copy link
Owner

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shapes Work relating to shapes module testing Relating to the testing suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add infinity target shape Add figure eight target shape
2 participants