Linecastable2D.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.util.List;

  19. /** Interface for objects that support linecast operations in Euclidean 2D space.
  20.  *
  21.  * <p>
  22.  * Linecasting is a process that takes a line or convex line subset and intersects it with
  23.  * the boundaries of a region. This is similar to
  24.  * <a href="https://en.wikipedia.org/wiki/Ray_casting">raycasting</a> used
  25.  * for collision detection with the exception that the intersecting element can be a
  26.  * line or convex line subset and not just a ray.
  27.  * </p>
  28.  */
  29. public interface Linecastable2D {

  30.     /** Intersect the given line against the boundaries in this instance, returning a
  31.      * list of all intersections in order of increasing position along the line. An empty
  32.      * list is returned if no intersections are discovered.
  33.      * @param line line the line to intersect
  34.      * @return a list of computed intersections in order of increasing position
  35.      *      along the line
  36.      */
  37.     default List<LinecastPoint2D> linecast(final Line line) {
  38.         return linecast(line.span());
  39.     }

  40.     /** Intersect the given line subset against the boundaries in this instance, returning
  41.      * a list of all intersections in order of increasing position along the line. An empty
  42.      * list is returned if no intersections are discovered.
  43.      * @param subset line subset to intersect
  44.      * @return a list of computed intersections in order of increasing position
  45.      *      along the line
  46.      */
  47.     List<LinecastPoint2D> linecast(LineConvexSubset subset);

  48.     /** Intersect the given line against the boundaries in this instance, returning
  49.      * the first intersection found when traveling in the direction of the line from
  50.      * infinity.
  51.      * @param line the line to intersect
  52.      * @return the first intersection found or null if no intersection
  53.      *      is found
  54.      */
  55.     default LinecastPoint2D linecastFirst(final Line line) {
  56.         return linecastFirst(line.span());
  57.     }

  58.     /** Intersect the given line subset against the boundaries in this instance, returning
  59.      * the first intersection found when traveling in the direction of the line subset
  60.      * from its start location.
  61.      * @param subset line subset to intersect
  62.      * @return the first intersection found or null if no intersection
  63.      *      is found
  64.      */
  65.     LinecastPoint2D linecastFirst(LineConvexSubset subset);
  66. }