--- /dev/null
+package org.simantics.district.network.ui.nodes;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+
+import org.simantics.district.network.ModelledCRS;
+
+public class DistrictNetworkNodeUtils {
+
+ public static Rectangle2D calculateDrawnGeometry(Point2D p, Rectangle2D margin, Rectangle2D result, double scaleRecip) {
+ if (result == null)
+ result = new Rectangle2D.Double();
+ double mw = margin.getWidth();
+ double mh = margin.getHeight();
+ result.setFrame(p.getX() - (mw / 2 * scaleRecip), p.getY() - (mh / 2 * scaleRecip), mw * scaleRecip, mh * scaleRecip);
+ return result;
+ }
+
+ public static Point2D calculatePoint2D(Point2D point, Point2D result) {
+ double x = ModelledCRS.longitudeToX(point.getX());
+ double y = ModelledCRS.latitudeToY(-point.getY()); // Inverse because Simantics Diagram is inverted
+ if (result == null)
+ result = new Point2D.Double(x, y);
+ else
+ result.setLocation(x, y);
+ return result;
+ }
+
+ public static AffineTransform getTransformToRectangle(Rectangle2D toDraw, AffineTransform transform) {
+ if (transform == null)
+ transform = new AffineTransform();
+
+ transform.setTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY());
+ return transform;
+ }
+
+}