-
Notifications
You must be signed in to change notification settings - Fork 94
RegularDiscretization of Triangle and Tetrahedron #1206
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1206 +/- ##
==========================================
- Coverage 88.43% 88.43% -0.01%
==========================================
Files 196 196
Lines 6159 6163 +4
==========================================
+ Hits 5447 5450 +3
- Misses 712 713 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR introduces RegularDiscretization
support for 2D and 3D simplices by adding new dispatch methods and corresponding tests.
- Adds
discretize
overloads forTriangle
andTetrahedron
using a genericdiscretizewithinbox
helper. - Updates existing polygon test resolution and adds a new triangle discretization test (tetrahedron tests pending
isconvex
support). - Refactors fallback in
src/discretization/regular.jl
to calldiscretizewithinbox
from both the general and specific dispatch paths.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
test/discretization.jl | Reduced polygon resolution, added triangle discretization test, pending tetrahedron test. |
src/discretization/regular.jl | Introduced discretizewithinbox , added overloads for Triangle and Tetrahedron . |
Comments suppressed due to low confidence (5)
test/discretization.jl:464
- Consider adding a placeholder or @test_throws for
Tetrahedron
onceisconvex
is implemented, to ensure coverage for 3D simplex discretization.
tri = Triangle(cart(0, 0), cart(1, 0), cart(0, 1))
src/discretization/regular.jl:30
- Add a docstring above this method to explain that triangle discretization is implemented by sampling its bounding box and then restricting to the triangle.
discretize(triangle::Triangle, method::RegularDiscretization) = discretizewithinbox(triangle, method)
src/discretization/regular.jl:32
- Add a docstring for the tetrahedron overload to clarify the approach and any limitations (e.g., requirement for a convex geometry).
discretize(tetrahedron::Tetrahedron, method::RegularDiscretization) = discretizewithinbox(tetrahedron, method)
src/discretization/regular.jl:34
- [nitpick] The helper name
discretizewithinbox
could be more idiomatically written asdiscretize_within_box
to match snake_case conventions and improve readability.
function discretizewithinbox(geometry::Geometry, method::RegularDiscretization)
src/discretization/regular.jl:30
- Since the general
discretize(Geometry, RegularDiscretization)
fallback already callsdiscretizewithinbox
, these explicit overloads forTriangle
andTetrahedron
may be redundant; consider relying solely on the fallback unless specialized behavior is needed.
discretize(triangle::Triangle, method::RegularDiscretization) = discretizewithinbox(triangle, method)
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.
LGTM. I only left one minor suggestion below.
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.
Thanks!
Just FYI (probably you are already aware of it): Something similar probably has to be done for RegularSampling
. I just tried on master
julia> using Meshes
julia> tri = Triangle(Point(0, 0), Point(1, 0), Point(0, 1))
Triangle
├─ Point(x: 0.0 m, y: 0.0 m)
├─ Point(x: 1.0 m, y: 0.0 m)
└─ Point(x: 0.0 m, y: 1.0 m)
julia> p = sample(tri, RegularSampling(10))
Base.Iterators.Flatten{Base.Generator{Tuple{Base.Generator{Base.Iterators.ProductIterator{Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}, Meshes.var"#459#463"{Triangle{𝔼{2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}}}, Base.Generator{Tuple{}, typeof(identity)}}, typeof(identity)}}(Base.Generator{Tuple{Base.Generator{Base.Iterators.ProductIterator{Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}, Meshes.var"#459#463"{Triangle{𝔼{2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}}}, Base.Generator{Tuple{}, typeof(identity)}}, typeof(identity)}(identity, (Base.Generator{Base.Iterators.ProductIterator{Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}, Meshes.var"#459#463"{Triangle{𝔼{2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}}}(Meshes.var"#459#463"{Triangle{𝔼{2}, CoordRefSystems.Cartesian2D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}}(Triangle((x: 0.0 m, y: 0.0 m), (x: 1.0 m, y: 0.0 m), (x: 0.0 m, y: 1.0 m))), Base.Iterators.ProductIterator{Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}((0.0:0.1111111111111111:1.0, 0.0:0.1111111111111111:1.0))), Base.Generator{Tuple{}, typeof(identity)}(identity, ()))))
julia> collect(p)
ERROR: DomainError with (1.0, 0.1111111111111111):
invalid barycentric coordinates for triangle.
So, this looks like a similar issue, which would be good to resolve.
I think the |
Ah, I would have expected that |
That is a good point. Maybe we should consider this more general definition! |
Sounds good. |
If we allow |
Alternatively, one could think of providing a translation from |
Yes, that inconsistency bothered me too in the past, but most algorithms I know that use triangles and tetrahedra end up requiring barycentric coordinates. The mapping of the box coordinates to the barycentric coordinates (and vice-versa) could be useful in other contexts besides numerical integration. The other examples with unbounded parametric coordinates like |
This PR adds methods for
RegularDiscretization
ofTriangle
andTetrahedron
. The parametrization of simplices of 2 or more dimensions is not orthogonal so we can't rely onRegularSampling
.I didn't add a test for
Tetrahedron
due to a missingisconvex
method reported in #1205.