import numpy as np

from plane import Plane
from ray import Ray
from vector import Vector


def test_plane():
  p = Plane(
    Vector.fromargs(0, 0, 0),
    Vector.fromargs(0, 0, 1),
  )
  assert (p & Vector.fromargs(0, 0, 0))
  assert (p & Vector.fromargs(1, 1, 0))
  assert not (p & Vector.fromargs(0, 0, -1))

  p = Plane(
    Vector.fromargs(1, 1),
    Vector.fromargs(1, 1),
  )

  assert not (p & Vector.fromargs(0, 0))
  assert (p & Vector.fromargs(2, 0))


def test_reflection():
  p = Plane(
    Vector.fromargs(0, 0),
    Vector.fromargs(0, 1),
  )

  r = Ray(
    Vector.fromargs(-1, 1),
    Vector.fromargs(1, -1),
  )

  assert p.intersect(r) == np.sqrt(2)
