Skip to content

Commit

Permalink
Fix "Change name from 'inverse' to 'inv'" #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuele-Colombo committed May 25, 2021
1 parent d3fa232 commit 57a9ced
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Raytracer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import Base:
size, zero, one, fill!, eltype,
length, firstindex, lastindex, getindex, setindex!, iterate, axes,
show, write,
readline, read
readline, read,
inv
import Base.Broadcast:
BroadcastStyle, Style, Broadcasted, combine_eltypes,
broadcastable, copy, similar
Expand All @@ -46,7 +47,7 @@ export
Vec, Point, Normal, Transformation, Vec2D,
rotationX, rotationY, rotationZ,
translation, scaling,
isconsistent, inverse,
isconsistent,
Ray, OrthogonalCamera, PerspectiveCamera,
fire_ray, aperture_deg,
ImageTracer, fire_all_rays,
Expand Down
6 changes: 3 additions & 3 deletions src/geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function (*)(t ::Transformation, p ::Point)
end

"""
inverse(t)
inv(t)
Return the inverse [`Transformation`](@ref).
Expand All @@ -269,7 +269,7 @@ Inverse matrix of type Diagonal{Float64, Vector{Float64}}:
⋅ ⋅ 0.3333333333333333 ⋅
⋅ ⋅ ⋅ 1.0
julia> inverse(t)
julia> inv(t)
4x4 Transformation{Float64}:
Matrix of type Diagonal{Float64, Vector{Float64}}:
1.0 ⋅ ⋅ ⋅
Expand All @@ -283,7 +283,7 @@ Inverse matrix of type Diagonal{Int64, Vector{Int64}}:
⋅ ⋅ ⋅ 1
```
"""
inverse(t::Transformation) = Transformation(t.invm, t.m)
inv(t::Transformation) = Transformation(t.invm, t.m)

let rotation_matrices = Dict(
:X => :(@SMatrix([ 1 0 0 0;
Expand Down
4 changes: 2 additions & 2 deletions src/shape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if none exists, return `nothing`.
""" ray_intersection

function ray_intersection(ray::Ray, s::Sphere)
inv_ray = inverse(s.transformation) * ray
inv_ray = inv(s.transformation) * ray
O⃗ = inv_ray.origin - ORIGIN
scalprod = O⃗ inv_ray.dir
# Δ/4 where Δ is the discriminant of the intersection system solution
Expand Down Expand Up @@ -124,7 +124,7 @@ Base.@kwdef struct Plane <: Shape
end

function ray_intersection(ray::Ray, s::Plane)
inv_ray = inverse(s.transformation) * ray
inv_ray = inv(s.transformation) * ray
dz = inv_ray.dir.z
t = -inv_ray.origin.v[3]/dz
inv_ray.tmin < t < inv_ray.tmax || return nothing
Expand Down
6 changes: 3 additions & 3 deletions test/test_geometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ end

@testset "methods" begin
t = t1 * t2
invt = inverse(t)
invt = inv(t)
@test t.m == invt.invm && t.invm == invt.m

θ = π/4
Expand Down Expand Up @@ -287,7 +287,7 @@ end
@test expected_n (m * Normal(3.0, 2.0, 4.0))
end

@testset "inverse" begin
@testset "inv" begin
m1 = Transformation([1.0 2.0 3.0 4.0;
5.0 6.0 7.0 8.0;
9.0 9.0 8.0 7.0;
Expand All @@ -297,7 +297,7 @@ end
0.5 0.5 -1.0 1.0;
-1.375 0.875 0.0 -0.5])

m2 = inverse(m1)
m2 = inv(m1)
@test isconsistent(m1)

prod = m1 * m2
Expand Down

0 comments on commit 57a9ced

Please sign in to comment.