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; 18 19 import java.util.function.Consumer; 20 import java.util.function.Supplier; 21 22 /** Class representing a sum of Euclidean vectors. 23 * @param <V> Vector implementation type 24 */ 25 public abstract class EuclideanVectorSum<V extends EuclideanVector<V>> 26 implements Supplier<V>, Consumer<V> { 27 28 /** Add a vector to this instance. This method is an alias for {@link #add(EuclideanVector)}. 29 * @param vec vector to add 30 */ 31 @Override 32 public void accept(final V vec) { 33 add(vec); 34 } 35 36 /** Add a vector to this instance. 37 * @param vec vector to add 38 * @return this instance 39 */ 40 public abstract EuclideanVectorSum<V> add(V vec); 41 42 /** Add a scaled vector to this instance. In general, the result produced by this method 43 * will be more accurate than if the vector was scaled first and then added directly. In other 44 * words, {@code sum.addScale(scale, vec)} will generally produce a better result than 45 * {@code sum.add(vec.multiply(scale))}. 46 * @param scale scale factor 47 * @param vec vector to scale and add 48 * @return this instance 49 */ 50 public abstract EuclideanVectorSum<V> addScaled(double scale, V vec); 51 }