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 @ 43983

History | View | Annotate | Download (2.05 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
        );
28
    }
29

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