LineConvexSubset3D.java

  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.euclidean.threed.line;

  18. import org.apache.commons.geometry.core.Transform;
  19. import org.apache.commons.geometry.euclidean.oned.Interval;
  20. import org.apache.commons.geometry.euclidean.threed.Vector3D;

  21. /** Class representing a convex subset of a line in 3D Euclidean space. Instances
  22.  * need not be finite, in which case the start or end point (or both) will be null.
  23.  * @see Lines3D
  24.  */
  25. public abstract class LineConvexSubset3D extends LineSubset3D {

  26.     /** Construct a new instance for the given line.
  27.      * @param line line containing this convex subset
  28.      */
  29.     LineConvexSubset3D(final Line3D line) {
  30.         super(line);
  31.     }

  32.     /** Get the start point for the line subset.
  33.      * @return the start point for the line subset, or null if no start point exists
  34.      */
  35.     public abstract Vector3D getStartPoint();

  36.     /** Get the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
  37.      * no start location exists.
  38.      * @return the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
  39.      *      no start location exists.
  40.      */
  41.     public abstract double getSubspaceStart();

  42.     /** Get the end point for the line subset.
  43.      * @return the end point for the line subset, or null if no end point exists.
  44.      */
  45.     public abstract Vector3D getEndPoint();

  46.     /** Get the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
  47.      * no end location exists.
  48.      * @return the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
  49.      *      no end location exists
  50.      */
  51.     public abstract double getSubspaceEnd();

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     public Interval getSubspaceRegion() {
  55.         final double start = getSubspaceStart();
  56.         final double end = getSubspaceEnd();

  57.         return Interval.of(start, end, getLine().getPrecision());
  58.     }

  59.     /** Get the 1D interval for the line subset. This method is an alias for {@link #getSubspaceRegion()}.
  60.      * @return the 1D interval for the line subset.
  61.      */
  62.     public Interval getInterval() {
  63.         return getSubspaceRegion();
  64.     }

  65.     /** Return true if the given point lies in the line subset.
  66.      * @param pt point to check
  67.      * @return true if the point lies in the line subset
  68.      */
  69.     public boolean contains(final Vector3D pt) {
  70.         final Line3D line = getLine();
  71.         return line.contains(pt) && containsAbscissa(line.abscissa(pt));
  72.     }

  73.     /** Transform this instance.
  74.      * @param transform the transform to apply
  75.      * @return a new, transformed instance
  76.      */
  77.     public abstract LineConvexSubset3D transform(Transform<Vector3D> transform);

  78.     /** Return true if the given abscissa value is contained in the line subset (ie, in the subspace region
  79.      * or one of its 1D boundaries).
  80.      * @param abscissa abscissa to check
  81.      * @return true if {@code abscissa} lies on the inside or boundary of the subspace region
  82.      */
  83.     abstract boolean containsAbscissa(double abscissa);
  84. }