Package snap.geom

Class Shape

java.lang.Object
snap.geom.Shape
Direct Known Subclasses:
Polygon, PolygonPath, RectBase, Segment, SegmentPath, ShapeBox, ShapeBuilder, SplicerShape

public abstract class Shape extends Object
A class to represent a generic geometric shape (Line, Rect, Ellipse, etc.).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Rect
     
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Shape
    addShapes(Shape aShape1, Shape aShape2)
    Adds two shapes together.
    boolean
    contains(double aX, double aY)
    Returns whether shape contains x/y.
    boolean
    contains(double aX, double aY, double aLineWidth)
    Returns whether shape with line width contains point.
    boolean
    contains(Point aPoint)
    Returns whether shape contains point.
    boolean
    contains(Shape aShape)
    Returns whether shape contains shape.
    boolean
    Returns whether this shape contains given segment.
    copyFor(Rect aRect)
    Returns the shape in rect.
    Returns a copy of this shape transformed by given transform.
    copyForBounds(double aX, double aY, double aW, double aH)
    Returns the shape in rect.
    boolean
    Returns whether any segments of this shape cross given segment.
    double
    Returns the total length of all shape segements.
    Returns the bounds.
    protected Rect
    Returns the bounds.
    int
    getCrossings(double aX, double aY)
    Returns the number of crossings for the ray from given point extending to the right.
    double
    getDistance(double x, double y)
    Returns the closest distance from given point to path.
    Returns a flattented version of this shape (just this shape if already flat).
    getFlattenedShape(double aFlatDistance)
    Returns a flattented version of this shape (just this shape if already flat).
    double
    Returns the shape bounds height.
    static Shape
    Returns a simple shape for complex shape.
    abstract PathIter
    Returns a path iterator.
    Returns an SVG string representation of Shape.
    double
    Returns the shape bounds width.
    double
    Returns the shape bounds x.
    double
    Returns the shape bounds y.
    boolean
    intersects(double aX, double aY, double aLineWidth)
    Returns whether shape with line width intersects point.
    boolean
    intersects(Shape aShape)
    Returns whether this shape intersects given shape.
    boolean
    intersects(Shape aShape, double aLineWidth)
    Returns whether shape with line width intersects shape.
    static Shape
    intersectShapes(Shape aShape1, Shape aShape2)
    Returns the intersection shape of two shapes.
    boolean
    Returns whether this shape intersects given segment (crosses or contains).
    boolean
    Returns whether shape forms a closed polygon/path, either explicitly (last segment is close) or implicitly (last segment ends at last move to).
    boolean
    Returns whether this shape is made up of only line segements.
    boolean
    Returns whether path made up of multiple subpaths (more than one moveto).
    boolean
    Returns whether shape has intersecting segments.
    boolean
    Returns whether path has only a single moveto.
    protected void
    Called when shape changes.
    static Shape
    subtractShapes(Shape aShape1, Shape aShape2)
    Subtracts two shapes together.
    Standard to string implementation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Shape

      public Shape()
  • Method Details

    • getX

      public double getX()
      Returns the shape bounds x.
    • getY

      public double getY()
      Returns the shape bounds y.
    • getWidth

      public double getWidth()
      Returns the shape bounds width.
    • getHeight

      public double getHeight()
      Returns the shape bounds height.
    • getBounds

      public Rect getBounds()
      Returns the bounds.
    • getBoundsImpl

      protected Rect getBoundsImpl()
      Returns the bounds.
    • getArcLength

      public double getArcLength()
      Returns the total length of all shape segements.
    • getPathIter

      public abstract PathIter getPathIter(Transform aT)
      Returns a path iterator.
    • contains

      public boolean contains(Point aPoint)
      Returns whether shape contains point.
    • contains

      public boolean contains(double aX, double aY)
      Returns whether shape contains x/y.
    • getCrossings

      public int getCrossings(double aX, double aY)
      Returns the number of crossings for the ray from given point extending to the right.
    • contains

      public boolean contains(Shape aShape)
      Returns whether shape contains shape.
    • intersects

      public boolean intersects(Shape aShape)
      Returns whether this shape intersects given shape.
    • containsSeg

      public boolean containsSeg(Segment aSeg)
      Returns whether this shape contains given segment.
    • intersectsSeg

      public boolean intersectsSeg(Segment aSeg)
      Returns whether this shape intersects given segment (crosses or contains).
    • crossesSeg

      public boolean crossesSeg(Segment aSeg)
      Returns whether any segments of this shape cross given segment.
    • getDistance

      public double getDistance(double x, double y)
      Returns the closest distance from given point to path.
    • contains

      public boolean contains(double aX, double aY, double aLineWidth)
      Returns whether shape with line width contains point.
    • intersects

      public boolean intersects(double aX, double aY, double aLineWidth)
      Returns whether shape with line width intersects point.
    • intersects

      public boolean intersects(Shape aShape, double aLineWidth)
      Returns whether shape with line width intersects shape.
    • isClosed

      public boolean isClosed()
      Returns whether shape forms a closed polygon/path, either explicitly (last segment is close) or implicitly (last segment ends at last move to). Supports multiple subpaths.
    • isFlat

      public boolean isFlat()
      Returns whether this shape is made up of only line segements.
    • getFlattenedShape

      public Shape getFlattenedShape()
      Returns a flattented version of this shape (just this shape if already flat).
    • getFlattenedShape

      public Shape getFlattenedShape(double aFlatDistance)
      Returns a flattented version of this shape (just this shape if already flat).
    • isSingleCycle

      public boolean isSingleCycle()
      Returns whether path has only a single moveto.
    • isMultiCycle

      public boolean isMultiCycle()
      Returns whether path made up of multiple subpaths (more than one moveto).
    • isSelfIntersecting

      public boolean isSelfIntersecting()
      Returns whether shape has intersecting segments.
    • shapeChanged

      protected void shapeChanged()
      Called when shape changes.
    • copyFor

      public Shape copyFor(Rect aRect)
      Returns the shape in rect.
    • copyForBounds

      public Shape copyForBounds(double aX, double aY, double aW, double aH)
      Returns the shape in rect.
    • copyFor

      public Shape copyFor(Transform aTrans)
      Returns a copy of this shape transformed by given transform.
    • getSvgString

      public String getSvgString()
      Returns an SVG string representation of Shape.
    • toString

      public String toString()
      Standard to string implementation.
      Overrides:
      toString in class Object
    • addShapes

      public static Shape addShapes(Shape aShape1, Shape aShape2)
      Adds two shapes together.
    • subtractShapes

      public static Shape subtractShapes(Shape aShape1, Shape aShape2)
      Subtracts two shapes together.
    • intersectShapes

      public static Shape intersectShapes(Shape aShape1, Shape aShape2)
      Returns the intersection shape of two shapes.
    • getNotSelfIntersectingShape

      public static Shape getNotSelfIntersectingShape(Shape aShape)
      Returns a simple shape for complex shape.