LineSubset3D.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.RegionEmbedding;
  19. import org.apache.commons.geometry.core.Sized;
  20. import org.apache.commons.geometry.core.partitioning.HyperplaneBoundedRegion;
  21. import org.apache.commons.geometry.euclidean.oned.Vector1D;
  22. import org.apache.commons.geometry.euclidean.threed.Bounds3D;
  23. import org.apache.commons.geometry.euclidean.threed.Vector3D;

  24. /** Class representing a subset of a line in 3D Euclidean space. For example, line segments,
  25.  * rays, and disjoint combinations of the two are line subsets. Line subsets may be finite or infinite.
  26.  */
  27. public abstract class LineSubset3D implements RegionEmbedding<Vector3D, Vector1D>, Sized {
  28.     /** The line containing this instance. */
  29.     private final Line3D line;

  30.     /** Construct a new instance based on the given line.
  31.      * @param line line containing the instance
  32.      */
  33.     LineSubset3D(final Line3D line) {
  34.         this.line = line;
  35.     }

  36.     /** Get the line containing this subset.
  37.      * @return the line containing this subset
  38.      */
  39.     public Line3D getLine() {
  40.         return line;
  41.     }

  42.     /** {@inheritDoc} */
  43.     @Override
  44.     public Vector3D toSpace(final Vector1D pt) {
  45.         return line.toSpace(pt);
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     public Vector1D toSubspace(final Vector3D pt) {
  50.         return line.toSubspace(pt);
  51.     }

  52.     /** Get the centroid, or geometric center, of the line subset or null if
  53.      * the subset is empty or infinite.
  54.      * @return the centroid of the line subset, or null if the subset is empty or
  55.      *      infinite
  56.      */
  57.     public abstract Vector3D getCentroid();

  58.     /** Get the 3D bounding box of the line subset or null if the subset is
  59.      * empty or infinite.
  60.      * @return the 3D bounding box the line subset or null if the subset is
  61.      *      empty or infinite
  62.      */
  63.     public abstract Bounds3D getBounds();

  64.     /** Get the subspace region for the instance.
  65.      * @return the subspace region for the instance
  66.      */
  67.     @Override
  68.     public abstract HyperplaneBoundedRegion<Vector1D> getSubspaceRegion();
  69. }