All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.graphbuilder.math.func.AvgFunction Maven / Gradle / Ivy

Go to download

Implementation of various mathematical curves that define themselves over a set of control points. The API is written in Java. The curves supported are: Bezier, B-Spline, Cardinal Spline, Catmull-Rom Spline, Lagrange, Natural Cubic Spline, and NURBS.

There is a newer version: 1.08
Show newest version
package com.graphbuilder.math.func;

/**
The average function.
*/
public class AvgFunction implements Function {

	public AvgFunction() {}

	/**
	Returns the average of the values in the array from [0, numParam).
	*/
	public double of(double[] d, int numParam) {
		double sum = 0;

		for (int i = 0; i < numParam; i++)
			sum += d[i];

		return sum / numParam;
	}

	/**
	Returns true for 1 or more parameters, false otherwise.
	*/
	public boolean acceptNumParam(int numParam) {
		return numParam > 0;
	}

	public String toString() {
		return "avg(x1, x2, ..., xn)";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy