InterpolatedFromSurfacesDoublesCube extends Cube<Double, Double, Double, Double> { @Override public Double getValue(final Double x, final Double y, final Double z) { Validate.notNull(x, "x"); Validate.notNull(y, "y"); Validate.notNull(z, "z"); final double[] values = new double[_nSurfaces]; int i = 0; double x1, y1, z1; switch (_plane) { case XY: x1 = x; y1 = y; z1 = z; break; case ZX: x1 = x; y1 = z; z1 = y; break; case YZ: x1 = y; y1 = z; z1 = x; break; default: throw new IllegalArgumentException("Cannot handle type " + _plane); } final int index = Arrays.binarySearch(_points, z1); if (index < 0) { for (final Surface<Double, Double, Double> surface : _surfaces) { values[i++] = surface.getZValue(x1, y1); } return InterpolatedDoublesCurve.fromSorted(_points, values, _interpolator).getYValue(z1); } return _surfaces[index].getZValue(x1, y1); } InterpolatedFromSurfacesDoublesCube(final Plane plane, final double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final boolean isSorted); @SuppressWarnings("unchecked")  InterpolatedFromSurfacesDoublesCube(final Plane plane, final Double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final boolean isSorted); @SuppressWarnings("unchecked")  InterpolatedFromSurfacesDoublesCube(final Plane plane, final List<Double> points, final List<Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final boolean isSorted); @SuppressWarnings("unchecked")  InterpolatedFromSurfacesDoublesCube(final Plane plane, final Map<Double, Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final boolean isSorted);  InterpolatedFromSurfacesDoublesCube(final Plane plane, final double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final boolean isSorted, final String name); @SuppressWarnings("unchecked")  InterpolatedFromSurfacesDoublesCube(final Plane plane, final Double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final boolean isSorted, final String name); @SuppressWarnings("unchecked")  InterpolatedFromSurfacesDoublesCube(final Plane plane, final List<Double> points, final List<Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final boolean isSorted, final String name); @SuppressWarnings("unchecked")  InterpolatedFromSurfacesDoublesCube(final Plane plane, final Map<Double, Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final boolean isSorted, final String name); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final Double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final List<Double> points, final List<Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final Map<Double, Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final String name); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final Double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final String name); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final List<Double> points, final List<Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final String name); static InterpolatedFromSurfacesDoublesCube from(final Plane plane, final Map<Double, Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final String name); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final Double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final List<Double> points, final List<Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final Map<Double, Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final String name); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final Double[] points, final Surface<Double, Double, Double>[] surfaces,
      final Interpolator1D interpolator, final String name); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final List<Double> points, final List<Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final String name); static InterpolatedFromSurfacesDoublesCube fromSorted(final Plane plane, final Map<Double, Surface<Double, Double, Double>> surfaces,
      final Interpolator1D interpolator, final String name); @Override Double[] getXData(); @Override Double[] getYData(); @Override Double[] getZData(); @Override Double[] getValues(); @Override int size(); @Override Double getValue(final Double x, final Double y, final Double z); @Override Double getValue(final Triple<Double, Double, Double> xyz); Plane getPlane(); double[] getPoints(); Surface<Double, Double, Double>[] getSurfaces(); Interpolator1D getInterpolator(); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test public void testCubes() { double x = 3; double y = 4; double z = A1; assertEquals(XY_CUBE.getValue(x, y, z), F2.evaluate(x, y), 0); assertEquals(XY_CUBE.getValue(new Triple<>(x, y, z)), F2.evaluate(x, y), 0); z = A1 * Math.random(); double lower = F1.evaluate(x, y); double higher = F2.evaluate(x, y); double value = (higher - lower) * (z / A1) + lower; assertEquals(XY_CUBE.getValue(x, y, z), value, 0); assertEquals(XY_CUBE.getValue(new Triple<>(x, y, z)), value, 0); x = 2.4; y = A2; z = 5.6; assertEquals(XZ_CUBE.getValue(x, y, z), F2.evaluate(x, z), 0); assertEquals(XZ_CUBE.getValue(new Triple<>(x, y, z)), F2.evaluate(x, z), 0); y = A1 * Math.random(); lower = F1.evaluate(x, z); higher = F2.evaluate(x, z); value = (higher - lower) * (y / A1) + lower; assertEquals(XZ_CUBE.getValue(x, y, z), value, 0); assertEquals(XZ_CUBE.getValue(new Triple<>(x, y, z)), value, 0); x = A0; y = 1.34; z = 5.6; assertEquals(YZ_CUBE.getValue(x, y, z), F1.evaluate(y, z), 0); assertEquals(YZ_CUBE.getValue(new Triple<>(x, y, z)), F1.evaluate(y, z), 0); x = A1 * Math.random(); lower = F1.evaluate(y, z); higher = F2.evaluate(y, z); value = (higher - lower) * (x / A1) + lower; assertEquals(YZ_CUBE.getValue(x, y, z), value, 0); assertEquals(YZ_CUBE.getValue(new Triple<>(x, y, z)), value, 0); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetValueWithNull1() { XY_CUBE.getValue(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetValueWithNull2() { XY_CUBE.getValue(null, 2., 3.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetValueWithNull3() { XY_CUBE.getValue(1., null, 3.); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testGetValueWithNull4() { XY_CUBE.getValue(1., 2., null); }