Class SpatialUtil


  • public final class SpatialUtil
    extends java.lang.Object
    Utility class with spatial functions.
    Since:
    0.4.0
    Author:
    Erich Schubert
    • Constructor Detail

      • SpatialUtil

        private SpatialUtil()
        Fake constructor: do not instantiate.
    • Method Detail

      • assertSameDimensionality

        public static int assertSameDimensionality​(SpatialComparable box1,
                                                   SpatialComparable box2)
        Check that two spatial objects have the same dimensionality.
        Parameters:
        box1 - First object
        box2 - Second object
        Returns:
        Dimensionality
        Throws:
        java.lang.IllegalArgumentException - when the dimensionalities do not agree
      • getMin

        public static double[] getMin​(SpatialComparable box)
        Returns a clone of the minimum hyper point.
        Parameters:
        box - spatial object
        Returns:
        the minimum hyper point
      • getMax

        public static double[] getMax​(SpatialComparable box)
        Returns a clone of the maximum hyper point.
        Parameters:
        box - spatial object
        Returns:
        the maximum hyper point
      • intersects

        public static boolean intersects​(SpatialComparable box1,
                                         SpatialComparable box2)
        Returns true if the two SpatialComparables intersect, false otherwise.
        Parameters:
        box1 - the first SpatialComparable
        box2 - the first SpatialComparable
        Returns:
        true if the SpatialComparables intersect, false otherwise
      • contains

        public static boolean contains​(SpatialComparable box1,
                                       SpatialComparable box2)
        Returns true if the first SpatialComparable contains the second SpatialComparable, false otherwise.
        Parameters:
        box1 - the outer SpatialComparable
        box2 - the inner SpatialComparable
        Returns:
        true if the first SpatialComparable contains the second SpatialComparable, false otherwise
      • contains

        public static boolean contains​(SpatialComparable box,
                                       double[] point)
        Returns true if this SpatialComparable contains the given point, false otherwise.
        Parameters:
        box - spatial object
        point - the point to be tested for containment
        Returns:
        true if this SpatialComparable contains the given point, false otherwise
      • volume

        public static double volume​(SpatialComparable box)
        Computes the volume of this SpatialComparable.
        Parameters:
        box - Spatial object
        Returns:
        the volume of this SpatialComparable
      • volumeUnion

        public static double volumeUnion​(SpatialComparable box1,
                                         SpatialComparable box2)
        Compute the volume (area) of the union of two MBRs.
        Parameters:
        box1 - First object
        box2 - Second object
        Returns:
        Volume of union
      • volumeScaled

        public static double volumeScaled​(SpatialComparable box,
                                          double scale)
        Computes the volume of this SpatialComparable.
        Parameters:
        box - Box
        scale - Scaling factor
        Returns:
        the volume of this SpatialComparable
      • volumeUnionScaled

        public static double volumeUnionScaled​(SpatialComparable box1,
                                               SpatialComparable box2,
                                               double scale)
        Compute the volume (area) of the union of two MBRs.
        Parameters:
        box1 - First object
        box2 - Second object
        scale - Scaling factor
        Returns:
        Volume of union
      • enlargement

        public static double enlargement​(SpatialComparable exist,
                                         SpatialComparable addit)
        Compute the enlargement obtained by adding an object to an existing object.
        Parameters:
        exist - Existing rectangle
        addit - Additional rectangle
        Returns:
        Enlargement factor
      • perimeter

        public static double perimeter​(SpatialComparable box)
        Computes the perimeter of this SpatialComparable.
        Parameters:
        box - spatial object
        Returns:
        the perimeter of this SpatialComparable
      • overlap

        public static double overlap​(SpatialComparable box1,
                                     SpatialComparable box2)
        Computes the volume of the overlapping box between two SpatialComparables.
        Parameters:
        box1 - the first SpatialComparable
        box2 - the second SpatialComparable
        Returns:
        the overlap volume.
      • relativeOverlap

        public static double relativeOverlap​(SpatialComparable box1,
                                             SpatialComparable box2)
        Computes the volume of the overlapping box between two SpatialComparables and return the relation between the volume of the overlapping box and the volume of both SpatialComparable.
        Parameters:
        box1 - the first SpatialComparable
        box2 - the second SpatialComparable
        Returns:
        the overlap volume in relation to the singular volumes.
      • union

        public static ModifiableHyperBoundingBox union​(SpatialComparable box1,
                                                       SpatialComparable box2)
        Computes the union HyperBoundingBox of two SpatialComparables.
        Parameters:
        box1 - the first SpatialComparable
        box2 - the second SpatialComparable
        Returns:
        the union HyperBoundingBox of this HyperBoundingBox and the given HyperBoundingBox
      • intersection

        public static ModifiableHyperBoundingBox intersection​(SpatialComparable box1,
                                                              SpatialComparable box2)
        Calculate the intersection of the two MBRs or null if they do not intersect. Note: if the given MBRs intersect in only one point of any dimension, this method still returns a result!
        Parameters:
        box1 - the first MBR
        box2 - the second MBR
        Returns:
        the union of the two specified MBRs
      • centroid

        public static double[] centroid​(SpatialComparable obj)
        Returns the centroid of this SpatialComparable.
        Parameters:
        obj - Spatial object to process
        Returns:
        the centroid of this SpatialComparable
      • equals

        public static boolean equals​(SpatialComparable box1,
                                     SpatialComparable box2)
        Test two SpatialComparables for equality.
        Parameters:
        box1 - First bounding box
        box2 - Second bounding box
        Returns:
        true when the boxes are equal