From 33108fe0e3366dbcb8515edc527bfb241f25292a Mon Sep 17 00:00:00 2001 From: AndreasHassing Date: Fri, 20 May 2016 18:49:47 +0200 Subject: [PATCH] Add infix operator for transform --- src/Ray/Ray.fs | 11 ++++++++++- src/Ray/Ray.fsi | 11 ++++++++++- src/Ray/project.json | 2 +- test/Ray.Test/RayTest.fs | 12 ++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Ray/Ray.fs b/src/Ray/Ray.fs index bb41a2f..e814454 100644 --- a/src/Ray/Ray.fs +++ b/src/Ray/Ray.fs @@ -35,10 +35,19 @@ let getOrigin (R(o, _)) = o let getVector (R(_, d)) = d /// -/// Transform the ray with some transformation. +/// Transform a ray with a transformation. /// /// The ray to transform. /// The transformation to apply to the ray. /// The transformed ray. let transform (R(o, d)) (t:Transformation) = R(o * t, d * t) + +type Ray with + /// + /// Transform a ray with a transformation. + /// + /// The ray to transform. + /// The transformation to apply to the ray. + /// The transformed ray. + static member (*) (r, t) = transform r t diff --git a/src/Ray/Ray.fsi b/src/Ray/Ray.fsi index b35473f..701b5fb 100644 --- a/src/Ray/Ray.fsi +++ b/src/Ray/Ray.fsi @@ -5,7 +5,16 @@ open Point open Transform open Vector -type Ray +[] +[] +type Ray = + /// + /// Transform a ray with a transformation. + /// + /// The ray to transform. + /// The transformation to apply to the ray. + /// The transformed ray. + static member (*) : r:Ray * t:Transformation -> Ray /// /// Create a ray; a normalized vector with a point of origin. diff --git a/src/Ray/project.json b/src/Ray/project.json index ddb7479..9c94ac7 100644 --- a/src/Ray/project.json +++ b/src/Ray/project.json @@ -1,5 +1,5 @@ { - "version": "0.1.0", + "version": "0.2.0", "description": "A library for modelling 3-dimensional rays of light", "authors": [ "Andreas Bjørn Hassing Nielsen " diff --git a/test/Ray.Test/RayTest.fs b/test/Ray.Test/RayTest.fs index a4bb64d..c5f4afb 100755 --- a/test/Ray.Test/RayTest.fs +++ b/test/Ray.Test/RayTest.fs @@ -45,6 +45,18 @@ let ``transform transforms a ray with the appropriate transformation`` () = Ray.getOrigin tr |> should equal (Point.make -1. 1. 1.) Ray.getVector tr |> should equal tv +[] +let ``transform transforms a ray with the appropriate transformation, using the static member`` () = + let p = Point.make 1. 1. 1. + let v = Vector.make -1. -1. -1. + let r = Ray.make p v + let tr = r * (Transform.mirror Transform.Axis.X) + + let tv = (Vector.normalise v) * (Transform.mirror Transform.Axis.X) + + Ray.getOrigin tr |> should equal (Point.make -1. 1. 1.) + Ray.getVector tr |> should equal tv + [] let ``transform with an empty matrix does nothing to the ray`` () = let p = Point.make 1. 1. 1.