-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first implementation of reference shapes + tests
- Loading branch information
1 parent
bad3773
commit 5e3feee
Showing
9 changed files
with
175 additions
and
8 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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
name = "Inti" | ||
uuid = "fb74042b-437e-4c5b-88cf-d4e2beb394d5" | ||
authors = ["Luiz M. Faria"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
|
||
[compat] | ||
StaticArrays = "1" | ||
julia = "1.6" |
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,26 @@ | ||
#= | ||
Definition of basic geometrical concepts. | ||
=# | ||
|
||
|
||
""" | ||
ambient_dimension(x) | ||
Dimension of the ambient space where `x` lives. For geometrical objects this can | ||
differ from its [`geometric_dimension`](@ref); for example a triangle in `ℝ³` | ||
has ambient dimension `3` but geometric dimension `2`, while a curve in `ℝ³` has | ||
ambient dimension 3 but geometric dimension 1. | ||
""" | ||
function ambient_dimension end | ||
|
||
""" | ||
geometric_dimension(x) | ||
Number of independent coordinates needed to describe `x`. Lines have geometric | ||
dimension 1, triangles have geometric dimension 2, etc. | ||
""" | ||
function geometric_dimension end | ||
|
||
include("referenceshapes.jl") |
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,72 @@ | ||
""" | ||
abstract type AbstractReferenceShape | ||
A fixed reference domain/shape. Used mostly for defining more complex shapes as | ||
transformations mapping an `AbstractReferenceShape` to some region of `ℜᴹ`. | ||
See e.g. [`ReferenceLine`](@ref) or [`ReferenceTriangle`](@ref) for some | ||
examples of concrete subtypes. | ||
""" | ||
abstract type AbstractReferenceShape end | ||
|
||
""" | ||
struct ReferenceTriangle | ||
Singleton type representing the triangle with vertices `(0,0),(1,0),(0,1)` | ||
""" | ||
struct ReferenceTriangle <: AbstractReferenceShape end | ||
geometric_dimension(::ReferenceTriangle) = 2 | ||
ambient_dimension(::ReferenceTriangle) = 2 | ||
vertices(::ReferenceTriangle) = SVector(0, 0), SVector(1, 0), SVector(0, 1) | ||
Base.in(x, ::ReferenceTriangle) = 0 ≤ x[1] ≤ 1 && 0 ≤ x[2] ≤ 1 - x[1] | ||
center(::ReferenceTriangle) = svector(i -> 1 / 3, 3) | ||
|
||
""" | ||
struct ReferenceTetrahedron | ||
Singleton type representing the tetrahedron with vertices | ||
`(0,0,0),(0,0,1),(0,1,0),(1,0,0)` | ||
""" | ||
struct ReferenceTetrahedron <: AbstractReferenceShape end | ||
geometric_dimension(::ReferenceTetrahedron) = 3 | ||
ambient_dimension(::ReferenceTetrahedron) = 3 | ||
vertices(::ReferenceTetrahedron) = SVector(0, 0, 0), SVector(1, 0, 0), SVector(0, 1, 0), SVector(0, 0, 1) | ||
Base.in(x,::ReferenceTetrahedron) = 0 ≤ x[1] ≤ 1 && 0 ≤ x[2] ≤ 1 - x[1] && 0 ≤ x[3] ≤ 1 - x[1] - x[2] | ||
center(::ReferenceTetrahedron) = svector(i -> 1 / 4, 4) | ||
|
||
|
||
# TODO: generalize structs above to `ReferenceSimplex{N}` and | ||
|
||
""" | ||
struct ReferenceHyperCube{N} <: AbstractReferenceShape{N} | ||
Singleton type representing the axis-aligned hypercube in `N` dimensions with | ||
the lower corner at the origin and the upper corner at `(1,1,…,1)`. | ||
""" | ||
struct ReferenceHyperCube{N} <: AbstractReferenceShape end | ||
geometric_dimension(::ReferenceHyperCube{N}) where {N} = N | ||
ambient_dimension(::ReferenceHyperCube{N}) where {N} = N | ||
vertices(::ReferenceHyperCube{N}) where {N} = ntuple(i -> SVector(ntuple(j -> (i >> j) & 1, N)), 2^N) | ||
Base.in(x, ::ReferenceHyperCube{N}) where {N} = all(0 .≤ x .≤ 1) | ||
center(::ReferenceHyperCube{N}) where {N} = svector(i -> 0.5, N) | ||
|
||
""" | ||
const ReferenceLine = ReferenceHyperCube{1} | ||
Singleton type representing the `[0,1]` segment. | ||
""" | ||
const ReferenceLine = ReferenceHyperCube{1} | ||
|
||
""" | ||
const ReferenceSquare = ReferenceHyperCube{2} | ||
Singleton type representing the unit square `[0,1]²`. | ||
""" | ||
const ReferenceSquare = ReferenceHyperCube{2} | ||
|
||
""" | ||
const ReferenceCube = ReferenceHyperCube{3} | ||
Singleton type representing the unit cube `[0,1]³`. | ||
""" | ||
const ReferenceCube = ReferenceHyperCube{3} |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
module Inti | ||
|
||
# Write your package code here. | ||
const PROJECT_ROOT = pkgdir(Inti) | ||
|
||
using StaticArrays | ||
|
||
include("utils.jl") | ||
include("Geometry/Geometry.jl") | ||
|
||
|
||
end |
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,13 @@ | ||
#= | ||
Utility functions that have nowhere obvious to go. | ||
=# | ||
|
||
""" | ||
svector(f,n) | ||
Create an `SVector` of length n, computing each element as f(i), where i is the | ||
index of the element. | ||
""" | ||
svector(f,n)= ntuple(f,n) |> SVector | ||
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,37 @@ | ||
using Test | ||
import Inti | ||
using StaticArrays | ||
|
||
@testset "Line" begin | ||
l = Inti.ReferenceLine() | ||
@test Inti.ambient_dimension(l) == 1 | ||
@test Inti.geometric_dimension(l) == 1 | ||
x = SVector(0.5) | ||
@test x ∈ l | ||
x = SVector(1.0) | ||
@test x ∈ l | ||
x = SVector(1.1) | ||
@test !in(x, l) | ||
end | ||
@testset "Triangle" begin | ||
t = Inti.ReferenceTriangle() | ||
@test Inti.ambient_dimension(t) == 2 | ||
@test Inti.geometric_dimension(t) == 2 | ||
x = SVector(0.5, 0.5) | ||
@test x ∈ t | ||
x = SVector(1.0, 0.0) | ||
@test x ∈ t | ||
x = SVector(1.1, 0.0) | ||
@test !in(x, t) | ||
end | ||
@testset "Tetrahedron" begin | ||
t = Inti.ReferenceTetrahedron() | ||
@test Inti.ambient_dimension(t) == 3 | ||
@test Inti.geometric_dimension(t) == 3 | ||
x = SVector(0.5, 0.5, 0.0) | ||
@test x ∈ t | ||
x = SVector(1.0, 0.0, 0.0) # point on edge | ||
@test x ∈ t | ||
x = SVector(1.1, 0.0, 0.0) | ||
@test !in(x, t) | ||
end |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[deps] | ||
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
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,7 @@ | ||
using Inti | ||
using Test | ||
using Aqua | ||
|
||
@testset "Aqua" begin | ||
Aqua.test_all(Inti) | ||
end |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
using Inti | ||
using Test | ||
using SafeTestsets | ||
using Aqua | ||
|
||
@testset "Inti.jl" begin | ||
@testset "Code quality (Aqua.jl)" begin | ||
Aqua.test_all(Inti) | ||
end | ||
# Write your tests here. | ||
@safetestset "Code quality" begin | ||
include("aqua_test.jl") | ||
end | ||
|
||
@safetestset "Geometry" begin | ||
@safetestset "Reference shapes" include("Geometry/referenceshapes_test.jl") | ||
end |