001         package com.croftsoft.core.math.geom;
002    
003         import java.io.Serializable;
004    
005         /*********************************************************************
006         * A mutable point in three-dimensional integer space (x, y, and z).
007         *
008         * @version
009         *   $Id: Point3DI.java,v 1.3 2008/09/20 02:51:51 croft Exp $
010         * @since
011         *   2001-03-07
012         * @author
013         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
014         *********************************************************************/
015    
016         public final class  Point3DI
017           implements Cloneable, Serializable
018         //////////////////////////////////////////////////////////////////////
019         //////////////////////////////////////////////////////////////////////
020         {
021    
022         private static final long  serialVersionUID = 0L;
023    
024         //
025    
026         private int  x;
027    
028         private int  y;
029    
030         private int  z;
031    
032         //////////////////////////////////////////////////////////////////////
033         //////////////////////////////////////////////////////////////////////
034    
035         public static boolean  equivalent (
036           Point3DI  aPoint3DI,
037           Point3DI  bPoint3DI )
038         //////////////////////////////////////////////////////////////////////
039         {
040           if ( aPoint3DI == null )
041           {
042             return bPoint3DI == null;
043           }
044           
045           return aPoint3DI.equals ( bPoint3DI );
046         }
047    
048         //////////////////////////////////////////////////////////////////////
049         //////////////////////////////////////////////////////////////////////
050    
051         public  Point3DI (
052           int  x,
053           int  y,
054           int  z )
055         //////////////////////////////////////////////////////////////////////
056         {
057           this.x = x;
058    
059           this.y = y;
060    
061           this.z = z;
062         }
063    
064         public  Point3DI ( )
065         //////////////////////////////////////////////////////////////////////
066         {
067           this ( 0, 0, 0 );
068         }
069    
070         //////////////////////////////////////////////////////////////////////
071         //////////////////////////////////////////////////////////////////////
072    
073         public int  getX ( ) { return x; }
074    
075         public int  getY ( ) { return y; }
076    
077         public int  getZ ( ) { return z; }
078    
079         //////////////////////////////////////////////////////////////////////
080         //////////////////////////////////////////////////////////////////////
081    
082         public void  setX ( int  x ) { this.x = x; }
083    
084         public void  setY ( int  y ) { this.y = y; }
085    
086         public void  setZ ( int  z ) { this.z = z; }
087    
088         //////////////////////////////////////////////////////////////////////
089         //////////////////////////////////////////////////////////////////////
090    
091         @Override
092         public boolean  equals ( Object  other )
093         //////////////////////////////////////////////////////////////////////
094         {
095           if ( other == null )
096           {
097             return false;
098           }
099    
100           if ( !this.getClass ( ).equals ( other.getClass ( ) ) )
101           {
102             return false;
103           }
104    
105           Point3DI  that = ( Point3DI ) other;
106    
107           return ( this.x == that.x )
108             &&   ( this.y == that.y )
109             &&   ( this.z == that.z );
110         }
111    
112         @Override
113         public int  hashCode ( )
114         //////////////////////////////////////////////////////////////////////
115         {
116           // This might be a poor choice for a hash code algorithm.
117    
118           return x ^ y ^ z;
119         }
120    
121         @Override
122         public Object  clone ( )
123         //////////////////////////////////////////////////////////////////////
124         {
125           try
126           {
127             return super.clone ( );
128           }
129           catch ( CloneNotSupportedException  ex )
130           {
131             // This will never happen.
132    
133             throw new RuntimeException ( );
134           }
135         }
136    
137         @Override
138         public String  toString ( )
139         //////////////////////////////////////////////////////////////////////
140         {
141           return "<Point3DI>"
142                +   "<x>" + x + "</x>"
143                +   "<y>" + y + "</y>"
144                +   "<z>" + z + "</z>"
145                + "</Point3DI>";
146         }
147    
148         //////////////////////////////////////////////////////////////////////
149         //////////////////////////////////////////////////////////////////////
150         }