Mercurial > repos > public > sbplib_julia
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 1965:eedb5d7b90b4 | 1966:478b233999c5 |
|---|---|
| 1 struct Line{PT} | 1 struct Line{PT} |
| 2 p::PT | 2 p::PT |
| 3 tangent::PT | 3 tangent::PT |
| 4 | |
| 5 Line{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent) | |
| 6 end | |
| 7 | |
| 8 function Line(p, t) | |
| 9 S = length(p) | |
| 10 T = promote_type(eltype(p), eltype(t)) | |
| 11 | |
| 12 PT = SVector{S,T} | |
| 13 return Line{PT}( | |
| 14 convert(PT, p), | |
| 15 convert(PT, t), | |
| 16 ) | |
| 17 end | |
| 18 | |
| 19 function Line(p::Tuple, t::Tuple) | |
| 20 p = promote(p...) | |
| 21 t = promote(t...) | |
| 22 | |
| 23 return Line(SVector(p), SVector(t)) | |
| 4 end | 24 end |
| 5 | 25 |
| 6 (c::Line)(s) = c.p + s*c.tangent | 26 (c::Line)(s) = c.p + s*c.tangent |
| 7 | 27 |
| 8 | 28 |
