import PerspT from 'perspective-transform';
import config from './config';

class Transformer {
    constructor(srcCorners) {
        this.dstCorners = [0, 0, config.canvasWidth, 0, config.canvasWidth, config.canvasWidth / config.screenRatio, 0, config.canvasWidth / config.screenRatio];
        this.updatePerspective(srcCorners);
    }

    updatePerspective(srcCorners) {
        this.perspT = PerspT(srcCorners || this.dstCorners, this.dstCorners);
    }

    transform({x, y}) {
        const result = this.perspT.transform(x, y);
        return {
            x: result[0],
            y: result[1],
        };
    }
}

export default new Transformer();

@@ -285,25 +285,23 @@
 o%5D;%0A    
+%7D%0A%0A
     
-this.
 updatePe
@@ -325,53 +325,107 @@
 ers)
-;
+ %7B
 %0A    
-%7D%0A%0A    updatePerspective(srcCorners) %7B%0A
+    if (!this.perspT) %7B%0A            console.log('PerspT', srcCorners, this.dstCorners);%0A    
     
@@ -463,27 +463,8 @@
 ners
- %7C%7C this.dstCorners
 , th
@@ -475,24 +475,34 @@
 stCorners);%0A
+        %7D%0A
     %7D%0A%0A    t
@@ -516,24 +516,96 @@
 m(%7Bx, y%7D) %7B%0A
+        if (!this.perspT) %7B%0A            return %7Bx: x, y: y%7D;%0A        %7D%0A%0A
         cons

update perspectives only 1st time