public class Line extends AbstractCoordinateShape
A 3D line segment with perspective-correct width and alpha blending.

This class represents a line between two 3D points, rendered with a specified width that adjusts based on perspective (distance from the viewer). The line is drawn using interpolators to handle edge cases and alpha blending for transparency effects.

The rendering algorithm: 1. For thin lines (below a threshold), draws single-pixel lines with alpha adjustment based on perspective. 2. For thicker lines, creates four interpolators to define the line's rectangular area and fills it scanline by scanline.

Note: The width is scaled by the LINE_WIDTH_MULTIPLIER and adjusted based on the distance from the viewer (z-coordinate) to maintain a consistent visual size.

  • Field Details

    • width

      public final double width
      width of the line.
    • color

      public Color color
      Color of the line.
  • Constructor Details

    • Line

      public Line(Line parentLine)
      Creates a copy of an existing line with cloned coordinates and color.
      Parameters:
      parentLine - the line to copy
    • Line

      public Line(Point3D point1, Point3D point2, Color color, double width)
      Creates a line between two points with the specified color and width.
      Parameters:
      point1 - the starting point of the line
      point2 - the ending point of the line
      color - the color of the line
      width - the width of the line in world units
  • Method Details

    • getScreenYMargin

      protected double getScreenYMargin(RenderingContext renderingContext)
      The thick-line path widens the line perpendicular to its direction by the projected endpoint radii, reaching beyond the vertex Y range. The thin paths stay within the vertex Y range, but there the radius is below 1 pixel anyway.
      Overrides:
      getScreenYMargin in class AbstractCoordinateShape
      Parameters:
      renderingContext - the rendering context (provides projection parameters for size computation)
      Returns:
      the Y margin in screen pixels (0 = vertex bounds are exact)
    • getScreenXMargin

      protected double getScreenXMargin(RenderingContext renderingContext)
      The thick-line widening is perpendicular to the line direction, so it reaches past the vertex range on the X axis exactly as much as on Y.
      Overrides:
      getScreenXMargin in class AbstractCoordinateShape
      Parameters:
      renderingContext - the rendering context (provides projection parameters for size computation)
      Returns:
      the X margin in screen pixels (0 = vertex bounds are exact)
    • paint

      public void paint(RenderingContext buffer)
      Renders this line to the screen using perspective-correct width and alpha blending.

      This method handles two rendering modes:

      • Thin lines: When the projected width is below threshold, draws single-pixel lines with alpha adjusted for sub-pixel appearance.
      • Thick lines: Creates four edge interpolators and fills the rectangular area scanline by scanline with perspective-correct alpha fading at edges.
      Specified by:
      paint in class AbstractCoordinateShape
      Parameters:
      buffer - the rendering context containing the pixel buffer