Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / numeric / AffineTransformFunction.java @ 43989

History | View | Annotate | Download (2.06 KB)

1
package org.gvsig.expressionevaluator.impl.function.numeric;
2

    
3
import java.awt.geom.AffineTransform;
4
import org.apache.commons.lang3.Range;
5
import org.gvsig.expressionevaluator.Interpreter;
6
import org.gvsig.expressionevaluator.spi.AbstractFunction;
7

    
8
public class AffineTransformFunction extends AbstractFunction {
9

    
10
    public AffineTransformFunction() {
11
        super(
12
            "Numeric", 
13
            "AffineTransform", 
14
            Range.between(0, 6),
15
            "With 0 parameters create an AffineTransform representing the Identity transformation\n" +
16
            "With 6 parameters create an AffineTransform with the 6 specifiable entries of the 3x3 transformation matrix.",
17
            "AffineTransform({{m00}}, m10, m01, m11, m02, m12)",
18
            new String[]{
19
                "m00 - the X coordinate scaling element of the 3x3 matrix",
20
                "m10 - the Y coordinate shearing element of the 3x3 matrix",
21
                "m01 - the X coordinate shearing element of the 3x3 matrix",
22
                "m11 - the Y coordinate scaling element of the 3x3 matrix",
23
                "m02 - the X coordinate translation element of the 3x3 matrix",
24
                "m12 - the Y coordinate translation element of the 3x3 matrix"
25
            },
26
            "AffineTransform",
27
            false
28
        );
29
    }
30

    
31
    @Override
32
    public Object call(Interpreter interpreter, Object[] args) {
33
        AffineTransform at;
34
        switch(args.length) {
35
            case 0:
36
                at = new AffineTransform();
37
                return at;
38
            case 6:
39
                double m00 = getDouble(args, 0);
40
                double m10 = getDouble(args, 0);
41
                double m01 = getDouble(args, 0);
42
                double m11 = getDouble(args, 0);
43
                double m02 = getDouble(args, 0);
44
                double m12 = getDouble(args, 0);
45
                at = new AffineTransform(m00, m10, m01, m11, m02, m12);
46
                return at;
47
            default:
48
                throw new IllegalArgumentException("The AffinaTransform function requires 0 or 6 parameters.");
49
        }
50
    }
51
}