This repository was archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
added ellipses #202
Open
yakir12
wants to merge
1
commit into
JuliaGeometry:master
Choose a base branch
from
yakir12:yg/ellipse
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
added ellipses #202
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| Ellipsoid(x...) = HyperEllipse(x...) | ||
|
|
||
| Ellipse(x...) = HyperEllipse(x...) | ||
|
|
||
| widths(c::HyperEllipse{N, T}) where {N, T} = Vec{N, T}(radius(c)*2) | ||
| radius(c::HyperEllipse) = c.r | ||
| origin(c::HyperEllipse) = c.center | ||
| minimum(c::HyperEllipse{N, T}) where {N, T} = Vec{N, T}(origin(c)) - radius(c) | ||
| maximum(c::HyperEllipse{N, T}) where {N, T} = Vec{N, T}(origin(c)) + radius(c) | ||
|
|
||
| _ellipseterm(p, c, r) = ((p - c)/r)^2 | ||
| isinside(c::HyperEllipse{N,T}, p::Point{N,R}) where {N, T, R} = mapreduce(_ellipseterm, +, p, origin(c), radius(c)) ≤ 1 | ||
| isinside(c::Ellipse, x::Real, y::Real) = isinside(c, Point(x, y)) | ||
|
|
||
| centered(S::Type{HyperEllipse{N, T}}) where {N, T} = S(Vec{N,T}(0), Vec{N,T}(0.5)) | ||
| centered(::Type{T}) where {T <: HyperEllipse} = centered(HyperEllipse{ndims_or(T, 3), eltype_or(T, Float32)}) |
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
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,36 @@ | ||
| @testset "HyperEllipse" begin | ||
| @test Ellipsoid(Point(0,0,0), Vec(4, 3, 2)) == HyperEllipse{3,Int}(Point{3,Int}((0,0,0)),Vec{3,Int}((4,3,2))) | ||
| c = Ellipse(Point(0,0), Vec(1,2)) | ||
| @test c == HyperEllipse(Point(0,0), Vec(1,2)) | ||
| @test origin(c) == Point(0,0) | ||
| @test !( isinside(c, 1, 2) ) | ||
| @test isinside(c, 0.5, 0.5) | ||
|
|
||
| centered_rect = centered(HyperEllipse) | ||
| @test centered_rect == HyperEllipse{3,Float32}(Point3f0(0), Vec3f0(0.5)) | ||
| centered_rect = centered(HyperEllipse{2}) | ||
| @test centered_rect == HyperEllipse{2,Float32}(Point2f0(0), Vec2f0(0.5)) | ||
|
|
||
| centered_rect = centered(HyperEllipse{2, Float64}) | ||
| @test centered_rect == HyperEllipse{2,Float64}(Point(0.,0.), Vec(0.5, 0.5)) | ||
|
|
||
| centered_rect = centered(HyperEllipse{3, Float32}) | ||
| @test centered_rect == HyperEllipse{3,Float32}(Point3f0(0), Vec3f0(0.5)) | ||
|
|
||
| @test widths(centered_rect) == Vec3f0(1) | ||
| @test radius(centered_rect) == Vec3f0(0.5) | ||
| @test maximum(centered_rect) == Vec3f0(0.5f0) | ||
| @test minimum(centered_rect) == Vec3f0(-0.5f0) | ||
| s = Ellipsoid(Point3f0(0), Vec3f0(1)) | ||
| f = decompose(Face{2, Int}, s, 3) | ||
| # TODO 54 linesegments for 3 facets is too much. | ||
| @test length(f) == 16 | ||
|
|
||
| s = Ellipsoid(Point3f0(-1, 10, 5), Vec3f0(3)) | ||
| ps = decompose(Point3f0, s) | ||
| bb = AABB(ps) | ||
| # The maximum radius doesn't get sampled in the ellipsoid mesh, hence the smaller widths | ||
| @test all(x-> x > 5.9 && x <= 6.0, widths(bb)) | ||
| middle = (minimum(bb) .+ (widths(bb) ./ 2)) | ||
| @test all(((x,y),)-> isapprox(x, y, atol = 0.05), zip((-1, 10, 5), middle)) | ||
| end |
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
@SimonDanisch I dunno how to implement src/primitives.jl#L28 for an Ellipse...
Uh oh!
There was an error while loading. Please reload this page.
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.
You should be able to do the same thing, since the triangulation is the same either way.
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 tried adding
to
primitives.jlbut I don't understand why it isn't working. Honestly, my understanding here is really low, I'm basically copy pasting things that were implemented specifically forHyperSphereand adjusting them to an ellipse (so 2 radii, not one). Stumped, do you know what's missing?