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.euclidean;
018
019import java.util.function.Consumer;
020import java.util.function.Supplier;
021
022/** Class representing a sum of Euclidean vectors.
023 * @param <V> Vector implementation type
024 */
025public abstract class EuclideanVectorSum<V extends EuclideanVector<V>>
026    implements Supplier<V>, Consumer<V> {
027
028    /** Add a vector to this instance. This method is an alias for {@link #add(EuclideanVector)}.
029     * @param vec vector to add
030     */
031    @Override
032    public void accept(final V vec) {
033        add(vec);
034    }
035
036    /** Add a vector to this instance.
037     * @param vec vector to add
038     * @return this instance
039     */
040    public abstract EuclideanVectorSum<V> add(V vec);
041
042    /** Add a scaled vector to this instance. In general, the result produced by this method
043     * will be more accurate than if the vector was scaled first and then added directly. In other
044     * words, {@code sum.addScale(scale, vec)} will generally produce a better result than
045     * {@code sum.add(vec.multiply(scale))}.
046     * @param scale scale factor
047     * @param vec vector to scale and add
048     * @return this instance
049     */
050    public abstract EuclideanVectorSum<V> addScaled(double scale, V vec);
051}