changeset 2071:9e9c56f5a656 feature/grids/geometry_functions

Add parameter validation when calling a transfinite interpolation object
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 17 Feb 2026 20:37:53 +0100
parents c68fa6c74477
children c36812de3f2d
files src/Grids/geometry.jl test/Grids/geometry_test.jl
diffstat 2 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/geometry.jl	Tue Feb 17 20:25:13 2026 +0100
+++ b/src/Grids/geometry.jl	Tue Feb 17 20:37:53 2026 +0100
@@ -54,7 +54,7 @@
     LineSegment(a,b)
 
 A line segment, as a callable object, from `a` to `b`.
-The parametrization is ``l(s) = (1-s)a + s*b`` where ``s\in(0,1)``.
+The parametrization is ``l(s) = (1-s)a + s*b`` where ``s∈(0,1)``.
 
 # Example
 ```julia-repl
@@ -250,6 +250,9 @@
 end
 
 function (s::TransfiniteInterpolationSurface)(u,v)
+    if (u,v) ∉ unitsquare()
+        throw(DomainError((u,v), "Transfinite interpolation was called with parameters outside the unit square."))
+    end
     c₁, c₂, c₃, c₄ = s.c₁, s.c₂, s.c₃, s.c₄
     P₀₀ = c₁(0)
     P₁₀ = c₂(0)
--- a/test/Grids/geometry_test.jl	Tue Feb 17 20:25:13 2026 +0100
+++ b/test/Grids/geometry_test.jl	Tue Feb 17 20:37:53 2026 +0100
@@ -321,6 +321,14 @@
         @test ti(1/2, 1) == (c+d)/2
         @test ti(0, 1/2) == (a+d)/2
         @test ti(1, 1/2) == (b+c)/2
+
+        @testset "Out of domain error" begin
+            @test_throws DomainError ti(-0.1, 0)
+            @test_throws DomainError ti(1.1, 0)
+            @test_throws DomainError ti(0, -0.1)
+            @test_throws DomainError ti(0, 1.1)
+            @test_throws DomainError ti(1.1, -0.1)
+        end
     end
 
     @testset "check_transfiniteinterpolation" begin