package eu.jonahbauer.raytracing.scene.hittable3d;

import eu.jonahbauer.raytracing.math.Range;
import eu.jonahbauer.raytracing.math.Ray;
import eu.jonahbauer.raytracing.math.Vec3;
import eu.jonahbauer.raytracing.render.Color;
import eu.jonahbauer.raytracing.render.material.LambertianMaterial;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class SphereTest {

    @Test
    void hit() {
        var center = new Vec3(1, 2, 3);
        var radius = 5;
        var sphere = new Sphere(center, radius, new LambertianMaterial(Color.WHITE));

        var origin = new Vec3(6, 7, 8);
        var direction = new Vec3(-1, -1, -1);
        var ray = new Ray(origin, direction);

        var result = sphere.hit(ray, Range.NON_NEGATIVE);
        assertFalse(result.isEmpty());
        assertEquals(center.plus(new Vec3(1, 1, 1).unit().times(radius)), ray.at(result.get().t()));
    }
}