LineSpanningSubset.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.twod;

  18. import java.text.MessageFormat;

  19. import org.apache.commons.geometry.core.RegionLocation;
  20. import org.apache.commons.geometry.core.Transform;
  21. import org.apache.commons.geometry.core.partitioning.Split;

  22. /** Class representing the span of a line in 2D Euclidean space. This is the set of all points
  23.  * contained by the line.
  24.  *
  25.  * <p>Instances of this class are guaranteed to be immutable.</p>
  26.  */
  27. final class LineSpanningSubset extends LineConvexSubset {

  28.     /** Construct a new instance for the given line.
  29.      * @param line line to construct the span for
  30.      */
  31.     LineSpanningSubset(final Line line) {
  32.         super(line);
  33.     }

  34.     /** {@inheritDoc}
  35.      *
  36.      * <p>This method always returns {@code true}.</p>
  37.      */
  38.     @Override
  39.     public boolean isFull() {
  40.         return true;
  41.     }

  42.     /** {@inheritDoc}
  43.     *
  44.     * <p>This method always returns {@code true}.</p>
  45.     */
  46.     @Override
  47.     public boolean isInfinite() {
  48.         return true;
  49.     }

  50.     /** {@inheritDoc}
  51.     *
  52.     * <p>This method always returns {@code false}.</p>
  53.     */
  54.     @Override
  55.     public boolean isFinite() {
  56.         return false;
  57.     }

  58.     /** {@inheritDoc}
  59.     *
  60.     * <p>This method always returns {@link Double#POSITIVE_INFINITY}.</p>
  61.     */
  62.     @Override
  63.     public double getSize() {
  64.         return Double.POSITIVE_INFINITY;
  65.     }

  66.     /** {@inheritDoc}
  67.      *
  68.      * <p>This method always returns {@code null}.</p>
  69.      */
  70.     @Override
  71.     public Vector2D getCentroid() {
  72.         return null;
  73.     }

  74.     /** {@inheritDoc}
  75.     *
  76.     * <p>This method always returns {@code null}.</p>
  77.     */
  78.     @Override
  79.     public Vector2D getStartPoint() {
  80.         return null;
  81.     }

  82.     /** {@inheritDoc}
  83.     *
  84.     * <p>This method always returns {@link Double#NEGATIVE_INFINITY}.</p>
  85.     */
  86.     @Override
  87.     public double getSubspaceStart() {
  88.         return Double.NEGATIVE_INFINITY;
  89.     }

  90.     /** {@inheritDoc}
  91.     *
  92.     * <p>This method always returns {@code null}.</p>
  93.     */
  94.     @Override
  95.     public Vector2D getEndPoint() {
  96.         return null;
  97.     }

  98.     /** {@inheritDoc}
  99.      *
  100.      * <p>This method always returns {@link Double#POSITIVE_INFINITY}.</p>
  101.      */
  102.     @Override
  103.     public double getSubspaceEnd() {
  104.         return Double.POSITIVE_INFINITY;
  105.     }

  106.     /** {@inheritDoc}
  107.     *
  108.     * <p>This method always returns {@code null}.</p>
  109.     */
  110.     @Override
  111.     public Bounds2D getBounds() {
  112.         return null; // infinite; no bounds
  113.     }

  114.     /** {@inheritDoc} */
  115.     @Override
  116.     public LineSpanningSubset transform(final Transform<Vector2D> transform) {
  117.         return new LineSpanningSubset(getLine().transform(transform));
  118.     }

  119.     /** {@inheritDoc} */
  120.     @Override
  121.     public LineSpanningSubset reverse() {
  122.         return new LineSpanningSubset(getLine().reverse());
  123.     }

  124.     /** {@inheritDoc} */
  125.     @Override
  126.     public String toString() {
  127.         final Line line = getLine();

  128.         return MessageFormat.format(Line.TO_STRING_FORMAT,
  129.                 getClass().getSimpleName(),
  130.                 line.getOrigin(),
  131.                 line.getDirection());
  132.     }

  133.     /** {@inheritDoc} */
  134.     @Override
  135.     RegionLocation classifyAbscissa(final double abscissa) {
  136.         return RegionLocation.INSIDE;
  137.     }

  138.     /** {@inheritDoc} */
  139.     @Override
  140.     double closestAbscissa(final double abscissa) {
  141.         return abscissa;
  142.     }

  143.     /** {@inheritDoc} */
  144.     @Override
  145.     Split<LineConvexSubset> splitOnIntersection(final Line splitter, final Vector2D intersection) {
  146.         final Line line = getLine();

  147.         final ReverseRay low = new ReverseRay(line, intersection);
  148.         final Ray high = new Ray(line, intersection);

  149.         return createSplitResult(splitter, low, high);
  150.     }
  151. }