Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
NickyMateev committed Nov 21, 2018
1 parent ad0913a commit 0b099a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Homework3/solution.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
)

const Episilon = 1e-7
const epsilon = 1e-7

type Triangle struct {
a, b, c geom.Vector
Expand Down Expand Up @@ -53,7 +53,7 @@ func (triangle Triangle) Intersect(ray geom.Ray) bool {
h := geom.Cross(ray.Direction, edge2)

det := geom.Dot(edge1, h)
if det > -Episilon && det < Episilon {
if det > -epsilon && det < epsilon {
return false // The ray is parallel to triangle plane, impossible that they intersect
}

Expand All @@ -78,7 +78,7 @@ func (triangle Triangle) Intersect(ray geom.Ray) bool {

// Calculating t - final check to see if ray intersects triangle
t := f * geom.Dot(edge2, q)
if t > Episilon {
if t > epsilon {
return true
}

Expand Down
22 changes: 17 additions & 5 deletions Homework3/solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ func TestSampleSimpleTriangle(t *testing.T) {
}
}

func TestSampleSimpleSphere(t *testing.T) {
func TestSampleSimpleTriangleBoundaryIntersectionShouldIntersect(t *testing.T) {
var prim geom.Intersectable

a, b, c := geom.NewVector(0, -2, 0), geom.NewVector(3, 0, 0), geom.NewVector(0, 1, 0)
prim = NewTriangle(a, b, c)
ray := geom.NewRay(geom.NewVector(0, 0, 3), geom.NewVector(0, 0, -2))

if !prim.Intersect(ray) {
t.Errorf("Expected ray %#v to intersect triangle %#v but it did not.", ray, prim)
}
}

func TestSampleSimpleSphereShouldIntersect(t *testing.T) {
var prim geom.Intersectable

origin, r := geom.NewVector(0, 0, 0), 2.0
Expand All @@ -30,10 +42,10 @@ func TestSampleSimpleSphere(t *testing.T) {
}
}

func TestSampleSimpleQuadConvex(t *testing.T) {
func TestSampleSimpleQuadConvexShouldIntersect(t *testing.T) {
var prim geom.Intersectable

a, b, c, d := geom.NewVector(0, -2, 0), geom.NewVector(3, 0, 0), geom.NewVector(0, 1, 0), geom.Vector{-1, 0, 0}
a, b, c, d := geom.NewVector(0, -2, 0), geom.NewVector(3, 0, 0), geom.NewVector(0, 1, 0), geom.NewVector(-1, 0, 0)
prim = NewQuad(a, b, c, d)
ray := geom.NewRay(geom.NewVector(0, 0, 2), geom.NewVector(0, 0, -1))

Expand All @@ -45,12 +57,12 @@ func TestSampleSimpleQuadConvex(t *testing.T) {
func TestSampleSimpleQuadConcaveShouldNotIntersect(t *testing.T) {
var prim geom.Intersectable

a, b, c, d := geom.NewVector(0, -2, 0), geom.NewVector(3, 0, 0), geom.NewVector(0, 1, 0), geom.Vector{1, 0, 0}
a, b, c, d := geom.NewVector(0, -2, 0), geom.NewVector(3, 0, 0), geom.NewVector(0, 1, 0), geom.NewVector(1, 0, 0)
prim = NewQuad(a, b, c, d)
ray := geom.NewRay(geom.NewVector(0, 0, 2), geom.NewVector(0, 0, -1))

if prim.Intersect(ray) {
t.Errorf("Expected ray %#v to intersect quad %#v but it did not.", ray, prim)
t.Errorf("Expected ray %#v to not intersect quad %#v but it did.", ray, prim)
}
}

Expand Down

0 comments on commit 0b099a3

Please sign in to comment.