changeset 1975:79adad4a15d6 feature/grids/geometry_functions

Implement Grids.jacobian for LineSegment
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 25 Feb 2025 22:42:14 +0100
parents 3ed7ca1f60c4
children 34a7e3919e9a
files src/Grids/geometry.jl test/Grids/geometry_test.jl
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/geometry.jl	Tue Feb 25 22:39:28 2025 +0100
+++ b/src/Grids/geometry.jl	Tue Feb 25 22:42:14 2025 +0100
@@ -34,6 +34,7 @@
 
 (c::LineSegment)(s) = (1-s)*c.a + s*c.b
 
+Grids.jacobian(c::LineSegment, s) = c.b - c.a
 
 function linesegments(ps...)
     return [LineSegment(ps[i], ps[i+1]) for i ∈ 1:length(ps)-1]
--- a/test/Grids/geometry_test.jl	Tue Feb 25 22:39:28 2025 +0100
+++ b/test/Grids/geometry_test.jl	Tue Feb 25 22:42:14 2025 +0100
@@ -50,6 +50,16 @@
         @test l(1) == [2,3]
         @test l(1/2) == [1,2]/2 + [2,3]/2
     end
+
+    @testset "Grids.jacobian" begin
+        a, b = [1,2], [2,3]
+        l = LineSegment(a,b)
+        d = b-a
+
+        @test Grids.jacobian(l,0) == d
+        @test Grids.jacobian(l,1) == d
+        @test Grids.jacobian(l,1/2) == d
+    end
 end
 
 @testset "linesegments" begin