eightminuseight icon

Class w Static Properties

eightminuseight | PRO | 10/05/16 07:39:03 PM UTC | 0 ⭐ | 238 👁️ | Never ⏰ | []
JavaScript |

700 B

|

None

|

0 👍

/

0 👎

class Grid {
    static origin = {x: 0, y: 0};
    
    static aStaticMethodMultiply() {
        // multiply the two static origin props together
        console.log(Grid.origin.x * Grid.origin.y)
    }
    
    calculateDistanceFromOrigin(point: {x: number; y: number;}) {
        let xDist = (point.x - Grid.origin.x);
        let yDist = (point.y - Grid.origin.y);
        return Math.sqrt(xDist * xDist + yDist * yDist) / this.scale;
    }
    constructor (public scale: number) { }
}
 
let grid1 = new Grid(1.0);  // 1x scale
let grid2 = new Grid(5.0);  // 5x scale
 
console.log(grid1.calculateDistanceFromOrigin({x: 10, y: 10}));
console.log(grid2.calculateDistanceFromOrigin({x: 10, y: 10}));

Comments