-
-
Notifications
You must be signed in to change notification settings - Fork 372
Generalize Shape #3436
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
Generalize Shape #3436
Conversation
|
|
||
| "get an array of tuples of points on a circle with radius `r`" | ||
| function partialcircle(start_θ, end_θ, n = 20, r=1) | ||
| Tuple{Float64,Float64}[(r*cos(u),r*sin(u)) for u in range(start_θ, stop=end_θ, length=n)] |
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.
The removal of the type annotation here is only necessary for creating circles with a radius ::MyType. The type in these tuples will be that of *(::MyType, ::Float64), but I don't think annotating that changes the type of the vector.
If this annotation is very important for performance, this change could easily be reverted, it's not a very important function.
Codecov Report
@@ Coverage Diff @@
## master #3436 +/- ##
==========================================
+ Coverage 63.64% 63.65% +0.01%
==========================================
Files 27 27
Lines 6582 6585 +3
==========================================
+ Hits 4189 4192 +3
Misses 2393 2393
Continue to review full report at Codecov.
|
| function rotate(shape::Shape, θ::Real, c = center(shape)) | ||
| x, y = coords(shape) | ||
| cx, cy = c | ||
| x_new = rotate_x.(x, y, θ, cx, cy) | ||
| y_new = rotate_y.(x, y, θ, cx, cy) | ||
| Shape(x_new, y_new) |
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.
Rotating a Shape{Int, Int} will leave you with a Shape{Float64, Float64}, so rotate! doesn't work in general. I did a quick benchmark, and this function if anything seems slightly faster than the rotate! version.
daschw
left a comment
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.
Looks great!
|
Thanks! |
Allows
Shapeto hold other types thanFloat64, so that recipes can dispatch on the vertices.With this change, for instance,
Shape([(0u"m", 1u"s"), (1u"m", 1u"s"), (1u"m", 2u"s")])(with Unitful unitsu"m"andu"s") is a validShape, and when plotted it will invoke the recipes for the respective axis types: