View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.commons.geometry.spherical;
    18
    19  import org.apache.commons.geometry.core.Region;
    20  import org.apache.commons.geometry.core.RegionLocation;
    21  import org.apache.commons.geometry.core.precision.EpsilonDoublePrecisionContext;
    22  import org.apache.commons.geometry.euclidean.threed.Vector3D;
    23  import org.apache.commons.geometry.spherical.oned.Point1S;
    24  import org.apache.commons.geometry.spherical.twod.Point2S;
    25  import org.junit.Assert;
    26
    27  /** Class containing various test utilities for spherical space.
    28   */
    29  public final class SphericalTestUtils {
    30
    31      /** Private constructor. */
    32      private SphericalTestUtils() {}
    33
    34      /** Assert that the given points are equal, using the specified tolerance value.
    35       * @param expected
    36       * @param actual
    37       * @param tolerance
    38       */
    39      public static void assertPointsEqual(final Point1S expected, final Point1S actual, final double tolerance) {
    40          final String msg = "Expected point to equal " + expected + " but was " + actual + ";";
    41          Assert.assertEquals(msg, expected.getAzimuth(), actual.getAzimuth(), tolerance);
    42      }
    43
    44      /** Assert that the given points are equal, using the specified tolerance value.
    45       * @param expected
    46       * @param actual
    47       * @param tolerance
    48       */
    49      public static void assertPointsEqual(final Point2S expected, final Point2S actual, final double tolerance) {
    50          final String msg = "Expected point to equal " + expected + " but was " + actual + ";";
    51          Assert.assertEquals(msg, expected.getAzimuth(), actual.getAzimuth(), tolerance);
    52          Assert.assertEquals(msg, expected.getPolar(), actual.getPolar(), tolerance);
    53      }
    54
    55      /** Assert that the given points are equivalent, using the specified tolerance value.
    56       * @param expected
    57       * @param actual
    58       * @param tolerance
    59       */
    60      public static void assertPointsEq(final Point2S expected, final Point2S actual, final double tolerance) {
    61          final String msg = "Expected point to be equivalent to " + expected + " but was " + actual + ";";
    62          Assert.assertTrue(msg, expected.eq(actual, new EpsilonDoublePrecisionContext(tolerance)));
    63      }
    64
    65      /** Assert that the given vectors are equal, using the specified tolerance value.
    66       * @param expected
    67       * @param actual
    68       * @param tolerance
    69       */
    70      public static void assertVectorsEqual(final Vector3D expected, final Vector3D actual, final double tolerance) {
    71          final String msg = "Expected vector to equal " + expected + " but was " + actual + ";";
    72          Assert.assertEquals(msg, expected.getX(), actual.getX(), tolerance);
    73          Assert.assertEquals(msg, expected.getY(), actual.getY(), tolerance);
    74          Assert.assertEquals(msg, expected.getZ(), actual.getZ(), tolerance);
    75      }
    76
    77      /** Assert that the given points lie in the specified location relative to the region.
    78       * @param region region to test
    79       * @param loc expected location of the given points
    80       * @param pts points to test
    81       */
    82      public static void checkClassify(final Region<Point2S> region, final RegionLocation loc, final Point2S... pts) {
    83          for (final Point2S pt : pts) {
    84              Assert.assertEquals("Unexpected location for point " + pt, loc, region.classify(pt));
    85          }
    86      }
    87  }