-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
185 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
align = more // For pretty alignment. | ||
maxColumn = 100 // For my wide 30" display. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (C) 2019 James McMurray | ||
// | ||
// raytracer_challenge is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// raytracer_challenge is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with raytracer_challenge If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package raytracer | ||
|
||
class Plane(val transform: Matrix, val material: Material) extends SpaceObject { | ||
type T = Plane | ||
|
||
def constructor(t: Matrix, m: Material): T = new Plane(t, m) | ||
|
||
final override def equals(that: Any): Boolean = { | ||
that match { | ||
case that: Plane => transform === that.transform && material === that.material | ||
case _ => false | ||
} | ||
} | ||
|
||
final def ===(that: Plane): Boolean = { | ||
transform === that.transform && material === that.material | ||
} | ||
|
||
final override def hashCode: Int = (transform, material).## | ||
|
||
|
||
def localIntersect(r: Ray): Seq[Intersection] = { | ||
if (math.abs(r.direction.y) < EPSILON) (List[Intersection]()) else { | ||
val t: Double = -r.origin.y / r.direction.y | ||
List(new Intersection(t, this)) | ||
} | ||
} | ||
|
||
|
||
def localNormalAt(p: RTTuple): RTTuple = { | ||
Vector(0, 1, 0) | ||
} | ||
} | ||
|
||
|
||
object Plane { | ||
def apply(): Plane = new Plane(Matrix.getIdentityMatrix(4), Material.defaultMaterial()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (C) 2019 James McMurray | ||
// | ||
// raytracer_challenge is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// raytracer_challenge is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with raytracer_challenge If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package raytracer | ||
|
||
import org.scalatest.FunSuite | ||
|
||
class PlaneTest extends FunSuite { | ||
test("Plane.test_normal") { | ||
val p: Plane = Plane() | ||
val n1: RTTuple = p.localNormalAt(Point(0, 0, 0)) | ||
val n2: RTTuple = p.localNormalAt(Point(10, 0, -10)) | ||
val n3: RTTuple = p.localNormalAt(Point(-5, 0, 150)) | ||
assert(n1 === Vector(0, 1, 0) && n2 === Vector(0, 1, 0) && | ||
n3 === Vector(0, 1, 0)) | ||
} | ||
|
||
test("Plane.test_parallel") { | ||
val p: Plane = Plane() | ||
val r: Ray = Ray(Point(0, 10, 0), Vector(0, 0, 1)) | ||
|
||
val xs: Seq[Intersection] = p.localIntersect(r) | ||
assert(xs.isEmpty) | ||
} | ||
test("Plane.test_coplanar") { | ||
val p: Plane = Plane() | ||
val r: Ray = Ray(Point(0, 0, 0), Vector(0, 0, 1)) | ||
|
||
val xs: Seq[Intersection] = p.localIntersect(r) | ||
assert(xs.isEmpty) | ||
} | ||
test("Plane.test_intersect_above") { | ||
val p: Plane = Plane() | ||
val r: Ray = Ray(Point(0, 1, 0), Vector(0, -1, 0)) | ||
|
||
val xs: Seq[Intersection] = p.localIntersect(r) | ||
assert(xs.length === 1 && xs(0).t === 1 && xs(0).shape === p) | ||
} | ||
test("Plane.test_intersect_below") { | ||
val p: Plane = Plane() | ||
val r: Ray = Ray(Point(0, -1, 0), Vector(0, 1, 0)) | ||
|
||
val xs: Seq[Intersection] = p.localIntersect(r) | ||
assert(xs.length === 1 && xs(0).t === 1 && xs(0).shape === p) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters