changeset 2011:d0b6c63c506e feature/grids/geometry_functions

Add Arc type for representing partial circles
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 07 May 2025 08:38:35 +0200
parents cf0fa2967361
children 4617e4b74b82
files src/Grids/geometry.jl test/Grids/geometry_test.jl
diffstat 2 files changed, 46 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/geometry.jl	Thu May 01 17:25:24 2025 +0200
+++ b/src/Grids/geometry.jl	Wed May 07 08:38:35 2025 +0200
@@ -155,6 +155,32 @@
     r*@SVector[-sin(θ), cos(θ)]
 end
 
+struct Arc{PT,T}
+    c::Circle{PT,T}
+    θ₀::T
+    θ₁::T
+end
+
+"""
+    Arc(C::Circle, θ₀, θ₁)
+
+# TODO
+"""
+function Arc(C, θ₀, θ₁)
+    r, θ₀, θ₁ = promote(C.r, θ₀, θ₁)
+
+    return Arc(Circle(C.c, r), θ₀, θ₁)
+end
+
+function (A::Arc)(t)
+    (; θ₀, θ₁) = A
+    return A.c((1-t)*θ₀ + t*θ₁)
+end
+
+function Grids.jacobian(a::Arc, t)
+    return nothing
+end
+
 """
     TransfiniteInterpolationSurface(c₁, c₂, c₃, c₄)
 
--- a/test/Grids/geometry_test.jl	Thu May 01 17:25:24 2025 +0200
+++ b/test/Grids/geometry_test.jl	Wed May 07 08:38:35 2025 +0200
@@ -1,5 +1,5 @@
 using Diffinitive.Grids
-using Diffinitive.Grids: Line, LineSegment, linesegments, polygon_edges, Circle, TransfiniteInterpolationSurface, check_transfiniteinterpolation
+using Diffinitive.Grids: Line, LineSegment, linesegments, polygon_edges, Circle, TransfiniteInterpolationSurface, check_transfiniteinterpolation, arc, Arc
 using StaticArrays
 
 @testset "Line" begin
@@ -162,6 +162,25 @@
     end
 end
 
+@testset "Arc" begin
+    @test Arc(Circle([0,0], 1), 0, 1) isa Arc{SVector{2,Int}, Int}
+    @test Arc(Circle([0,0], 1.), 0, 1) isa Arc{SVector{2,Int}, Float64}
+    @test Arc(Circle([1., 1.], 1), 0., 1.) isa Arc{SVector{2,Float64}, Float64}
+    @test Arc(Circle([1., 1.], 1), 0, 1) isa Arc{SVector{2,Float64}, Int}
+    @test Arc(Circle([1., 1.], 1), 0, 1.) isa Arc{SVector{2,Float64}, Float64}
+
+    a = Arc(Circle([0,0], 1), 0, π/2)
+    @test a(0) ≈ [1,0]
+    @test a(1/3) ≈ [√(3)/2,1/2]
+    @test a(1/2) ≈ [1/√(2),1/√(2)]
+    @test a(2/3) ≈ [1/2, √(3)/2]
+    @test a(1) ≈ [0,1]
+
+    @testset "Grids.jacobian" begin
+        @test_broken false
+    end
+end
+
 @testset "TransfiniteInterpolationSurface" begin
     @testset "Constructors" begin
         @test TransfiniteInterpolationSurface(t->[1,2], t->[2,1], t->[0,0], t->[1,1]) isa TransfiniteInterpolationSurface