PenProfile 2.x

com.livescribe.geom
Class Shape

java.lang.Object
  extended by com.livescribe.geom.Shape
Direct Known Subclasses:
Ellipse, LineSegment, Point, Polygon, PolyLine, Rectangle, Stroke

public abstract class Shape
extends Object

This class is the superclass for all shapes handled by the system. Shapes created by the system are also aware of the page address on which they were created.

Note that there is no validation checking on the points. It may be possible to create, for example, rectangles or ellipses having a negative height or width.

Note: This class is not thread safe.


Field Summary
static int COORD_MAX
          The maximum coordinate value, unsigned.
static int COORD_MIN
          The minimum coordinate value, unsigned.
static int INTERSECT_CLIP
          The shapes intersect at one or more points.
static int INTERSECT_EXTERNAL
          The shapes do not intersect at all.
static int INTERSECT_INTERNAL1
          This shape is completely inside the other shape.
static int INTERSECT_INTERNAL2
          The other shape is completely inside this shape.
protected static int SHAPE_COMPOSITE
          The composite type.
protected static int SHAPE_ELLIPSE
          The ellipse type.
protected static int SHAPE_LINESEGMENT
          The line segment type.
protected static int SHAPE_POINT
          The point type.
protected static int SHAPE_POLYGON
          The polygon type.
protected static int SHAPE_POLYLINE
          The polyline type.
protected static int SHAPE_RECTANGLE
          The rectangle type.
protected static int SHAPE_STROKE
          The stroke type.
protected  int type
          The shape type, one of the SHAPE_XXX constants.
protected  int[] vertex
          The vertex array must be allocated by subclasses.
 
Constructor Summary
protected Shape(int type)
          Creates a new shape having the specified type.
 
Method Summary
 boolean contains(int x, int y)
          Indicates if the point specified by (x,y) is contained within this shape.
 Rectangle getBoundingBox()
          Gets the bounding box of this shape.
 int getNumberofVertices()
          Deprecated. Use getNumberOfVertices().
 int getNumberOfVertices()
          Returns the number of vertices in this shape.
 int getSize()
          Gets the geometrical area or length of this shape, depending on the type.
protected  int getType()
          Returns the shape type, one of the SHAPE_XXX constants.
static Rectangle getUnion(Shape a, Shape b)
          Finds the smallest possible rectangle that contains both shapes.
 int getX(int i)
          Gets the X-coordinate at the specified index.
 int[] getXY()
          Gets an array of the coordinates in this shape.
 int getY(int i)
          Gets the Y-coordinate at the specified index.
 int intersectsWith(Shape shape)
          Detects any intersection between the this shape and the given shape.
 void setVertexArray(int[] v)
          Sets the internal vertex array.
 void setX(int i, int x)
          Sets the X-coordinate at the specified index.
 void setXY(int[] xy)
          Sets the shape's coordinates to the specified X- and Y-coordinates.
 void setXY(int i, int x, int y)
          Sets the coordinate at the specified index.
 void setY(int i, int y)
          Sets the Y-coordinate at the specified index.
 String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SHAPE_POINT

protected static final int SHAPE_POINT
The point type.

See Also:
Constant Field Values

SHAPE_LINESEGMENT

protected static final int SHAPE_LINESEGMENT
The line segment type.

See Also:
Constant Field Values

SHAPE_RECTANGLE

protected static final int SHAPE_RECTANGLE
The rectangle type.

See Also:
Constant Field Values

SHAPE_ELLIPSE

protected static final int SHAPE_ELLIPSE
The ellipse type.

See Also:
Constant Field Values

SHAPE_POLYGON

protected static final int SHAPE_POLYGON
The polygon type.

See Also:
Constant Field Values

SHAPE_POLYLINE

protected static final int SHAPE_POLYLINE
The polyline type.

See Also:
Constant Field Values

SHAPE_STROKE

protected static final int SHAPE_STROKE
The stroke type.

See Also:
Constant Field Values

SHAPE_COMPOSITE

protected static final int SHAPE_COMPOSITE
The composite type.

See Also:
Constant Field Values

COORD_MIN

public static final int COORD_MIN
The minimum coordinate value, unsigned.

See Also:
Constant Field Values

COORD_MAX

public static final int COORD_MAX
The maximum coordinate value, unsigned.

See Also:
Constant Field Values

INTERSECT_EXTERNAL

public static final int INTERSECT_EXTERNAL
The shapes do not intersect at all.

See Also:
Constant Field Values

INTERSECT_INTERNAL1

public static final int INTERSECT_INTERNAL1
This shape is completely inside the other shape.

See Also:
Constant Field Values

INTERSECT_INTERNAL2

public static final int INTERSECT_INTERNAL2
The other shape is completely inside this shape.

See Also:
Constant Field Values

INTERSECT_CLIP

public static final int INTERSECT_CLIP
The shapes intersect at one or more points.

See Also:
Constant Field Values

vertex

protected int[] vertex
The vertex array must be allocated by subclasses. Each element contains a 32-bit integer, where the top 16 bits are the Y-coordinate and the bottom 16 bits are the X-coordinate.


type

protected final int type
The shape type, one of the SHAPE_XXX constants.

Constructor Detail

Shape

protected Shape(int type)
Creates a new shape having the specified type. The type should be one of the SHAPE_XXX constants.

Note that the internal vertex array is set to null.

Parameters:
type - the shape type
Method Detail

intersectsWith

public int intersectsWith(Shape shape)
Detects any intersection between the this shape and the given shape.

Parameters:
shape - check for intersection with this shape
Returns:
one of theINTERSECT_XXX constants describing how the shapes intersect.
Throws:
NullPointerException - if the given shape is null.

getSize

public int getSize()
Gets the geometrical area or length of this shape, depending on the type. Lines usually return the length, and any closed shapes usually return the area.

Returns:
the shape size, in Anoto Units.

getNumberofVertices

public int getNumberofVertices()
Deprecated. Use getNumberOfVertices().

Returns the number of vertices of a shape Point = 1 Rectangle = 2 Ellipse = 2 LineSeg = 2 Rectangle = X PolyLine = X Stroke = X

Returns:
number of vertices

getNumberOfVertices

public int getNumberOfVertices()
Returns the number of vertices in this shape. The following table summarizes the vertex count for each type of shape.
ShapeVertex Count
Ellipse2
LineSegment2
Point1
PolygonN
PolyLineN
Rectangle2
StrokeN

Returns:
the vertex count for this shape.
Since:
2.3

getX

public int getX(int i)
Gets the X-coordinate at the specified index.

Parameters:
i - the coordinate index
Returns:
the X-coordinate at the specified index.
Throws:
IndexOutOfBoundsException - if the index is out of range.
See Also:
getNumberOfVertices()

getY

public int getY(int i)
Gets the Y-coordinate at the specified index.

Parameters:
i - the coordinate index
Returns:
the Y-coordinate at the specified index.
Throws:
IndexOutOfBoundsException - if the index is out of range.
See Also:
getNumberOfVertices()

getXY

public int[] getXY()
Gets an array of the coordinates in this shape. Each point will fill two elements in the returned array, in (X,Y) order. In other words, the returned array size will be twice the number of vertices.

Returns:
the array
See Also:
setXY(int[]), getNumberOfVertices()

setX

public void setX(int i,
                 int x)
Sets the X-coordinate at the specified index.

Parameters:
i - the coordinate index
x - the new X-coordinate
Throws:
IndexOutOfBoundsException - if the index is out of range.
See Also:
getNumberOfVertices()

setY

public void setY(int i,
                 int y)
Sets the Y-coordinate at the specified index.

Parameters:
i - the coordinate index
y - the new Y-coordinate
Throws:
IndexOutOfBoundsException - if the index is out of range.
See Also:
getNumberOfVertices()

setXY

public void setXY(int i,
                  int x,
                  int y)
Sets the coordinate at the specified index.

Parameters:
i - the coordinate index
x - the X-coordinate
y - the Y-coordinate
Throws:
IndexOutOfBoundsException - if the index is out of range.
See Also:
getNumberOfVertices()

setXY

public void setXY(int[] xy)
Sets the shape's coordinates to the specified X- and Y-coordinates. Note that this can change the number of coordinates in the shape.

Parameters:
xy - array with an even number of elements containing (X,Y) pairs
Throws:
IllegalArgumentException - if the array does not have an even number of elements.

setVertexArray

public void setVertexArray(int[] v)
Sets the internal vertex array. The reference to the array is stored directly. The array is not copied. Please see the vertex documentation for more information.

Parameters:
v - the array
See Also:
vertex

getType

protected final int getType()
Returns the shape type, one of the SHAPE_XXX constants.

Returns:
the shape type, one of the SHAPE_XXX constants.

getBoundingBox

public Rectangle getBoundingBox()
Gets the bounding box of this shape. This returns a new Rectangle.

Returns:
the shape bounds as a Rectangle.

getUnion

public static Rectangle getUnion(Shape a,
                                 Shape b)
Finds the smallest possible rectangle that contains both shapes. This returns a Rectangle instance.

Parameters:
a - the first shape
b - the second shape
Returns:
the resulting rectangle, a Rectangle instance.
Throws:
NullPointerException - if either shape is null.

toString

public String toString()
Returns a string representation of this object.

Overrides:
toString in class Object
Returns:
a string representation of this object.

contains

public boolean contains(int x,
                        int y)
Indicates if the point specified by (x,y) is contained within this shape.

Note that is a very generic implementation. Subclasses can override this to provide a more optimized implementation.

Parameters:
x - the X-coordinate to test
y - the Y-coordinate to test
Returns:
true if it is contained and false if not fully contained.

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.