Package snap.geom

Class Line


public class Line extends Segment
A class to represent a mathematical line.
  • Constructor Details

    • Line

      public Line(double aX0, double aY0, double aX1, double aY1)
      Creates a new line.
  • Method Details

    • setPoints

      public void setPoints(double aX0, double aY0, double aX1, double aY1)
      Sets the line points.
    • getArcLengthImpl

      protected double getArcLengthImpl()
      Calculates and returns length of this segment.
      Specified by:
      getArcLengthImpl in class Segment
    • getBoundsImpl

      protected Rect getBoundsImpl()
      Returns the shape bounds.
      Overrides:
      getBoundsImpl in class Shape
    • copyFor

      public Shape copyFor(Rect aRect)
      Returns the shape in rect.
      Overrides:
      copyFor in class Shape
    • getPathIter

      public PathIter getPathIter(Transform aTrans)
      Returns the path iterator.
      Specified by:
      getPathIter in class Shape
    • contains

      public boolean contains(double aX, double aY)
      Returns whether shape contains x/y.
      Overrides:
      contains in class Shape
    • contains

      public boolean contains(Shape aShape)
      Returns whether shape contains x/y/w/h.
      Overrides:
      contains in class Shape
    • contains

      public boolean contains(double aX, double aY, double aLineWidth)
      Returns whether shape with line width contains point.
      Overrides:
      contains in class Shape
    • getX

      public double getX(double aLoc)
      Returns the x value at given parametric location.
      Specified by:
      getX in class Segment
    • getY

      public double getY(double aLoc)
      Returns the y value at given parametric location.
      Specified by:
      getY in class Segment
    • split

      public Line split(double aLoc)
      Splits the line at given parametric location and return the remainder.
      Specified by:
      split in class Segment
    • createReverse

      public Line createReverse()
      Creates and returns the reverse of this segement.
      Specified by:
      createReverse in class Segment
    • getDistance

      public double getDistance(double aX, double aY)
      Returns the minimum distance from the given point to this line.
      Overrides:
      getDistance in class Shape
    • getDistanceSquared

      public double getDistanceSquared(double aX, double aY)
      Returns the minimum distance from the given point to this line, squared.
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class Object
    • matches

      public boolean matches(Object anObj)
      Returns whether line is equal to another, regardless of direction.
      Specified by:
      matches in class Segment
    • getHit

      public SegHit getHit(Segment aSeg)
      Returns the hit for given segment.
      Overrides:
      getHit in class Segment
    • getDistance

      public static double getDistance(double x0, double y0, double x1, double y1, double aX, double aY)
      Returns the distance from the given line points (p1,p2) to the given point.
    • getDistanceSquared

      public static double getDistanceSquared(double x0, double y0, double x1, double y1, double aX, double aY)
      Returns the distance from the given line points (p1,p2) to the given point.
    • getBounds

      public static Rect getBounds(double x0, double y0, double x1, double y1, Rect aRect)
      Returns the bounds for given line points.
    • crossings

      public static int crossings(double x0, double y0, double x1, double y1, double px, double py)
      Returns the number of crossings for the ray from given point extending to the right.
    • intersectsLine

      public static boolean intersectsLine(double x0, double y0, double x1, double y1, double px0, double py0, double px1, double py1)
      Returns whether line for given points is intersected by second line with given points.
    • isCollinear

      public static boolean isCollinear(double x0, double y0, double x1, double y1, double x2, double y2)
      Returns whether given three points are collinear.