001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.geometry.euclidean.threed.line;
018
019import org.apache.commons.geometry.core.Transform;
020import org.apache.commons.geometry.euclidean.oned.Interval;
021import org.apache.commons.geometry.euclidean.threed.Vector3D;
022
023/** Class representing a convex subset of a line in 3D Euclidean space. Instances
024 * need not be finite, in which case the start or end point (or both) will be null.
025 * @see Lines3D
026 */
027public abstract class LineConvexSubset3D extends LineSubset3D {
028
029    /** Construct a new instance for the given line.
030     * @param line line containing this convex subset
031     */
032    LineConvexSubset3D(final Line3D line) {
033        super(line);
034    }
035
036    /** Get the start point for the line subset.
037     * @return the start point for the line subset, or null if no start point exists
038     */
039    public abstract Vector3D getStartPoint();
040
041    /** Get the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
042     * no start location exists.
043     * @return the 1D start location of the line subset or {@link Double#NEGATIVE_INFINITY} if
044     *      no start location exists.
045     */
046    public abstract double getSubspaceStart();
047
048    /** Get the end point for the line subset.
049     * @return the end point for the line subset, or null if no end point exists.
050     */
051    public abstract Vector3D getEndPoint();
052
053    /** Get the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
054     * no end location exists.
055     * @return the 1D end location of the line subset or {@link Double#POSITIVE_INFINITY} if
056     *      no end location exists
057     */
058    public abstract double getSubspaceEnd();
059
060    /** {@inheritDoc} */
061    @Override
062    public Interval getSubspaceRegion() {
063        final double start = getSubspaceStart();
064        final double end = getSubspaceEnd();
065
066        return Interval.of(start, end, getLine().getPrecision());
067    }
068
069    /** Get the 1D interval for the line subset. This method is an alias for {@link #getSubspaceRegion()}.
070     * @return the 1D interval for the line subset.
071     */
072    public Interval getInterval() {
073        return getSubspaceRegion();
074    }
075
076    /** Return true if the given point lies in the line subset.
077     * @param pt point to check
078     * @return true if the point lies in the line subset
079     */
080    public boolean contains(final Vector3D pt) {
081        final Line3D line = getLine();
082        return line.contains(pt) && containsAbscissa(line.abscissa(pt));
083    }
084
085    /** Transform this instance.
086     * @param transform the transform to apply
087     * @return a new, transformed instance
088     */
089    public abstract LineConvexSubset3D transform(Transform<Vector3D> transform);
090
091    /** Return true if the given abscissa value is contained in the line subset (ie, in the subspace region
092     * or one of its 1D boundaries).
093     * @param abscissa abscissa to check
094     * @return true if {@code abscissa} lies on the inside or boundary of the subspace region
095     */
096    abstract boolean containsAbscissa(double abscissa);
097}