haxekineticjs

Creating Haxe extern, return types


I'm trying to make an extern of KineticJS for Haxe. And I'm making the 'Transform' class, I'm missing a few pieces though.

extern class Transform {
    public function new();
    public function translate(x:Float, y:Float):Void;
    public function scale(sx:Float, sy:Float):Void;
    public function rotate(rad:Float):Void;

    /**
     * Returns the translation
     * @returns {Object} 2D point(x, y)
     */
    getTranslation: function() {
        return {
            x: this.m[4],
            y: this.m[5]
        };
    },

    public function multiply(matrix:Transform):Void;
    public function invert():Void;
    
    /**
     * return matrix
     */
    getMatrix: function() {
        return this.m;
    }
}

So, as you can see I'm missing getTranslation and getMatrix. This is because I'm not sure what their return type should be.

For those wondering, the m variable is defined as follows:

Kinetic.Transform = function() {
    this.m = [1, 0, 0, 1, 0, 0];
}

Solution

  • Given m is storing a matrix, it should be an Array<Float>.

    The return type of getTranslation is a structure.

    So at the end the functions should be:

    public function getMatrix():Array<Float>;
    
    public function getTranslation():{ x:Float, y:Float };