Mercurial > repos > public > sbplib_julia
comparison src/Grids/geometry.jl @ 1969:7f4a5146c84c feature/grids/geometry_functions
Add tests and better constructor for Circle
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Fri, 14 Feb 2025 08:23:00 +0100 |
| parents | 669361a8195a |
| children | deeb61325320 |
comparison
equal
deleted
inserted
replaced
| 1968:35cb503985b6 | 1969:7f4a5146c84c |
|---|---|
| 62 function polygon_edges(ps...) | 62 function polygon_edges(ps...) |
| 63 n = length(ps) | 63 n = length(ps) |
| 64 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)] | 64 return [LineSegment(ps[i], ps[mod1(i+1,n)]) for i ∈ eachindex(ps)] |
| 65 end | 65 end |
| 66 | 66 |
| 67 struct Circle{T,PT} | 67 struct Circle{PT,T} |
| 68 c::PT | 68 c::PT |
| 69 r::T | 69 r::T |
| 70 | |
| 71 Circle{PT,T}(c,r) where {PT,T} = new{PT,T}(c,r) | |
| 72 end | |
| 73 | |
| 74 function Circle(c,r) | |
| 75 c = SVector{2}(c) | |
| 76 return Circle{typeof(c), typeof(r)}(c,r) | |
| 70 end | 77 end |
| 71 | 78 |
| 72 function (C::Circle)(θ) | 79 function (C::Circle)(θ) |
| 73 (;c, r) = C | 80 (;c, r) = C |
| 74 c + r*@SVector[cos(θ), sin(θ)] | 81 c + r*@SVector[cos(θ), sin(θ)] |
