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

java.lang.Object
  extended by java.awt.geom.Point2D
      extended by java.awt.geom.Point2D.Double
          extended by net.von_gagern.martin.confoo.mesh.flat.Vertex2D
All Implemented Interfaces:
Serializable, Cloneable

public class Vertex2D
extends Point2D.Double

A 2D point with equality comparison.

To easily construct meshes, it is useful to identify common vertices. This implementation considers points equal if they exactly agree in their coordinates. This contrasts with the implementation in the super class, which inherits the equality comparison from Object.

Since:
1.0
Author:
Martin von Gagern
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Point2D
Point2D.Double, Point2D.Float
 
Field Summary
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Constructor Summary
Vertex2D(double x, double y)
          Construct vertex from given coordinates.
Vertex2D(Point2D p)
          Construct vertex from given point.
 
Method Summary
 boolean equals(Object o)
          Compare vertex to other point.
 int hashCode()
          Calculate hash code from coordinates.
 
Methods inherited from class java.awt.geom.Point2D.Double
getX, getY, setLocation, toString
 
Methods inherited from class java.awt.geom.Point2D
clone, distance, distance, distance, distanceSq, distanceSq, distanceSq, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vertex2D

public Vertex2D(Point2D p)
Construct vertex from given point.

Parameters:
p - the point used to initialize the coordinates

Vertex2D

public Vertex2D(double x,
                double y)
Construct vertex from given coordinates.

Parameters:
x - the initial x coordinate
y - the initial y coordinate
Method Detail

hashCode

public int hashCode()
Calculate hash code from coordinates.

Overrides:
hashCode in class Point2D
Returns:
a hash code derived from the coordinates

equals

public boolean equals(Object o)
Compare vertex to other point. The comparison is based on coordinates, not object identity. The classes aren't compared either. Any Point2D with the same coordinates will compare equal. This is a violation of symmetry! While it may be handy to compare vertices with other points where you know what you are doing, mixing them in any container that compares its elements is a bad idea, as it can lead to inconsistent behaviour.

Overrides:
equals in class Point2D
Parameters:
o - another object
Returns:
whether o is a Point2D with the same coordinates as this vertex
See Also:
Point2D


Copyright © 2008-2009 Martin von Gagern. All Rights Reserved.