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.core;
018
019import java.util.function.UnaryOperator;
020
021/** Interface representing geometric transforms in a space, i.e. mappings from points to points.
022 * Implementations <em>must</em> fulfill a set of requirements, listed below, that preserve the
023 * consistency of partitionings on the space. Transforms that do not meet these requirements, while
024 * potentially valid mathematically, cannot be expected to produce correct results with algorithms
025 * that use this interface.
026 *
027 * <ol>
028 *      <li>Transforms must represent functions that are <em>one-to-one</em> and <em>onto</em> (i.e.
029 *      <a href="https://en.wikipedia.org/wiki/Bijection">bijections</a>). This means that every point
030 *      in the space must be mapped to exactly one other point in the space. This also implies that the
031 *      function is invertible.</li>
032 *      <li>Transforms must preserve <a href="https://en.wikipedia.org/wiki/Collinearity">collinearity</a>.
033 *      This means that if a set of points lie on a common hyperplane before the transform, then they must
034 *      also lie on a common hyperplane after the transform. For example, if the Euclidean 2D points {@code a},
035 *      {@code b}, and {@code c} lie on line {@code L}, then the transformed points {@code a'}, {@code b'}, and
036 *      {@code c'} must lie on line {@code L'}, where {@code L'} is the transformed form of the line.</li>
037 *      <li>Transforms must preserve the concept of
038 *      <a href="https://en.wikipedia.org/wiki/Parallel_(geometry)">parallelism</a> defined for the space.
039 *      This means that hyperplanes that are parallel before the transformation must remain parallel afterwards,
040 *      and hyperplanes that intersect must also intersect afterwards. For example, a transform that causes parallel
041 *      lines to converge to a single point in Euclidean space (such as the projective transforms used to create
042 *      perspective viewpoints in 3D graphics) would not meet this requirement. However, a transform that turns
043 *      a square into a rhombus with no right angles would fulfill the requirement, since the two pairs of parallel
044 *      lines forming the square remain parallel after the transformation.
045 *      </li>
046 * </ol>
047 *
048 * <p>Transforms that meet the above requirements in Euclidean space (and other affine spaces) are known as
049 * <a href="https://en.wikipedia.org/wiki/Affine_transformation">affine transforms</a>. Common affine transforms
050 * include translation, scaling, rotation, reflection, and any compositions thereof.
051 * </p>
052 *
053 * @param <P> Point implementation type
054 * @see <a href="https://en.wikipedia.org/wiki/Geometric_transformation">Geometric Transformation</a>
055 */
056public interface Transform<P extends Point<P>> extends UnaryOperator<P> {
057
058    /** Get an instance representing the inverse transform.
059     * @return an instance representing the inverse transform
060     */
061    Transform<P> inverse();
062
063    /** Return true if the transform preserves the orientation of the space.
064     * For example, in Euclidean 2D space, this will be true for translations,
065     * rotations, and scalings but will be false for reflections.
066     * @return true if the transform preserves the orientation of the space
067     * @see <a href="https://en.wikipedia.org/wiki/Orientation_(vector_space)">Orientation</a>
068     */
069    boolean preservesOrientation();
070}