com.partnersoft.geometry.xy
Interface XyShape<T extends XyShape>

All Superinterfaces:
Immutable, java.lang.Iterable<XyPoint>
All Known Subinterfaces:
XyArea<T>, XyPath<T>
All Known Implementing Classes:
XyArc, XyBounds, XyCircle, XyCubicCurve, XyEllipse, XyLineSegment, XyPoint, XyPolygon, XyPolyline, XyQuadraticCurve, XyQuadrilateral, XyRectangle, XyRegularPolygon, XyShapeList, XyTriangle

public interface XyShape<T extends XyShape>
extends Immutable, java.lang.Iterable<XyPoint>

Generic supertype for all shapes in the (x, y) coordinate space.

Defines basic methods and enforces immutability and iterability. In addition, shapes must be defined in such a way that translation and uniform scaling do not change their class. Other types of affine transform may change the class. For example, scaling a square by the same factor in both dimensions always results in a square. Translating it by moving it any amount in either dimension always results in a square. However, scaling it by one factor in X and another factor in Y, or applying shears, results in something not a square.

Subclasses should generally provide themselves as the generic type parameter T. For example:

 public class XyPoint implements XyShape<XyPoint> {
 
This clever construction allows you to use e.g. scaledBy() on a shape of declared type without having to cast the result:
 XyPoint original = new XyPoint(100, 100);
 XyPoint scaled = original.scaledBy(5);
 
Copyright 2007 Partner Software, Inc.

Version:
$Id: XyShape.java 1704 2009-01-13 22:16:02Z paul $
Author:
Paul Reavis

Method Summary
 XyBounds getBounds()
          Returns an XyBounds object representing the rectangular extents of this shape.
 T scaledBy(double factor)
          Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions.
 XyShape transformedBy(XyTransform transform)
          Transform the shape using the given transform.
 T translatedBy(double offsetX, double offsetY)
          Translate the shape by adding all coordinates to the given x and y offsets.
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

scaledBy

T scaledBy(double factor)
Return a scaled version of the shape by multiplying all coordinates by the given factor in both dimensions. This resulting shape must be of the same class as the original.

Parameters:
factor - scaling factor
Returns:
scaled result

translatedBy

T translatedBy(double offsetX,
               double offsetY)
Translate the shape by adding all coordinates to the given x and y offsets. The resulting shape must be of the same class as the original.

Parameters:
offsetX - offset for the x dimension
offsetY - offset for the y dimension
Returns:
offset result

transformedBy

XyShape transformedBy(XyTransform transform)
Transform the shape using the given transform. Due to potential distortion the result may be a different type of shape than this one.

Parameters:
transform - affine transform to apply.
Returns:
transformed result

getBounds

XyBounds getBounds()
Returns an XyBounds object representing the rectangular extents of this shape.