Class LineSegment2d

java.lang.Object
imagingbook.common.geometry.basic.LineSegment2d
All Implemented Interfaces:
ShapeProducer

public class LineSegment2d extends Object implements ShapeProducer
Described a 2D line segment defined by two end points. Instances are immutable.
  • Constructor Details

    • LineSegment2d

      public LineSegment2d(Pnt2d p1, Pnt2d p2)
      Constructor for arbitrary 2D points.
      Parameters:
      p1 - first end point
      p2 - second end point
    • LineSegment2d

      public LineSegment2d(int x1, int y1, int x2, int y2)
      Constructor for integer coordinates.
      Parameters:
      x1 - x-coordinate of first point
      y1 - y-coordinate of first point
      x2 - x-coordinate of second point
      y2 - y-coordinate of second point
    • LineSegment2d

      public LineSegment2d(double x1, double y1, double x2, double y2)
      Constructor for double coordinates.
      Parameters:
      x1 - x-coordinate of first point
      y1 - y-coordinate of first point
      x2 - x-coordinate of second point
      y2 - y-coordinate of second point
  • Method Details

    • getP1

      public Pnt2d getP1()
      Returns the first end point.
      Returns:
      the first end point
    • getP2

      public Pnt2d getP2()
      Returns the second end point.
      Returns:
      the second end point
    • getShape

      public Shape getShape(double scale)
      Description copied from interface: ShapeProducer
      Returns a scaled Shape for this object (default scale is 1). Must be defined by implementing classes. The interpretation of the scale factor is left to the implementing class. For example, for Pnt2d it specifies the size of the marker (see Pnt2d.getShape(double).
      Specified by:
      getShape in interface ShapeProducer
      Parameters:
      scale - the scale of the shape
      Returns:
      a Shape instance