Skip to content

Commit

Permalink
Bug in intersection test was fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Nov 9, 2017
1 parent 0b1b428 commit 67b30a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
main
*.coverprofile
*.jpg
*.prof
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ all:
go build ./...

run:
export GOPATH=`pwd`
go build ./src/main.go && ./main

test:
Expand Down
11 changes: 11 additions & 0 deletions src/core/bounds3d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ func TestBounds3dIntersect(t *testing.T) {
t.Errorf("Failed: %f vs %f", tMin, 0.5)
}
}

func TestMaxExtent(t *testing.T) {
b1 := Bounds3d{
MinPos: Vector3d{1.0, 2.0, 3.0},
MaxPos: Vector3d{2.0, 4.0, 6.0},
}

if b1.MaxExtent() != 2 {
t.Error("Max extent test is failed!")
}
}
8 changes: 4 additions & 4 deletions src/shape/triangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func (t *Triangle) Intersect(ray *Ray, isect *Intersection) bool {
func (t *Triangle) Bounds() Bounds3d {
b := NewBounds3d()
b.MinPos.X = math.Min(t.Points[0].X, math.Min(t.Points[1].X, t.Points[2].X))
b.MinPos.X = math.Min(t.Points[0].Y, math.Min(t.Points[1].Y, t.Points[2].Y))
b.MinPos.X = math.Min(t.Points[0].Z, math.Min(t.Points[1].Z, t.Points[2].Z))
b.MinPos.Y = math.Min(t.Points[0].Y, math.Min(t.Points[1].Y, t.Points[2].Y))
b.MinPos.Z = math.Min(t.Points[0].Z, math.Min(t.Points[1].Z, t.Points[2].Z))
b.MaxPos.X = math.Max(t.Points[0].X, math.Max(t.Points[1].X, t.Points[2].X))
b.MaxPos.X = math.Max(t.Points[0].Y, math.Max(t.Points[1].Y, t.Points[2].Y))
b.MaxPos.X = math.Max(t.Points[0].Z, math.Max(t.Points[1].Z, t.Points[2].Z))
b.MaxPos.Y = math.Max(t.Points[0].Y, math.Max(t.Points[1].Y, t.Points[2].Y))
b.MaxPos.Z = math.Max(t.Points[0].Z, math.Max(t.Points[1].Z, t.Points[2].Z))
return b
}

0 comments on commit 67b30a3

Please sign in to comment.