Package geomss.geom

Class Point

  • All Implemented Interfaces:
    GeomElement<GeomPoint>, PointGeometry<GeomPoint>, Transformable<GeomPoint>, XYPoint, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, javolution.lang.Immutable, javolution.lang.Reusable, javolution.lang.ValueType, javolution.xml.XMLSerializable

    public final class Point
    extends GeomPoint
    implements javolution.lang.ValueType
    A container that holds the coordinates of a point in n-dimensional space.

    Modified by: Joseph A. Huwaldt

    Version:
    February 17, 2025
    Author:
    Joseph A. Huwaldt, Date: December 11, 1999
    See Also:
    Serialized Form
    • Method Detail

      • newInstance

        public static Point newInstance​(int dim)
        Returns a Point instance of the specified dimension with zero meters for each coordinate value.
        Parameters:
        dim - the physical dimension of the point to create.
        Returns:
        the point having the specified dimension and zero meters for values.
      • newInstance

        public static Point newInstance​(int dim,
                                        javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
        Returns a Point instance of the specified dimension and units with zero for each coordinate value.
        Parameters:
        dim - the physical dimension of the point to create.
        unit - The unit for the point to create. May not be null.
        Returns:
        the point having the specified dimension & units and zero for values.
      • valueOf

        public static Point valueOf​(double... x)
        Returns a Point instance holding the specified double value or values stated in meters.
        Parameters:
        x - the coordinate values stated in meters. May not be null.
        Returns:
        the point having the specified value.
      • valueOf

        public static Point valueOf​(double x,
                                    javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
        Returns a 1D Point instance holding the specified double values stated in the specified units.
        Parameters:
        x - the x value stated in the specified unit.
        unit - the unit in which the coordinates are stated. May not be null.
        Returns:
        the point having the specified value.
      • valueOf

        public static Point valueOf​(double x,
                                    double y,
                                    javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
        Returns a 2D Point instance holding the specified double value stated in the specified units.
        Parameters:
        x - the x value stated in the specified unit.
        y - the y value stated in the specified unit.
        unit - the unit in which the coordinates are stated. May not be null.
        Returns:
        the point having the specified values.
      • valueOf

        public static Point valueOf​(double x,
                                    double y,
                                    double z,
                                    javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
        Returns a 3D Point instance holding the specified double values stated in the specified units.
        Parameters:
        x - the x value stated in the specified unit.
        y - the y value stated in the specified unit.
        z - the z value stated in the specified unit.
        unit - the unit in which the coordinates are stated. May not be null.
        Returns:
        the point having the specified values.
      • valueOf

        public static Point valueOf​(javax.measure.unit.Unit<javax.measure.quantity.Length> unit,
                                    double... values)
        Returns a Point instance holding the specified double values stated in the specified units.
        Parameters:
        unit - the length unit in which the coordinates are stated. May not be null.
        values - the list of values stated in the specified unit. May not be null.
        Returns:
        the point having the specified values.
      • valueOf

        public static Point valueOf​(Parameter<javax.measure.quantity.Length>... values)
        Returns a Point instance holding the specified Parameter values. All the values are converted to the same units as the 1st value.
        Parameters:
        values - The list of values to be stored. May not be null.
        Returns:
        the point having the specified values in the units of the 1st value.
      • valueOf

        public static Point valueOf​(java.util.List<Parameter<javax.measure.quantity.Length>> values)
        Returns a Point instance holding the specified Parameter values. All the values are converted to the same units as the 1st value.
        Parameters:
        values - The list of values to be stored. May not be null and must have at least one element..
        Returns:
        the point having the specified values in the units of the 1st value.
      • valueOf

        public static Point valueOf​(Coordinate3D<javax.measure.quantity.Length> coord)
        Returns a Point instance holding the specified @link jahuwaldt.js.param.Coordinate3D Coordinate3D values.
        Parameters:
        coord - The Coordinate3D to be stored. May not be null.
        Returns:
        the point having the specified values.
      • valueOf

        public static Point valueOf​(Vector<Float64> vector,
                                    javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
        Returns a Point instance containing the specified vector of Float64 values stated in the specified units.
        Parameters:
        vector - the vector of Float64 values stated in the specified unit. May not be null.
        unit - the unit in which the values are stated. May not be null.
        Returns:
        the point having the specified values.
      • valueOf

        public static <Q extends javax.measure.quantity.Quantity> Point valueOf​(Vector<Parameter<Q>> vector)
        Returns a Point instance containing the specified vector of Parameter values with length units. All the values are converted to the same units as the 1st value.
        Type Parameters:
        Q - The Quantity (type of unit) for this Point data. Must be "Length" or "Dimensionless".
        Parameters:
        vector - The vector of Parameter values stated in length or dimensionless units. If in dimensionless units, the values are interpreted as being in meters. May not be null.
        Returns:
        the point having the specified values.
        Throws:
        javax.measure.converter.ConversionException - if the input vector is not in Length (or Dimensionless) units.
      • valueOf

        public static Point valueOf​(GeomVector<?> vector)
        Returns a Point instance that represents the direction elements of the specified GeomVector given in length or dimensionless units. If the user wishes for the point to represent the end or tip of the vehicle they should use the following: Point p = Point.valueOf(vector).plus(vector.getOrigin());
        Parameters:
        vector - the GeomVector stated in length or dimensionless units. If in dimensionless units, the values are interpreted as being in meters. May not be null.
        Returns:
        the point having the elements of the vector.
        Throws:
        javax.measure.converter.ConversionException - if the input vector is not in length (or Dimensionless) units.
      • valueOf

        public static Point valueOf​(GeomPoint point)
        Returns a Point instance containing the specified GeomPoint's data.
        Parameters:
        point - the GeomPoint to be copied into a new Point. May not be null.
        Returns:
        the point having the specified values.
      • valueOf

        public static Point valueOf​(Point point)
        Returns a Point instance containing the specified Point's data.
        Parameters:
        point - the Point to be copied into a new Point. May not be null.
        Returns:
        the point having the specified values.
      • immutable

        public Point immutable()
        Return an immutable version of this point. This implementation simply returns this Point instance.
        Specified by:
        immutable in class GeomPoint
        Returns:
        A reference to this Point (which is immutable).
      • mutable

        public MutablePoint mutable()
        Return a mutable copy of this point.
        Returns:
        A mutable copy of this Point object.
      • getPhyDimension

        public int getPhyDimension()
        Returns the number of physical dimensions of the geometry element.
        Specified by:
        getPhyDimension in interface GeomElement<GeomPoint>
        Returns:
        The number of physical dimensions of the geometry element.
      • getValue

        public double getValue​(int i)
        Returns the value of a coordinate in this point as a double, stated in this point's unit.
        Specified by:
        getValue in class GeomPoint
        Parameters:
        i - the dimension index.
        Returns:
        the value of the Parameter at i.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i ≥ dimension())
      • getValue

        public double getValue​(int i,
                               javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
        Returns the value of a coordinate in this point as a double, stated in the specified unit.
        Specified by:
        getValue in class GeomPoint
        Parameters:
        i - the dimension index.
        unit - the unit to return the value in. May not be null.
        Returns:
        the value of the Parameter at i in the specified unit.
        Throws:
        java.lang.IndexOutOfBoundsException - (i < 0) || (i ≥ dimension())
      • normSqValue

        public double normSqValue()
        Returns the square of the Euclidean norm, magnitude, or length value of the vector from the origin to this point (the dot product of the origin-to-this-point vector and itself). This is slightly faster than calling normValue if the squared value is all that is needed.
        Specified by:
        normSqValue in class GeomPoint
        Returns:
        this.normSq().getValue().
        See Also:
        GeomPoint.normValue()
      • plus

        public Point plus​(GeomPoint that)
        Returns the sum of this point with the one specified. The unit of the output point will be the units of this point.
        Specified by:
        plus in class GeomPoint
        Parameters:
        that - the point to be added. May not be null.
        Returns:
        this + that.
        Throws:
        DimensionException - if point dimensions are different.
      • plus

        public Point plus​(Parameter<javax.measure.quantity.Length> that)
        Adds the specified parameter to each component of this point. The unit of the output point will be the units of this point.
        Specified by:
        plus in class GeomPoint
        Parameters:
        that - the parameter to be added to each component of this point. May not be null.
        Returns:
        this + that.
      • minus

        public Point minus​(GeomPoint that)
        Returns the difference between this point and the one specified. The unit of the output point will be the units of this point.
        Specified by:
        minus in class GeomPoint
        Parameters:
        that - the point to be subtracted from this point. May not be null.
        Returns:
        this - that.
        Throws:
        DimensionException - if point dimensions are different.
      • minus

        public Point minus​(Parameter<javax.measure.quantity.Length> that)
        Subtracts the specified parameter from each component of this point. The unit of the output point will be the units of this point.
        Specified by:
        minus in class GeomPoint
        Parameters:
        that - the parameter to be subtracted from each component of this point. May not be null.
        Returns:
        this - that.
      • opposite

        public Point opposite()
        Returns the negation of this point (all the values of each dimension negated).
        Specified by:
        opposite in class GeomPoint
        Returns:
        -this
      • times

        public Point times​(double k)
        Returns the product of this point with the specified coefficient.
        Specified by:
        times in class GeomPoint
        Parameters:
        k - the coefficient multiplier.
        Returns:
        this ยท k
      • copy

        public Point copy()
        Returns a copy of this Point instance allocated by the calling thread (possibly on the stack).
        Specified by:
        copy in interface GeomElement<GeomPoint>
        Specified by:
        copy in interface javolution.lang.ValueType
        Specified by:
        copy in class GeomPoint
        Returns:
        an identical and independent copy of this point.
      • getUnit

        public final javax.measure.unit.Unit<javax.measure.quantity.Length> getUnit()
        Returns the unit in which the values in this point are stated in.
        Specified by:
        getUnit in interface GeomElement<GeomPoint>
        Returns:
        The unit in which this Point is stated.
      • to

        public Point to​(javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
                 throws javax.measure.converter.ConversionException
        Returns the equivalent to this point but stated in the specified unit.
        Specified by:
        to in interface GeomElement<GeomPoint>
        Specified by:
        to in interface PointGeometry<GeomPoint>
        Parameters:
        unit - the length unit of the point to be returned. May not be null.
        Returns:
        an equivalent of this point but stated in the specified unit.
        Throws:
        javax.measure.converter.ConversionException - if the the input unit is not a length unit.
      • toDimension

        public Point toDimension​(int newDim)
        Return the equivalent of this point converted to the specified number of physical dimensions. If the number of dimensions is greater than this element, then zeros are added to the additional dimensions. If the number of dimensions is less than this element, then the extra dimensions are simply dropped (truncated). If the new dimensions are the same as the dimension of this element, then this element is simply returned.
        Specified by:
        toDimension in interface GeomElement<GeomPoint>
        Parameters:
        newDim - The dimension of the point to return.
        Returns:
        A copy of this point converted to the new dimensions.
      • toFloat64Vector

        public final Float64Vector toFloat64Vector()
        Returns the values stored in this point, stated in this point's unit, as a Float64Vector.
        Specified by:
        toFloat64Vector in class GeomPoint
        Returns:
        A Float64Vector containing the values stored in this Point in the current units.
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares this Point against the specified object for strict equality (same values and same units).
        Overrides:
        equals in class AbstractGeomElement<GeomPoint>
        Parameters:
        obj - the object to compare with.
        Returns:
        true if this point is identical to that point; false otherwise.
      • allocateArray

        public static Point[] allocateArray​(int size)
        Allocate a recyclable array that can contain Point objects using factory methods.

        WARNING: The array returned may not be zeroed. Any object references in the returned array must be assumed to be invalid. Also, the returned array may be larger than the requested size! The array returned by this method can be recycled by recycleArray().

        Parameters:
        size - The minimum number of elements for the returned array to contain.
        Returns:
        An array that can contain Point objects allocated using factory methods.
        See Also:
        recycleArray(geomss.geom.Point[])
      • recycleArray

        public static void recycleArray​(Point[] arr)
        Recycle an array of Point objects that was created by Point.allocateArray().
        Parameters:
        arr - The array to be recycled. The array must have been created by this the allocateArray() method!
        See Also:
        allocateArray(int)
      • main

        public static void main​(java.lang.String[] args)
        Tests the methods in this class.
        Parameters:
        args - Command-line arguments (not used).