Mercurial > repos > public > sbplib_julia
diff src/Grids/geometry.jl @ 1967:669361a8195a feature/grids/geometry_functions
Add tests and better constructors for LineSegment
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 12 Feb 2025 15:40:19 +0100 |
parents | 478b233999c5 |
children | 7f4a5146c84c |
line wrap: on
line diff
--- a/src/Grids/geometry.jl Wed Feb 12 15:33:48 2025 +0100 +++ b/src/Grids/geometry.jl Wed Feb 12 15:40:19 2025 +0100 @@ -29,6 +29,26 @@ struct LineSegment{PT} a::PT b::PT + + LineSegment{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent) +end + +function LineSegment(a, b) + S = length(a) + T = promote_type(eltype(a), eltype(b)) + + PT = SVector{S,T} + return LineSegment{PT}( + convert(PT, a), + convert(PT, b), + ) +end + +function LineSegment(a::Tuple, b::Tuple) + a = promote(a...) + b = promote(b...) + + return LineSegment(SVector(a), SVector(b)) end (c::LineSegment)(s) = (1-s)*c.a + s*c.b