View Javadoc

    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
    19  import java.util.List;
    20
    21  /** Interface for objects that support linecast operations in Euclidean 2D space.
    22   *
    23   * <p>
    24   * Linecasting is a process that takes a line or convex line subset and intersects it with
    25   * the boundaries of a region. This is similar to
    26   * <a href="https://en.wikipedia.org/wiki/Ray_casting">raycasting</a> used
    27   * for collision detection with the exception that the intersecting element can be a
    28   * line or convex line subset and not just a ray.
    29   * </p>
    30   */
    31  public interface Linecastable2D {
    32
    33      /** Intersect the given line against the boundaries in this instance, returning a
    34       * list of all intersections in order of increasing position along the line. An empty
    35       * list is returned if no intersections are discovered.
    36       * @param line line the line to intersect
    37       * @return a list of computed intersections in order of increasing position
    38       *      along the line
    39       */
    40      default List<LinecastPoint2D> linecast(final Line line) {
    41          return linecast(line.span());
    42      }
    43
    44      /** Intersect the given line subset against the boundaries in this instance, returning
    45       * a list of all intersections in order of increasing position along the line. An empty
    46       * list is returned if no intersections are discovered.
    47       * @param subset line subset to intersect
    48       * @return a list of computed intersections in order of increasing position
    49       *      along the line
    50       */
    51      List<LinecastPoint2D> linecast(LineConvexSubset subset);
    52
    53      /** Intersect the given line against the boundaries in this instance, returning
    54       * the first intersection found when traveling in the direction of the line from
    55       * infinity.
    56       * @param line the line to intersect
    57       * @return the first intersection found or null if no intersection
    58       *      is found
    59       */
    60      default LinecastPoint2D linecastFirst(final Line line) {
    61          return linecastFirst(line.span());
    62      }
    63
    64      /** Intersect the given line subset against the boundaries in this instance, returning
    65       * the first intersection found when traveling in the direction of the line subset
    66       * from its start location.
    67       * @param subset line subset to intersect
    68       * @return the first intersection found or null if no intersection
    69       *      is found
    70       */
    71      LinecastPoint2D linecastFirst(LineConvexSubset subset);
    72  }