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;
9 public class DistrictNetworkNodeUtils {
11 public static Rectangle2D calculateDrawnGeometry(Point2D p, Rectangle2D margin, Rectangle2D result, double scaleRecip) {
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);
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
24 result = new Point2D.Double(x, y);
26 result.setLocation(x, y);
30 public static AffineTransform getTransformToRectangle(Rectangle2D toDraw, AffineTransform transform) {
31 if (transform == null)
32 transform = new AffineTransform();
34 transform.setTransform(toDraw.getWidth(), 0.0, 0.0, toDraw.getHeight(), toDraw.getCenterX(), toDraw.getCenterY());