java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.LineInterpolator
All Implemented Interfaces:
Comparable<LineInterpolator>

public class LineInterpolator extends Object implements Comparable<LineInterpolator>
Interpolates the x coordinate along a 2D line edge for scanline-based polygon rasterization.

LineInterpolator represents one edge of a polygon in screen space, defined by two Point2D endpoints. Given a scanline y coordinate, it computes the corresponding x coordinate via linear interpolation. This is a core building block for the solid polygon rasterizer, which fills triangles by sweeping horizontal scanlines and using two LineInterpolator instances to find the left and right x boundaries at each y level.

Instances are Comparable, sorted by absolute height (tallest first) and then by width. This ordering is used during rasterization to select the primary (longest) edge of the triangle for the outer scanline loop.

See Also:
  • Constructor Details

    • LineInterpolator

      public LineInterpolator()
  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(LineInterpolator o)
      Specified by:
      compareTo in interface Comparable<LineInterpolator>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • containsY

      public boolean containsY(int y)
      Tests whether the given y coordinate falls within the vertical span of this edge.
      Parameters:
      y - the scanline y coordinate to test
      Returns:
      true if y is between the y coordinates of the two endpoints (inclusive)
    • getX

      public int getX(int y)
      Computes the interpolated x coordinate for the given scanline y value.

      If the edge is horizontal (height is zero), returns the average of the two endpoint x coordinates.

      Parameters:
      y - the scanline y coordinate
      Returns:
      the interpolated x coordinate on this edge at the given y
    • setPoints

      public void setPoints(Point2D p1, Point2D p2)
      Sets the two endpoints of this edge and precomputes the width, height, and absolute height.
      Parameters:
      p1 - the first endpoint
      p2 - the second endpoint