package renderer.primitive;

import basics.math.algebra.Ray;
import basics.math.algebra.Vector;

public class Plane implements Primitive {

    private double offset;
    private Vector normal;

    public Plane(Vector normal, double offset) {
        this.offset = offset;
        this.normal = normal;
    }

    @Override
    public double intersect(Ray ray) {
        return -(ray.getOrigin().dot(normal) + offset) / ray.getDirection().dot(normal);
    }

    @Override
    public Vector normalAt(Vector surfacePoint, Vector incoming) {
        return normal.scale(-Math.signum(normal.dot(incoming)));
    }
}
