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.Collection; 020import java.util.List; 021import java.util.stream.Collectors; 022 023/** This interface defines mappings between a space and one of its subspaces. 024 025 * <p>Subspaces are the lower-dimension subsets of a space. For example, 026 * in an n-dimension space, the subspaces are the (n-1) dimension space, 027 * the (n-2) dimension space, and so on. This interface can be used regardless 028 * of the difference in number of dimensions between the space and the target 029 * subspace. For example, a line in 3D Euclidean space can use this interface 030 * to map directly from 3D Euclidean space to 1D Euclidean space (ie, the location 031 * along the line).</p> 032 * 033 * @param <P> Point type defining the embedding space. 034 * @param <S> Point type defining the embedded subspace. 035 */ 036public interface Embedding<P extends Point<P>, S extends Point<S>> { 037 038 /** Transform a space point into a subspace point. 039 * @param pt n-dimension point of the space 040 * @return lower-dimension point of the subspace corresponding to 041 * the specified space point 042 * @see #toSpace 043 */ 044 S toSubspace(P pt); 045 046 /** Transform a collection of space points into subspace points. 047 * @param pts collection of n-dimension points to transform 048 * @return collection of transformed lower-dimension points. 049 * @see #toSubspace(Point) 050 */ 051 default List<S> toSubspace(final Collection<P> pts) { 052 return pts.stream().map(this::toSubspace).collect(Collectors.toList()); 053 } 054 055 /** Transform a subspace point into a space point. 056 * @param pt lower-dimension point of the subspace 057 * @return n-dimension point of the space corresponding to the 058 * specified subspace point 059 * @see #toSubspace(Point) 060 */ 061 P toSpace(S pt); 062 063 /** Transform a collection of subspace points into space points. 064 * @param pts collection of lower-dimension points to transform 065 * @return collection of transformed n-dimension points. 066 * @see #toSpace(Point) 067 */ 068 default List<P> toSpace(final Collection<S> pts) { 069 return pts.stream().map(this::toSpace).collect(Collectors.toList()); 070 } 071}