]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Small fix for SWTDPIUtil to prevent uninitialized use 97/2197/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 17 Sep 2018 12:34:42 +0000 (15:34 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 17 Sep 2018 12:41:14 +0000 (15:41 +0300)
gitlab #119

Change-Id: I27779078dca87927b9700a1acc3b26aed7cca308

bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTDPIUtil.java

index 962276432b223fa1138ef3f2a9f6628f02b6ecad..43d19efb2571cd987d380de84f9b8d0b824b795e 100644 (file)
@@ -105,17 +105,42 @@ public class SWTDPIUtil {
                return target;
        }
 
                return target;
        }
 
+       private static double downscaleSwt0(double x) {
+               return hasSwtScale ? x * fromSwtInternalScalingFactorD : x;
+       }
+
+       private static int downscaleToIntegerSwt0(double x) {
+               return (int)(hasSwtScale ? Math.round((double) x * fromSwtInternalScalingFactorD) : x);
+       }
+
+       private static int downscaleSwt0(int x) {
+               return hasSwtScale ? (int) Math.round((double) x * fromSwtInternalScalingFactorD) : x;
+       }
+
+       private static double upscaleSwt0(double x) {
+               return hasSwtScale ? x * toSwtInternalScalingFactorD : x;
+       }
+
+       private static int upscaleToIntegerSwt0(double x) {
+               return (int)(hasSwtScale ? Math.round((double) x * toSwtInternalScalingFactorD) : x);
+       }
+
+       private static int upscaleSwt0(int x) {
+               return hasSwtScale ? (int) Math.round((double) x * toSwtInternalScalingFactorD) : x;
+       }
+
        // SWT API Coordinates <-> pixels
 
        // SWT API Coordinates <-> pixels
 
+       // Downscaling
+
        public static double downscaleSwt(double x) {
                initialize();
        public static double downscaleSwt(double x) {
                initialize();
-               return hasSwtScale ? x * fromSwtInternalScalingFactorD : x;
+               return downscaleSwt0(x);
        }
 
        public static int downscaleSwt(int x) {
        }
 
        public static int downscaleSwt(int x) {
-               if (!hasSwtScale)
-                       return x;
-               return (int) Math.round(downscaleSwt((double) x));
+               initialize();
+               return downscaleSwt0(x);
        }
 
        public static Point2D downscaleSwt(double x, double y) {
        }
 
        public static Point2D downscaleSwt(double x, double y) {
@@ -127,7 +152,8 @@ public class SWTDPIUtil {
        }
 
        public static Point downscaleSwt(int x, int y) {
        }
 
        public static Point downscaleSwt(int x, int y) {
-               return new Point(downscaleSwt(x), downscaleSwt(y));
+               initialize();
+               return new Point(downscaleSwt0(x), downscaleSwt0(y));
        }
 
        public static Point2D downscaleSwt(Point2D p) {
        }
 
        public static Point2D downscaleSwt(Point2D p) {
@@ -135,9 +161,8 @@ public class SWTDPIUtil {
        }
 
        public static Point downscaleSwtToInteger(Point2D p) {
        }
 
        public static Point downscaleSwtToInteger(Point2D p) {
-               return new Point(
-                               (int) Math.round(downscaleSwt(p.getX())),
-                               (int) Math.round(downscaleSwt(p.getY())));
+               initialize();
+               return new Point(downscaleToIntegerSwt0(p.getX()), downscaleToIntegerSwt0(p.getY()));
        }
 
        public static Rectangle2D downscaleSwt(Rectangle2D r, Rectangle2D target) {
        }
 
        public static Rectangle2D downscaleSwt(Rectangle2D r, Rectangle2D target) {
@@ -159,26 +184,28 @@ public class SWTDPIUtil {
        }
 
        public static Rectangle downscaleSwtToInteger(Rectangle2D r) {
        }
 
        public static Rectangle downscaleSwtToInteger(Rectangle2D r) {
+               initialize();
                return new Rectangle( 
                return new Rectangle( 
-                               (int) Math.round(downscaleSwt(r.getMinX())),
-                               (int) Math.round(downscaleSwt(r.getMinY())),
-                               (int) Math.round(downscaleSwt(r.getWidth())),
-                               (int) Math.round(downscaleSwt(r.getHeight())));
+                               downscaleToIntegerSwt0(r.getMinX()),
+                               downscaleToIntegerSwt0(r.getMinY()),
+                               downscaleToIntegerSwt0(r.getWidth()),
+                               downscaleToIntegerSwt0(r.getHeight()));
        }
 
        }
 
+       // Upscaling
+
        public static double upscaleSwt(double x) {
                initialize();
        public static double upscaleSwt(double x) {
                initialize();
-               return hasSwtScale ? x * toSwtInternalScalingFactorD : x;
+               return upscaleSwt0(x);
        }
 
        public static int upscaleSwt(int x) {
                initialize();
        }
 
        public static int upscaleSwt(int x) {
                initialize();
-               if (!hasSwtScale)
-                       return x;
-               return (int) Math.round((double) x * toSwtInternalScalingFactorD);
+               return upscaleSwt0(x);
        }
 
        public static Point2D upscaleSwt(double x, double y) {
        }
 
        public static Point2D upscaleSwt(double x, double y) {
+               initialize();
                if (!hasSwtScale)
                        return new Point2D.Double(x, y);
                double s = toSwtInternalScalingFactorD;
                if (!hasSwtScale)
                        return new Point2D.Double(x, y);
                double s = toSwtInternalScalingFactorD;
@@ -186,7 +213,8 @@ public class SWTDPIUtil {
        }
 
        public static Point upscaleSwt(int x, int y) {
        }
 
        public static Point upscaleSwt(int x, int y) {
-               return new Point(upscaleSwt(x), upscaleSwt(y));
+               initialize();
+               return new Point(upscaleSwt0(x), upscaleSwt0(y));
        }
 
        public static Point2D upscaleSwt(Point2D p) {
        }
 
        public static Point2D upscaleSwt(Point2D p) {
@@ -194,9 +222,8 @@ public class SWTDPIUtil {
        }
 
        public static Point upscaleSwtToInteger(Point2D p) {
        }
 
        public static Point upscaleSwtToInteger(Point2D p) {
-               return new Point(
-                               (int) Math.round(upscaleSwt(p.getX())),
-                               (int) Math.round(upscaleSwt(p.getY())));
+               initialize();
+               return new Point(upscaleToIntegerSwt0(p.getX()), upscaleToIntegerSwt0(p.getY()));
        }
 
        public static Point upscaleSwt(Point p) {
        }
 
        public static Point upscaleSwt(Point p) {
@@ -223,10 +250,10 @@ public class SWTDPIUtil {
 
        public static Rectangle upscaleSwtToInteger(Rectangle2D r) {
                return new Rectangle( 
 
        public static Rectangle upscaleSwtToInteger(Rectangle2D r) {
                return new Rectangle( 
-                               (int) Math.round(upscaleSwt(r.getMinX())),
-                               (int) Math.round(upscaleSwt(r.getMinY())),
-                               (int) Math.round(upscaleSwt(r.getWidth())),
-                               (int) Math.round(upscaleSwt(r.getHeight())));
+                               upscaleToIntegerSwt0(r.getMinX()),
+                               upscaleToIntegerSwt0(r.getMinY()),
+                               upscaleToIntegerSwt0(r.getWidth()),
+                               upscaleToIntegerSwt0(r.getHeight()));
        }
 
 }
        }
 
 }