01 
02 /*
03  *  JScripter Standard 1.0 - To Script In Java
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package jsx.motion;
21 
22 
23 /**
24  * <p>Defines motions with various regular mathematical functions.</p>
25  * <p>A regular function is a unitary mathematical function whose domain is between 0 and 1 
26  * inclusive, and value range is from -1 to 1. A regular function can be a combination of 
27  * other regular functions.</p>
28  * 
29  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
30  */
31 public abstract class Regular extends Motion
32 {
33     /**
34      * <p>The default constructor doing nothing but being invoked from a subclass and 
35      * invoking the default constructor of the superclass.</p>
36      * @since 1.0
37      */
38     protected Regular() {}
39 
40     /**
41      * <p>Gets the datum of a float number for the specified step.</p>
42      * @param i The step number. It must be within the number of steps previously initialized 
43      * with the method {@link Motion#init(int)}.
44      * @return The float datum for the <tt>i</tt>th step.
45      * @since 1.0
46      */
47     @Override
48     public final double get(int i) {
49         return call(this, ((double)i) / steps(this));
50     }
51 
52     /**
53      * <p>Computes and returns the value, depending on a specified variable, of a 
54      * specified regular function.</p>
55      * <p>This method simply calls {@link #function(double)} on the specified regular 
56      * function and returns the result. This static method exists only for the {@link #function(double)} 
57      * body of a defined regular function to be callable in any subclasses of this one 
58      * regardless of its visibility.</p>
59      * @param r The regular function.
60      * @param x The independent variable.
61      * @return The value, depending on the variable <tt>x</tt>, of the regular function 
62      * <tt>r</tt>.
63      * @since 1.0
64      */
65     protected static final double call(Regular r, double x) {
66         return r.function(x);
67     }
68 
69     /**
70      * <p>Computes and returns the value, depending on a specified variable, of the 
71      * regular function defined by this class.</p>
72      * @param x The independent variable.
73      * @return The value, depending on <tt>x</tt>, of the defined regular function.
74      * @since 1.0
75      */
76     protected abstract double function(double x);
77 }