diff src/Grids/manifolds.jl @ 1779:2a8a2b52a112 feature/grids/manifolds

Refactor Interval to its own type. This allows the user better control of the coordinate type of 1d grids
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 16 Sep 2024 08:33:43 +0200
parents e213bd857f3f
children 8ecdc5bb46be
line wrap: on
line diff
--- a/src/Grids/manifolds.jl	Sun Sep 15 23:27:04 2024 +0200
+++ b/src/Grids/manifolds.jl	Mon Sep 16 08:33:43 2024 +0200
@@ -21,6 +21,21 @@
 Base.ndims(::ParameterSpace{D}) where D = D
 # TBD:  Should implement domain_dim?
 
+struct Interval{T} <: ParameterSpace{1}
+    a::T
+    b::T
+
+    function Interval(a,b)
+        a, b = promote(a, b)
+        new{typeof(a)}(a,b)
+    end
+end
+
+limits(i::Interval) = (i.a, i.b)
+
+unitinterval(T=Float64) = Interval(zero(T), one(T))
+
+
 struct HyperBox{T,D} <: ParameterSpace{D}
     a::SVector{D,T}
     b::SVector{D,T}
@@ -31,14 +46,12 @@
     HyperBox(convert(T,a), convert(T,b))
 end
 
-Interval{T} = HyperBox{T,1}
 Rectangle{T} = HyperBox{T,2}
 Box{T} = HyperBox{T,3}
 
 limits(box::HyperBox, d) = (box.a[d], box.b[d])
 limits(box::HyperBox) = (box.a, box.b)
 
-unitinterval(T=Float64) = unithyperbox(T,1)
 unitsquare(T=Float64) = unithyperbox(T,2)
 unitcube(T=Float64) = unithyperbox(T,3)
 unithyperbox(T, D) = HyperBox((@SVector zeros(T,D)), (@SVector ones(T,D)))