comparison 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
comparison
equal deleted inserted replaced
1966:478b233999c5 1967:669361a8195a
27 27
28 28
29 struct LineSegment{PT} 29 struct LineSegment{PT}
30 a::PT 30 a::PT
31 b::PT 31 b::PT
32
33 LineSegment{PT}(p::PT, tangent::PT) where PT = new{PT}(p,tangent)
34 end
35
36 function LineSegment(a, b)
37 S = length(a)
38 T = promote_type(eltype(a), eltype(b))
39
40 PT = SVector{S,T}
41 return LineSegment{PT}(
42 convert(PT, a),
43 convert(PT, b),
44 )
45 end
46
47 function LineSegment(a::Tuple, b::Tuple)
48 a = promote(a...)
49 b = promote(b...)
50
51 return LineSegment(SVector(a), SVector(b))
32 end 52 end
33 53
34 (c::LineSegment)(s) = (1-s)*c.a + s*c.b 54 (c::LineSegment)(s) = (1-s)*c.a + s*c.b
35 55
36 56