Compare commits
No commits in common. "ac4f5eb9a6c1245c08e3f1c213251170ce887601" and "e430e3769efd691c1494e921fbaadd2743bcc693" have entirely different histories.
ac4f5eb9a6
...
e430e3769e
@ -1,8 +0,0 @@
|
||||
# Installing
|
||||
Symlink the files in this directory into your `.git/hooks/` directory to
|
||||
enable policies for this project. Example:
|
||||
|
||||
```bash
|
||||
$ cd .git/hooks
|
||||
$ ln -s ../../git-hooks/pre-commit .
|
||||
```
|
||||
@ -1,26 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
pushd () {
|
||||
command pushd "$@" > /dev/null
|
||||
}
|
||||
|
||||
popd () {
|
||||
command popd "$@" > /dev/null
|
||||
}
|
||||
|
||||
for workspace in rtchallenge rtiow; do
|
||||
pushd ${workspace:?}
|
||||
cargo fmt -- --check || (echo "To fix, run: cd ${workspace:?} && cargo fmt" && false)
|
||||
popd
|
||||
done
|
||||
|
||||
RT=rtchallenge
|
||||
AFFECTED="$(git diff-index --cached --name-only HEAD)"
|
||||
#echo "AFFECTED $AFFECTED"
|
||||
RT_AFFECTED=$(echo "${AFFECTED:?}" | grep ${RT:?} || true)
|
||||
if [ ! -z "$RT_AFFECTED" ]; then
|
||||
echo "Files for the rt challenge were touched, running tests"
|
||||
cd ${RT:?} && cargo build --examples && cargo test
|
||||
fi
|
||||
# Uncomment to debug presubmit.
|
||||
#exit 1
|
||||
@ -3,7 +3,6 @@ use crate::{
|
||||
matrices::Matrix4x4,
|
||||
rays::Ray,
|
||||
tuples::{dot, Tuple},
|
||||
EPSILON,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -35,65 +34,6 @@ impl Default for Sphere {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sphere {
|
||||
/// Find the normal at the point on the sphere.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::{matrices::Matrix4x4, spheres::Sphere, tuples::Tuple};
|
||||
///
|
||||
/// // Normal on X-axis
|
||||
/// let s = Sphere::default();
|
||||
/// let n = s.normal_at(Tuple::point(1., 0., 0.));
|
||||
/// assert_eq!(n, Tuple::vector(1., 0., 0.));
|
||||
///
|
||||
/// // Normal on Y-axis
|
||||
/// let s = Sphere::default();
|
||||
/// let n = s.normal_at(Tuple::point(0., 1., 0.));
|
||||
/// assert_eq!(n, Tuple::vector(0., 1., 0.));
|
||||
///
|
||||
/// // Normal on Z-axis
|
||||
/// let s = Sphere::default();
|
||||
/// let n = s.normal_at(Tuple::point(0., 0., 1.));
|
||||
/// assert_eq!(n, Tuple::vector(0., 0., 1.));
|
||||
///
|
||||
/// // Normal on a sphere at a nonaxial point.
|
||||
/// let s = Sphere::default();
|
||||
/// let n = s.normal_at(Tuple::point(
|
||||
/// 3_f32.sqrt() / 3.,
|
||||
/// 3_f32.sqrt() / 3.,
|
||||
/// 3_f32.sqrt() / 3.,
|
||||
/// ));
|
||||
/// assert_eq!(
|
||||
/// n,
|
||||
/// Tuple::vector(3_f32.sqrt() / 3., 3_f32.sqrt() / 3., 3_f32.sqrt() / 3.,)
|
||||
/// );
|
||||
/// // Normals returned are normalized.
|
||||
/// let s = Sphere::default();
|
||||
/// let n = s.normal_at(Tuple::point(
|
||||
/// 3_f32.sqrt() / 3.,
|
||||
/// 3_f32.sqrt() / 3.,
|
||||
/// 3_f32.sqrt() / 3.,
|
||||
/// ));
|
||||
/// assert_eq!(n, n.normalize());
|
||||
/// ```
|
||||
/// ```should_panic
|
||||
/// use rtchallenge::{spheres::Sphere, tuples::Tuple};
|
||||
///
|
||||
/// // In debug builds points not on the sphere should fail.
|
||||
/// let s = Sphere::default();
|
||||
/// let n = s.normal_at(Tuple::point(0., 0., 0.5));
|
||||
/// ```
|
||||
pub fn normal_at(&self, point: Tuple) -> Tuple {
|
||||
debug_assert!(
|
||||
((point - Tuple::point(0., 0., 0.)).magnitude() - 1.).abs() < EPSILON,
|
||||
"{} != 1.",
|
||||
(point - Tuple::point(0., 0., 0.)).magnitude()
|
||||
);
|
||||
(point - Tuple::point(0., 0., 0.)).normalize()
|
||||
}
|
||||
}
|
||||
|
||||
/// Intersect a ray with a sphere.
|
||||
///
|
||||
/// # Examples
|
||||
|
||||
@ -34,7 +34,6 @@ impl Tuple {
|
||||
pub fn magnitude(&self) -> f32 {
|
||||
(self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w).sqrt()
|
||||
}
|
||||
|
||||
pub fn normalize(&self) -> Tuple {
|
||||
let m = self.magnitude();
|
||||
Tuple {
|
||||
|
||||
@ -19,7 +19,7 @@ impl EnvMap {
|
||||
}
|
||||
pub fn color(&self, ray: Vec3) -> Vec3 {
|
||||
let zero = Vec3::new(0., 0., 0.);
|
||||
let u = ray.x.atan2(ray.z) / f32::consts::PI / 2.0 + 0.5;
|
||||
let u = ray.x.atan2(ray.z) / f32::consts::PI /2.0 + 0.5;
|
||||
let v = ray.y / 2.0 + 0.5;
|
||||
self.img_tex.value(u, v, zero)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user