net.von_gagern.martin.confoo.mesh.flat
Class Triangle2D

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<V>
          extended by net.von_gagern.martin.confoo.mesh.SimpleTriangle<Vertex2D>
              extended by net.von_gagern.martin.confoo.mesh.flat.Triangle2D
All Implemented Interfaces:
Shape, Iterable<Vertex2D>, Collection<Vertex2D>, List<Vertex2D>, CorneredTriangle<Vertex2D>

public class Triangle2D
extends SimpleTriangle<Vertex2D>
implements Shape

A 2D triangle which is also a shape.

Since:
1.0
Author:
Martin von Gagern

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Triangle2D(double x1, double y1, double x2, double y2, double x3, double y3)
          Construct triangle from corner coordinates.
Triangle2D(Point2D p1, Point2D p2, Point2D p3)
          Construct triangle from three corner points.
Triangle2D(Vertex2D p1, Vertex2D p2, Vertex2D p3)
          Construct triangle from three vertices.
 
Method Summary
 boolean contains(double x, double y)
          Determine whether a point given by its coordinates lies within the triangle.
 boolean contains(double x, double y, double w, double h)
          Determine whether the triangle completely contains a rectangle given by its coordinates.
 boolean contains(Point2D p)
          Determine whether a given point lies within the triangle.
 boolean contains(Rectangle2D r)
          Determine whether the triangle completely contains a given rectangle.
 Rectangle getBounds()
          Calculate integer bounding box.
 Rectangle2D getBounds2D()
          Calculate bounding box.
 PathIterator getPathIterator(AffineTransform at)
          Get a path iterator for this shape.
 PathIterator getPathIterator(AffineTransform at, double flatness)
          Get a flattening path iterator for this shape.
 boolean intersects(double x, double y, double w, double h)
          Determine whether the triangle intersects a rectangle given by its coordinates.
 boolean intersects(Rectangle2D r)
          Determine whether the triangle intersects a given rectangle.
 
Methods inherited from class net.von_gagern.martin.confoo.mesh.SimpleTriangle
equal, equals, get, getCorner, hashCode, size
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

Triangle2D

public Triangle2D(Vertex2D p1,
                  Vertex2D p2,
                  Vertex2D p3)
Construct triangle from three vertices.

Parameters:
p1 - first vertex
p2 - second vertex
p3 - third vertex

Triangle2D

public Triangle2D(Point2D p1,
                  Point2D p2,
                  Point2D p3)
Construct triangle from three corner points. The points will be used to construct Vertex2D objects. After that, changes to the points won't affect the triangle object.

Parameters:
p1 - first corner point
p2 - second corner point
p3 - third corner point

Triangle2D

public Triangle2D(double x1,
                  double y1,
                  double x2,
                  double y2,
                  double x3,
                  double y3)
Construct triangle from corner coordinates.

Parameters:
x1 - first corner x coordinate
y1 - first corner y coordinate
x2 - second corner x coordinate
y2 - second corner y coordinate
x3 - third corner x coordinate
y3 - third corner y coordinate
Method Detail

getBounds

public Rectangle getBounds()
Calculate integer bounding box.

Specified by:
getBounds in interface Shape
Returns:
integer bounding box containing the triangle
See Also:
getBounds2D()

getBounds2D

public Rectangle2D getBounds2D()
Calculate bounding box. The bounding box will not contain all corner points, as a rectangle does not contain points on its lower and right boundary.

Specified by:
getBounds2D in interface Shape
Returns:
bounding box containing the triangle

contains

public boolean contains(double x,
                        double y)
Determine whether a point given by its coordinates lies within the triangle.

Specified by:
contains in interface Shape
Parameters:
x - the x coordinate of a point
y - the y coordinate of a point
Returns:
whether the triangle contains the point

contains

public boolean contains(Point2D p)
Determine whether a given point lies within the triangle.

Specified by:
contains in interface Shape
Parameters:
p - a point to check for insideness
Returns:
whether the triangle contains the point

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Determine whether the triangle completely contains a rectangle given by its coordinates.

Specified by:
contains in interface Shape
Parameters:
x - the x coordinate of a rectangle
y - the y coordinate of a rectangle
w - width of a rectangle
h - height of a rectangle
Returns:
whether the triangle contains the rectangle

contains

public boolean contains(Rectangle2D r)
Determine whether the triangle completely contains a given rectangle.

Specified by:
contains in interface Shape
Parameters:
r - a rectangle to check for containment
Returns:
whether the triangle contains the rectangle

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Determine whether the triangle intersects a rectangle given by its coordinates.

Specified by:
intersects in interface Shape
Parameters:
x - the x coordinate of a rectangle
y - the y coordinate of a rectangle
w - width of a rectangle
h - height of a rectangle
Returns:
whether the triangle intersects the rectangle

intersects

public boolean intersects(Rectangle2D r)
Determine whether the triangle intersects a given rectangle.

Specified by:
intersects in interface Shape
Parameters:
r - a rectangle to check for intersection
Returns:
whether the triangle intersects the rectangle

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Get a path iterator for this shape.

Specified by:
getPathIterator in interface Shape
Parameters:
at - a transformation to be applied to all coordinates
Returns:
an iterator over the triangle outline

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Get a flattening path iterator for this shape. As triangles are flat already, this is equal to the non-flattening version.

Specified by:
getPathIterator in interface Shape
Parameters:
at - a transformation to be applied to all coordinates
Returns:
an iterator over the triangle outline
See Also:
getPathIterator(AffineTransform)


Copyright © 2008 Martin von Gagern. All Rights Reserved.