/* Copyright (C) 2014 A.Vontobel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The license is in LICENCE-GPL.txt.
* If not, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
*/
package net.sf.drawj2d.cmd.geom;
import org.hecl.*;
/**
* GeomMultiplyCmd implements the "geom.multiply"/"**" command, which
* scales a vector by multiplication.
*/
public class GeomMultiplyCmd implements Command {
boolean debug = false;
public GeomMultiplyCmd () {
}
@Override
public Thing cmdCode(Interp interp, Thing[] argv) throws HeclException {
assert argv.length > 0;
if (debug) System.out.println(argv[0].toString());
if (argv.length != 3) throw new HeclException ("Illegal nb of arguments.");
double factor;
Thing[] factorargv = ListThing.getArray(argv[1]);
if (factorargv.length != 1) throw new HeclException ("Illegal argument format. 'nb \"nb nb\"' expected.");
factor = NumberThing.asNumber(factorargv[0]).doubleValue();
double[] vector = new double[2];
Thing[] currentargv = ListThing.getArray(argv[2]);
if (currentargv.length != 2) throw new HeclException ("Illegal argument format. 'nb \"nb nb\"' expected.");
vector[0] = NumberThing.asNumber(currentargv[0]).doubleValue();
vector[1] = NumberThing.asNumber(currentargv[1]).doubleValue();
double[] result = vector;
result[0] *= factor;
result[1] *= factor;
String xstr = StringThing.get(DoubleThing.create(result[0]));
String ystr = StringThing.get(DoubleThing.create(result[1]));
String answer = xstr + " " + ystr;
return new Thing(answer);
}
}
Ads help maintain this website.