Class SimpleDirectPosition

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double[] ordinates
      The ordinates.
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleDirectPosition​(int dimension)
      Creates a new direct position of the given dimension.
      SimpleDirectPosition​(java.awt.geom.Point2D point)
      Creates a new two-dimensional direct position initialized to the given point.
    • Field Detail

      • ordinates

        protected final double[] ordinates
        The ordinates.
    • Constructor Detail

      • SimpleDirectPosition

        public SimpleDirectPosition​(int dimension)
        Creates a new direct position of the given dimension.
        Parameters:
        dimension - The dimension.
      • SimpleDirectPosition

        public SimpleDirectPosition​(java.awt.geom.Point2D point)
        Creates a new two-dimensional direct position initialized to the given point.
    • Method Detail

      • getCoordinate

        public double[] getCoordinate()
        A copy of the ordinates presented as an array of double values. Please note that this is only a copy (the real values may be stored in another format) so changes to the returned array will not affect the source DirectPosition.
         final int dim = position.getDimension();
         for (int i=0; i<dim; i++) {
             position.getOrdinate(i); // no copy overhead
         }
         
        To manipulate ordinates, the following idiom can be used:
         position.setOrdinate(i, value); // edit in place
         
        There are a couple reasons for requerying a copy:

        • We want an array of coordinates with the intend to modify it for computation purpose (without modifying the original DirectPosition), or we want to protect the array from future DirectPosition changes.
        • If DirectPosition.getOrdinates() is guaranteed to not return the backing array, then we can work directly on this array. If we don't have this guarantee, then we must conservatively clone the array in every cases.
        • Cloning the returned array is useless if the implementation cloned the array or was forced to returns a new array anyway (for example because the coordinates were computed on the fly)

        Precedence is given to data integrity over getOrdinates() performance. Performance concern can be avoided with usage of DirectPosition.getOrdinate(int).

        Specified by:
        getCoordinate in interface DirectPosition
        Returns:
        A copy of the coordinates. Changes in the returned array will not be reflected back in this DirectPosition object.
      • getCoordinates

        @Deprecated
        public double[] getCoordinates()
        Deprecated.
      • getOrdinate

        public double getOrdinate​(int dimension)
                           throws java.lang.IndexOutOfBoundsException
        Returns the ordinate at the specified dimension.
        Specified by:
        getOrdinate in interface DirectPosition
        Parameters:
        dimension - The dimension in the range 0 to dimension-1.
        Returns:
        The coordinate at the specified dimension.
        Throws:
        java.lang.IndexOutOfBoundsException - If the given index is negative or is equals or greater than the envelope dimension.
      • setOrdinate

        public void setOrdinate​(int dimension,
                                double value)
                         throws java.lang.IndexOutOfBoundsException
        Sets the ordinate value along the specified dimension.
        Specified by:
        setOrdinate in interface DirectPosition
        Parameters:
        dimension - the dimension for the ordinate of interest.
        value - the ordinate value of interest.
        Throws:
        java.lang.IndexOutOfBoundsException - If the given index is negative or is equals or greater than the envelope dimension.
      • getDirectPosition

        public DirectPosition getDirectPosition()
        Returns the direct position. This method shall never returns null, but may returns this if invoked on an object which is already a DirectPosition instance.
        Specified by:
        getDirectPosition in interface Position
        Returns:
        The direct position (may be this).
      • equals

        public boolean equals​(java.lang.Object object)
        Returns true if this direct position is equals to the given object.
        Specified by:
        equals in interface DirectPosition
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - The object to compare with this direct position for equality.
        Returns:
        true if the given object is equals to this direct position.
      • hashCode

        public int hashCode()
        Returns a hash code value for this direct position.
        Specified by:
        hashCode in interface DirectPosition
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code value for this direct position.
      • toString

        public java.lang.String toString()
        Returns a string representation of this direct position.
        Overrides:
        toString in class java.lang.Object