-
-
Notifications
You must be signed in to change notification settings - Fork 57
Fix the Point concept #101
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
Merged
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fb04166
Add Point type
juliohm d8ca8a9
Add conversion methods
juliohm ef1df4d
Downstream fixes
juliohm ddb4a0c
Fix tests
juliohm 6ce6b7b
Downstream fixes
juliohm 949cd3e
Fix tests
juliohm 86173ee
Downstream fixes
juliohm 3420a09
Fix tests
juliohm 5374fea
Downstream fixes
juliohm a578874
Fix tests
juliohm ac3f732
Downstream fixes
juliohm 34b61fd
Fix tests
juliohm 8b1db68
Downstream fixes
juliohm a7a0653
Fix tests
juliohm eb87c85
Add rand methods for points
juliohm 713d3e5
Downstream fixes
juliohm 336cdc3
Fix tests
juliohm c4ab4c5
Downstream fixes
juliohm c9a6b0d
Fix tests
juliohm fe1836c
Small adjustments
juliohm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| abstract type AbstractPoint{N,T} end | ||
|
|
||
| """ | ||
| Point{N,T} | ||
|
|
||
| A point in `N`-dimensional space with coordinates of type `T`. | ||
| The coordinates of the point provided upon construction are with | ||
| respect to the canonical Euclidean basis. See [`vunit`](@ref). | ||
|
|
||
| ## Example | ||
|
|
||
| ```julia | ||
| O = Point(0.0, 0.0) # origin of 2D Euclidean space | ||
| ``` | ||
|
|
||
| ### Notes | ||
|
|
||
| - Type aliases are `Point2`, `Point3`, `Point2f`, `Point3f` | ||
| """ | ||
| struct Point{N,T} <: AbstractPoint{N,T} | ||
| coords::SVector{N,T} | ||
| end | ||
|
|
||
| # convenience constructors | ||
| Point(coords::NTuple{N,T}) where {N,T} = Point{N,T}(SVector(coords)) | ||
| Point(coords::Vararg{T,N}) where {N,T} = Point{N,T}(SVector(coords)) | ||
|
|
||
| # coordinate type conversions | ||
| Point{N,T}(coords::NTuple{N,V}) where {N,T,V} = Point(T.(coords)) | ||
| Point{N,T}(coords::Vararg{V,N}) where {N,T,V} = Point(T.(coords)) | ||
| Base.convert(::Type{Point{N,T}}, coords) where {N,T} = Point{N,T}(coords) | ||
| Base.convert(::Type{Point{N,T}}, p::Point) where {N,T} = Point{N,T}(p.coords) | ||
|
|
||
| # type aliases for convenience | ||
| const Point2 = Point{2,Float64} | ||
| const Point3 = Point{3,Float64} | ||
| const Point2f = Point{2,Float32} | ||
| const Point3f = Point{3,Float32} | ||
|
|
||
| """ | ||
| coordinates(A::Point) | ||
|
|
||
| Return the coordinates of the point with respect to the | ||
| canonical Euclidean basis. See [`vunit`](@ref). | ||
| """ | ||
| coordinates(A::Point) = A.coords | ||
|
|
||
| """ | ||
| -(A::Point, B::Point) | ||
|
|
||
| Return the [`Vec`](@ref) associated with the direction | ||
| from point `A` to point `B`. | ||
| """ | ||
| -(A::Point, B::Point) = Vec(A.coords - B.coords) | ||
|
|
||
| """ | ||
| +(A::Point, v::Vec) | ||
| +(v::Vec, A::Point) | ||
|
|
||
| Return the point at the end of the vector `v` placed | ||
| at a reference (or start) point `A`. | ||
| """ | ||
| +(A::Point, v::Vec) = Point(A.coords + v) | ||
| +(v::Vec, A::Point) = A + v | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 no inherit from StaticArrays? That would give us all functionality, and you could still get rid of the macro and rework the overloaded functions.
This will make it very unlikely to get merged, since you're dropping tons of functionality
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 functionality you are missing? It would be helpful to understand why you are resistant.
I appreciate if you can communicate more explicitly the design issues you have in your mind so that we can both work together on a satisfying solution. Currently, we don't have a satisfying point implementation, and I can't see how inheriting from StaticArrays.jl would help.