Class LineInterpolator
java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.solidpolygon.LineInterpolator
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintbooleancontainsY(int y) Tests whether the given y coordinate falls within the vertical span of this edge.booleanintgetX(int y) Computes the interpolated x coordinate for the given scanline y value.inthashCode()voidSets the two endpoints of this edge and precomputes the width, height, and absolute height.
-
Constructor Details
-
LineInterpolator
public LineInterpolator()
-
-
Method Details
-
equals
-
compareTo
- Specified by:
compareToin interfaceComparable<LineInterpolator>
-
hashCode
public int hashCode() -
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:
trueifyis 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
Sets the two endpoints of this edge and precomputes the width, height, and absolute height.- Parameters:
p1- the first endpointp2- the second endpoint
-