diff src/Grids/geometry.jl @ 1966:478b233999c5 feature/grids/geometry_functions

Add tests and better constructors for Line
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 12 Feb 2025 15:33:48 +0100
parents 6859089b361e
children 669361a8195a
line wrap: on
line diff
--- a/src/Grids/geometry.jl	Wed Feb 12 15:30:47 2025 +0100
+++ b/src/Grids/geometry.jl	Wed Feb 12 15:33:48 2025 +0100
@@ -1,6 +1,26 @@
 struct Line{PT}
     p::PT
     tangent::PT
+
+    Line{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent)
+end
+
+function Line(p, t)
+    S = length(p)
+    T = promote_type(eltype(p), eltype(t))
+
+    PT = SVector{S,T}
+    return Line{PT}(
+        convert(PT, p),
+        convert(PT, t),
+    )
+end
+
+function Line(p::Tuple, t::Tuple)
+    p = promote(p...)
+    t = promote(t...)
+
+    return Line(SVector(p), SVector(t))
 end
 
 (c::Line)(s) = c.p + s*c.tangent