EuclideanVectorSum.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;

  18. import java.util.function.Consumer;
  19. import java.util.function.Supplier;

  20. /** Class representing a sum of Euclidean vectors.
  21.  * @param <V> Vector implementation type
  22.  */
  23. public abstract class EuclideanVectorSum<V extends EuclideanVector<V>>
  24.     implements Supplier<V>, Consumer<V> {

  25.     /** Add a vector to this instance. This method is an alias for {@link #add(EuclideanVector)}.
  26.      * @param vec vector to add
  27.      */
  28.     @Override
  29.     public void accept(final V vec) {
  30.         add(vec);
  31.     }

  32.     /** Add a vector to this instance.
  33.      * @param vec vector to add
  34.      * @return this instance
  35.      */
  36.     public abstract EuclideanVectorSum<V> add(V vec);

  37.     /** Add a scaled vector to this instance. In general, the result produced by this method
  38.      * will be more accurate than if the vector was scaled first and then added directly. In other
  39.      * words, {@code sum.addScale(scale, vec)} will generally produce a better result than
  40.      * {@code sum.add(vec.multiply(scale))}.
  41.      * @param scale scale factor
  42.      * @param vec vector to scale and add
  43.      * @return this instance
  44.      */
  45.     public abstract EuclideanVectorSum<V> addScaled(double scale, V vec);
  46. }