]> gerrit.simantics Code Review - simantics/district.git/blob
8a369e26391d9efb77e458891824617f9a9c9231
[simantics/district.git] /
1 package org.simantics.district.network.ui.nodes;
2
3 import java.awt.geom.AffineTransform;
4 import java.awt.geom.Point2D;
5 import java.awt.geom.Rectangle2D;
6
7 import org.simantics.district.network.ModelledCRS;
8
9 public class DistrictNetworkNodeUtils {
10
11     public static Rectangle2D calculateDrawnGeometry(Point2D p, Rectangle2D margin, Rectangle2D result, double scaleRecip) {
12         if (result == null)
13             result = new Rectangle2D.Double();
14         double mw = margin.getWidth();
15         double mh = margin.getHeight();
16         result.setFrame(p.getX() - (mw / 2 * scaleRecip), p.getY() - (mh / 2 * scaleRecip), mw * scaleRecip, mh * scaleRecip);
17         return result;
18     }
19
20     public static Point2D calculatePoint2D(Point2D point, Point2D result) {
21         double x = ModelledCRS.longitudeToX(point.getX());
22         double y = ModelledCRS.latitudeToY(-point.getY()); // Inverse because Simantics Diagram is inverted
23         if (result == null)
24             result = new Point2D.Double(x, y);
25         else
26             result.setLocation(x, y);
27         return result;
28     }
29
30     public static AffineTransform getTransformToRectangle(Rectangle2D toDraw, AffineTransform transform) {
31         if (transform == null)
32             transform = new AffineTransform();
33
34         transform.setTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY());
35         return transform;
36     }
37
38 }