Selaa lähdekoodia

Simplify

customisations
alemart 9 kuukautta sitten
vanhempi
commit
0580637bfc
1 muutettua tiedostoa jossa 10 lisäystä ja 11 poistoa
  1. 10
    11
      src/core/viewport.ts

+ 10
- 11
src/core/viewport.ts Näytä tiedosto

@@ -997,23 +997,23 @@ export class Viewport extends ViewportEventTarget
997 997
     convertToPixels(position: Vector2, space: "normalized" | "adjusted" = 'normalized'): Vector2
998 998
     {
999 999
         const canvas = this.canvas;
1000
-        let mx = 1, my = 1;
1000
+        let px = position.x, py = position.y;
1001 1001
 
1002 1002
         if(space == 'adjusted') {
1003 1003
             // convert from adjusted to normalized space
1004 1004
             const a = canvas.width / canvas.height;
1005 1005
 
1006 1006
             if(a >= 1)
1007
-                my *= a;
1007
+                py *= a;
1008 1008
             else
1009
-                mx /= a;
1009
+                px /= a;
1010 1010
         }
1011 1011
         else if(space != 'normalized')
1012 1012
             throw new IllegalArgumentError(`Invalid space: "${space}"`);
1013 1013
 
1014 1014
         // convert from normalized to canvas space
1015
-        const x = 0.5 * (1 + position.x * mx) * canvas.width;
1016
-        const y = 0.5 * (1 - position.y * my) * canvas.height;
1015
+        const x = 0.5 * (1 + px) * canvas.width;
1016
+        const y = 0.5 * (1 - py) * canvas.height;
1017 1017
 
1018 1018
         // done!
1019 1019
         return new Vector2(x, y);
@@ -1029,26 +1029,25 @@ export class Viewport extends ViewportEventTarget
1029 1029
     convertFromPixels(position: Vector2, space: "normalized" | "adjusted" = 'normalized'): Vector2
1030 1030
     {
1031 1031
         const canvas = this.canvas;
1032
-        let mx = 1, my = 1;
1033 1032
 
1034 1033
         // convert from canvas to normalized space
1035
-        const x = 2 * position.x / canvas.width - 1;
1036
-        const y = -2 * position.y / canvas.height + 1;
1034
+        let x = 2 * position.x / canvas.width - 1;
1035
+        let y = -2 * position.y / canvas.height + 1;
1037 1036
 
1038 1037
         if(space == 'adjusted') {
1039 1038
             // convert from normalized to adjusted space
1040 1039
             const a = canvas.width / canvas.height;
1041 1040
 
1042 1041
             if(a >= 1)
1043
-                my /= a;
1042
+                y /= a;
1044 1043
             else
1045
-                mx *= a;
1044
+                x *= a;
1046 1045
         }
1047 1046
         else if(space != 'normalized')
1048 1047
             throw new IllegalArgumentError(`Invalid space: "${space}"`);
1049 1048
 
1050 1049
         // done!
1051
-        return new Vector2(x * mx, y * my);
1050
+        return new Vector2(x, y);
1052 1051
     }
1053 1052
 
1054 1053
     /**

Loading…
Peruuta
Tallenna