1 /*
2 * jcurl java curling software framework http://www.jcurl.org
3 * Copyright (C) 2005-2009 M. Rohrmoser
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 * Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 package org.jcurl.math;
20
21 import java.io.Serializable;
22
23 /**
24 * Abstract base class for n-dimensional curves <code>f : R^1 -> R^n</code>.
25 *
26 * @author <a href="mailto:m@jcurl.org">M. Rohrmoser </a>
27 * @version $Id: R1RNFunctionImpl.java 1031 2009-07-23 15:06:05Z mro $
28 */
29 public abstract class R1RNFunctionImpl implements R1RNFunction, Serializable {
30
31 private final transient int dim;
32
33 protected R1RNFunctionImpl(final int dim) {
34 this.dim = dim;
35 }
36
37 public double[] at(final double t, final int c, double[] ret) {
38 if (ret == null)
39 ret = new double[dim];
40 for (int i = dim - 1; i >= 0; i--)
41 ret[i] = this.at(t, c, i);
42 return ret;
43 }
44
45 public float[] at(final double t, final int c, float[] ret) {
46 if (ret == null)
47 ret = new float[dim];
48 for (int i = dim - 1; i >= 0; i--)
49 ret[i] = (float) this.at(t, c, i);
50 return ret;
51 }
52
53 public abstract double at(double t, int c, int dim);
54
55 public final int dim() {
56 return dim;
57 }
58 }