]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/utils/GridSpacing.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / utils / GridSpacing.java
index 55a385776c314a983b0bd6e43d47881a8f4d3fa9..3702bc4b1a5a2923b1ca55291b1bfb81792d04af 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.g2d.utils;\r
-\r
-import java.io.Serializable;\r
-\r
-import org.simantics.scenegraph.utils.GridUtils;\r
-\r
-\r
-/**\r
- * Grid configuration.\r
- * \r
- * @author Tuukka Lehtonen\r
- * @author Marko Luukkainen\r
- * @author Toni Kalajainen\r
- */\r
-public final class GridSpacing implements Serializable {\r
-\r
-    private static final long serialVersionUID = 8445639004963828463L;\r
-\r
-    /** When the view scale gets beneath this value a grid should no longer be shown */\r
-    public static final double GRID_MIN_USER_SIZE = 1e-6;\r
-\r
-       public static final GridSpacing SOME_SPACING = GridSpacing.makeGridSpacing(100, 100, 40);\r
-    \r
-    /** The minimum amount of pixel between major grid lines. */\r
-    public double      minPixels;\r
-\r
-    /** Grid segment sizes (canvas coordinates) */\r
-    public double              segment, segmentExp;\r
-\r
-    /** Conversions between canvas (unit) and control (pixel) */\r
-    public double              pixelsPerUnit;\r
-    public double      unitsPerPixel;\r
-\r
-    public double              pixelsPerSegment;\r
-    \r
-    public GridSpacing(double spacing, double spacingExp, double unitsPerPixel, double minPixels)\r
-    {\r
-        this.unitsPerPixel = unitsPerPixel;\r
-        pixelsPerUnit = 1 / unitsPerPixel;\r
-        this.segment = spacing; \r
-        this.segmentExp = spacingExp;\r
-        pixelsPerSegment = spacing * pixelsPerUnit;\r
-        this.minPixels = minPixels;\r
-    }\r
-\r
-    @Override\r
-    public boolean equals(Object obj) {\r
-       if (obj == null) return false;\r
-       if (obj == this) return true;\r
-        if (obj instanceof GridSpacing == false) return false;\r
-        GridSpacing g2 = (GridSpacing)obj;\r
-        if(pixelsPerUnit != g2.pixelsPerUnit) return false;\r
-        if(pixelsPerSegment != g2.pixelsPerSegment) return false;\r
-        if(unitsPerPixel != g2.unitsPerPixel) return false;\r
-        if(segment != g2.segment) return false;\r
-        if(segmentExp != g2.segmentExp) return false;\r
-        return true;\r
-    }\r
-\r
-    /**\r
-     * Calculates grid cofiguration\r
-     * \r
-     * @return grid configuration \r
-     */\r
-    public static GridSpacing makeGridSpacing(\r
-               double viewboxSize,  \r
-               double controlWidth,  \r
-               double minPixels)\r
-    {\r
-        if (controlWidth==0) controlWidth = 1;\r
-        if (Math.abs(viewboxSize) < GRID_MIN_USER_SIZE) viewboxSize = GRID_MIN_USER_SIZE * Math.signum(viewboxSize);\r
-\r
-        double unitsPerPixel = viewboxSize / Math.max(controlWidth, minPixels);\r
-        double [] gridSpacing = getGridSpacing(unitsPerPixel, minPixels);\r
-        return new GridSpacing(gridSpacing[0], gridSpacing[1], unitsPerPixel, minPixels);\r
-    }\r
-\r
-    public static GridSpacing makeGridSpacingForTime(\r
-               double viewboxSize,  \r
-               double controlWidth,  \r
-               double minPixels)\r
-    {\r
-        if (controlWidth==0) controlWidth = 1;\r
-        if (viewboxSize < GRID_MIN_USER_SIZE) viewboxSize = 1;\r
-\r
-        double unitsPerPixel = viewboxSize / Math.max(controlWidth, minPixels);\r
-        double [] gridSpacing = getGridSpacing(unitsPerPixel, minPixels);\r
-        return new GridSpacing(gridSpacing[0], gridSpacing[1], unitsPerPixel, minPixels);\r
-    }\r
-    \r
-    private static double[] getGridSpacing(double unitsPerPixel, double minPixels) {\r
-        double minGridSize = minPixels * unitsPerPixel;\r
-        double[] gridSpacing = GridUtils.getEvenGridSpacingWithExp(minGridSize, new double[2]);\r
-        return gridSpacing;\r
-    }\r
-\r
-    /**\r
-     * Snap point to the grid. The snapping is based on grid last paint operation.\r
-     * \r
-     * @param pos\r
-     * @return\r
-     */\r
-    public double snapToGrid(double pos) {\r
-        return GridUtils.snapToGrid(pos, segment);\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.g2d.utils;
+
+import java.io.Serializable;
+
+import org.simantics.scenegraph.utils.GridUtils;
+
+
+/**
+ * Grid configuration.
+ * 
+ * @author Tuukka Lehtonen
+ * @author Marko Luukkainen
+ * @author Toni Kalajainen
+ */
+public final class GridSpacing implements Serializable {
+
+    private static final long serialVersionUID = 8445639004963828463L;
+
+    /** When the view scale gets beneath this value a grid should no longer be shown */
+    public static final double GRID_MIN_USER_SIZE = 1e-6;
+
+       public static final GridSpacing SOME_SPACING = GridSpacing.makeGridSpacing(100, 100, 40);
+    
+    /** The minimum amount of pixel between major grid lines. */
+    public double      minPixels;
+
+    /** Grid segment sizes (canvas coordinates) */
+    public double              segment, segmentExp;
+
+    /** Conversions between canvas (unit) and control (pixel) */
+    public double              pixelsPerUnit;
+    public double      unitsPerPixel;
+
+    public double              pixelsPerSegment;
+    
+    public GridSpacing(double spacing, double spacingExp, double unitsPerPixel, double minPixels)
+    {
+        this.unitsPerPixel = unitsPerPixel;
+        pixelsPerUnit = 1 / unitsPerPixel;
+        this.segment = spacing; 
+        this.segmentExp = spacingExp;
+        pixelsPerSegment = spacing * pixelsPerUnit;
+        this.minPixels = minPixels;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+       if (obj == null) return false;
+       if (obj == this) return true;
+        if (obj instanceof GridSpacing == false) return false;
+        GridSpacing g2 = (GridSpacing)obj;
+        if(pixelsPerUnit != g2.pixelsPerUnit) return false;
+        if(pixelsPerSegment != g2.pixelsPerSegment) return false;
+        if(unitsPerPixel != g2.unitsPerPixel) return false;
+        if(segment != g2.segment) return false;
+        if(segmentExp != g2.segmentExp) return false;
+        return true;
+    }
+
+    /**
+     * Calculates grid cofiguration
+     * 
+     * @return grid configuration 
+     */
+    public static GridSpacing makeGridSpacing(
+               double viewboxSize,  
+               double controlWidth,  
+               double minPixels)
+    {
+        if (controlWidth==0) controlWidth = 1;
+        if (Math.abs(viewboxSize) < GRID_MIN_USER_SIZE) viewboxSize = GRID_MIN_USER_SIZE * Math.signum(viewboxSize);
+
+        double unitsPerPixel = viewboxSize / Math.max(controlWidth, minPixels);
+        double [] gridSpacing = getGridSpacing(unitsPerPixel, minPixels);
+        return new GridSpacing(gridSpacing[0], gridSpacing[1], unitsPerPixel, minPixels);
+    }
+
+    public static GridSpacing makeGridSpacingForTime(
+               double viewboxSize,  
+               double controlWidth,  
+               double minPixels)
+    {
+        if (controlWidth==0) controlWidth = 1;
+        if (viewboxSize < GRID_MIN_USER_SIZE) viewboxSize = 1;
+
+        double unitsPerPixel = viewboxSize / Math.max(controlWidth, minPixels);
+        double [] gridSpacing = getGridSpacing(unitsPerPixel, minPixels);
+        return new GridSpacing(gridSpacing[0], gridSpacing[1], unitsPerPixel, minPixels);
+    }
+    
+    private static double[] getGridSpacing(double unitsPerPixel, double minPixels) {
+        double minGridSize = minPixels * unitsPerPixel;
+        double[] gridSpacing = GridUtils.getEvenGridSpacingWithExp(minGridSize, new double[2]);
+        return gridSpacing;
+    }
+
+    /**
+     * Snap point to the grid. The snapping is based on grid last paint operation.
+     * 
+     * @param pos
+     * @return
+     */
+    public double snapToGrid(double pos) {
+        return GridUtils.snapToGrid(pos, segment);
+    }
+
+}