-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Ksimplex data type. * Rename `Ksimplex` -> `KSimplex`. * Rename KSimplex -> Simplex. * Overhaul constructors for Simplex type. * Define `issimplex` on Simplex type. * Add some more tests for Simplex. * Change `materialize` to always splat. * Rename file `ksimplex.jl` to `simplex.jl` * Remove mention of IndAdjTopology. * Some beauty improvements. * Nit: docstring format. Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com> * Docstring rewrite. Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com> * Nit: docstring. Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com> * Replace `K_` by `N`. Co-authored-by: Elias Carvalho <73039601+eliascarv@users.noreply.github.com> * Remove parametric constructors. Co-authored-by: Elias Carvalho <73039601+eliascarv@users.noreply.github.com> * Re-add parametric constructor for `K`. The reason we need this is for `materialize` to work. Specifically, consider the following code: ```julia P3 = Point{3} pts = [P3(0,0,0), P3(-1,-1,0), P3(-1,1,0), P3(1,1,0), P3(1,-1,0)] simplicies = connect.([(1, 2, 3), (1, 3, 4), (1, 4, 5), (1, 5, 2)], Simplex) # or Simplex{2} splx = materialize(simplicies[1], pts) ``` `Connection` requires `nvertices` to be defined on the Polytope type, so `connect` constructs the type `Simplex{K}`. Then, `materialize` tries to construct `PL(pts)` where `PL == Simplex{K}`. Therefore we need this constructor to be defined. * Refactor construction test. Refer to the last commit for the rationale behind the parametric constructor. * Add `display` test. * Fixup whitespace 4 spaces -> 2 spaces. * Revert "Change `materialize` to always splat." This reverts commit 74f76ed. * Support parametric constructor also for vararg, used by materialize. See also f74d34e. * Replace `Vararg` by splatted NTuple constructor. * Change NTuple constructor to Vararg constructor. * Remove mention of missing constructors. * Run formatter on all files. * Apply suggestions from code review Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com> * Apply suggestions & Update tests * Add header * Add more tests * Apply suggestions * Update tests --------- Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com> Co-authored-by: Elias Carvalho <73039601+eliascarv@users.noreply.github.com>
- Loading branch information
1 parent
ea14cb4
commit b3f6265
Showing
6 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -232,6 +232,7 @@ export | |
|
||
# polytopes | ||
Polytope, | ||
Simplex, | ||
Chain, | ||
Segment, | ||
Rope, | ||
|
This file contains 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 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 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,39 @@ | ||
# ------------------------------------------------------------------ | ||
# Licensed under the MIT License. See LICENSE in the project root. | ||
# ------------------------------------------------------------------ | ||
|
||
""" | ||
Simplex(p₁, p₂, ..., pₖ, pₖ₊₁) | ||
A K-simplex is a polytope with parametric dimension K and K+1 vertices. | ||
It generalizes the [`Segment`](@ref), the [`Triangle`](@ref) and the | ||
[`Tetrahedron`](@ref) to higher dimensions (K > 3). | ||
See also [`issimplex`](@ref). | ||
""" | ||
struct Simplex{K,Dim,T,N} <: Polytope{K,Dim,T} | ||
vertices::NTuple{N,Point{Dim,T}} | ||
end | ||
|
||
function Simplex{K}(vertices::NTuple{N,Point{Dim,T}}) where {K,Dim,T,N} | ||
N == K + 1 || throw(ArgumentError("number of vertices must be equal to rank K plus one")) | ||
K ≤ Dim || throw(ArgumentError("rank K must be less or equal to embedding dimension")) | ||
Simplex{K,Dim,T,N}(vertices) | ||
end | ||
|
||
Simplex{K}(vertices::Point{Dim,T}...) where {K,Dim,T} = Simplex{K}(vertices) | ||
Simplex{K}(vertices::Tuple...) where {K} = Simplex{K}(Point.(vertices)) | ||
|
||
function Simplex(vertices::NTuple{N,Point{Dim,T}}) where {Dim,T,N} | ||
K = N - 1 | ||
K ≤ Dim || throw(ArgumentError("rank (number of vertices minus one) must be less or equal to embedding dimension")) | ||
Simplex{K,Dim,T,N}(vertices) | ||
end | ||
|
||
Simplex(vertices::Point{Dim,T}...) where {Dim,T} = Simplex(vertices) | ||
Simplex(vertices::Tuple...) = Simplex(Point.(vertices)) | ||
|
||
nvertices(::Type{<:Simplex{K}}) where {K} = K + 1 | ||
|
||
Base.isapprox(s₁::Simplex, s₂::Simplex; kwargs...) = | ||
all(isapprox(v₁, v₂; kwargs...) for (v₁, v₂) in zip(vertices(s₁), vertices(s₂))) |
This file contains 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 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