comparison src/Grids/geometry.jl @ 1916:6859089b361e feature/grids/geometry_functions

Remove abstract types for Curve and surface
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 03 Feb 2025 15:44:07 +0100
parents c003685d9926
children 478b233999c5
comparison
equal deleted inserted replaced
1915:c003685d9926 1916:6859089b361e
1 ### 1 struct Line{PT}
2 # Geometry
3 ###
4
5 abstract type Curve end
6 abstract type Surface end
7
8
9 struct Line{PT} <: Curve
10 p::PT 2 p::PT
11 tangent::PT 3 tangent::PT
12 end 4 end
13 5
14 (c::Line)(s) = c.p + s*c.tangent 6 (c::Line)(s) = c.p + s*c.tangent
15 7
16 8
17 struct LineSegment{PT} <: Curve 9 struct LineSegment{PT}
18 a::PT 10 a::PT
19 b::PT 11 b::PT
20 end 12 end
21 13
22 (c::LineSegment)(s) = (1-s)*c.a + s*c.b 14 (c::LineSegment)(s) = (1-s)*c.a + s*c.b
30 function polygon_edges(ps...) 22 function polygon_edges(ps...)
31 n = length(ps) 23 n = length(ps)
32 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)] 24 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)]
33 end 25 end
34 26
35 struct Circle{T,PT} <: Curve 27 struct Circle{T,PT}
36 c::PT 28 c::PT
37 r::T 29 r::T
38 end 30 end
39 31
40 function (C::Circle)(θ) 32 function (C::Circle)(θ)
41 (;c, r) = C 33 (;c, r) = C
42 c + r*@SVector[cos(θ), sin(θ)] 34 c + r*@SVector[cos(θ), sin(θ)]
43 end 35 end
44 36
45 struct TransfiniteInterpolationSurface{T1,T2,T3,T4} <: Surface 37 struct TransfiniteInterpolationSurface{T1,T2,T3,T4}
46 c₁::T1 38 c₁::T1
47 c₂::T2 39 c₂::T2
48 c₃::T3 40 c₃::T3
49 c₄::T4 41 c₄::T4
50 end 42 end