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.RegionEmbedding;
020import org.apache.commons.geometry.core.Sized;
021import org.apache.commons.geometry.core.partitioning.HyperplaneBoundedRegion;
022import org.apache.commons.geometry.euclidean.oned.Vector1D;
023import org.apache.commons.geometry.euclidean.threed.Bounds3D;
024import org.apache.commons.geometry.euclidean.threed.Vector3D;
025
026/** Class representing a subset of a line in 3D Euclidean space. For example, line segments,
027 * rays, and disjoint combinations of the two are line subsets. Line subsets may be finite or infinite.
028 */
029public abstract class LineSubset3D implements RegionEmbedding<Vector3D, Vector1D>, Sized {
030    /** The line containing this instance. */
031    private final Line3D line;
032
033    /** Construct a new instance based on the given line.
034     * @param line line containing the instance
035     */
036    LineSubset3D(final Line3D line) {
037        this.line = line;
038    }
039
040    /** Get the line containing this subset.
041     * @return the line containing this subset
042     */
043    public Line3D getLine() {
044        return line;
045    }
046
047    /** {@inheritDoc} */
048    @Override
049    public Vector3D toSpace(final Vector1D pt) {
050        return line.toSpace(pt);
051    }
052
053    /** {@inheritDoc} */
054    @Override
055    public Vector1D toSubspace(final Vector3D pt) {
056        return line.toSubspace(pt);
057    }
058
059    /** Get the centroid, or geometric center, of the line subset or null if
060     * the subset is empty or infinite.
061     * @return the centroid of the line subset, or null if the subset is empty or
062     *      infinite
063     */
064    public abstract Vector3D getCentroid();
065
066    /** Get the 3D bounding box of the line subset or null if the subset is
067     * empty or infinite.
068     * @return the 3D bounding box the line subset or null if the subset is
069     *      empty or infinite
070     */
071    public abstract Bounds3D getBounds();
072
073    /** Get the subspace region for the instance.
074     * @return the subspace region for the instance
075     */
076    @Override
077    public abstract HyperplaneBoundedRegion<Vector1D> getSubspaceRegion();
078}