1 package org.simantics.district.network.ui.nodes;
3 import java.awt.geom.AffineTransform;
4 import java.awt.geom.Point2D;
5 import java.awt.geom.Rectangle2D;
7 import org.simantics.district.network.ModelledCRS;
8 import org.simantics.maps.MapScalingTransform;
10 public class DistrictNetworkNodeUtils {
12 public static Rectangle2D calculateDrawnGeometry(Point2D p, Rectangle2D margin, Rectangle2D result, double scaleRecip) {
14 result = new Rectangle2D.Double();
15 double mw = margin.getWidth();
16 double mh = margin.getHeight();
17 result.setFrame(p.getX() - (mw / 2 * scaleRecip), p.getY() - (mh / 2 * scaleRecip), mw * scaleRecip, mh * scaleRecip);
21 public static Point2D calculatePoint2D(Point2D point, Point2D result) {
22 double x = ModelledCRS.longitudeToX(point.getX());
23 double y = ModelledCRS.latitudeToY(-point.getY()); // Inverse because Simantics Diagram is inverted
25 result = new Point2D.Double(x, y);
27 result.setLocation(x, y);
31 public static AffineTransform getTransformToRectangle(Rectangle2D toDraw, AffineTransform transform) {
32 if (transform == null)
33 transform = new AffineTransform();
35 transform.setTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY());
39 public static double calculateScaleRecip(AffineTransform tr) {
40 int zoomLevel = MapScalingTransform.zoomLevel(tr);
41 double t = 1.0 / Math.sqrt(zoomLevel);