Package primitives

Class Ray

java.lang.Object
primitives.LineSegment
primitives.Ray

public class Ray
extends LineSegment
The Ray class represents a ray with it's base at the Point 'source' and shoots off in direction pointed at by NonZeroVector 'direction'.
  • Field Summary

    Fields inherited from class primitives.LineSegment

    direction, inverse, squareLength, start
  • Constructor Summary

    Constructors
    Constructor Description
    Ray​(Point start, NormalizedVector direction)
    Constructs a Ray from a source Point and a direction NonZeroVector.
  • Method Summary

    Modifier and Type Method Description
    Intersection closest​(java.util.List<Intersection> intersections)
    Returns the closest intersection to this ray's source from the given intersections.
    boolean equals​(java.lang.Object o)
    Compares the source and direction of the two Rays.
    int hashCode()
    Computes the hash code based on that of the source Point and the direction NonZeroVector.
    java.lang.String toString()
    Returns a string representing the source and direction as a tuple.
    protected boolean withinDistance​(double distance)
    Returns whether or not some given distance traveled from the start along the direction is within the length of the line segment.

    Methods inherited from class primitives.LineSegment

    travel

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • closest

      public Intersection closest​(java.util.List<Intersection> intersections)
      Returns the closest intersection to this ray's source from the given intersections.
      Parameters:
      intersections - The intersections from which to get the closest one.
      Returns:
      The closest intersection to the source of the ray.
      Throws:
      java.util.NoSuchElementException - if the list is empty.
    • withinDistance

      protected boolean withinDistance​(double distance)
      Description copied from class: LineSegment
      Returns whether or not some given distance traveled from the start along the direction is within the length of the line segment.
      Overrides:
      withinDistance in class LineSegment
      Parameters:
      distance - The distance traveled from the start along the direction.
      Returns:
      whether or not the distance squared is less than squareDistance.
    • equals

      public boolean equals​(java.lang.Object o)
      Compares the source and direction of the two Rays.
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Computes the hash code based on that of the source Point and the direction NonZeroVector.
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Returns a string representing the source and direction as a tuple.
      Overrides:
      toString in class java.lang.Object