]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/RoutePoint.java
70450e9666ab394a7b095d5fc79934796629dd96
[simantics/platform.git] / bundles / org.simantics.diagram.connection / src / org / simantics / diagram / connection / RoutePoint.java
1 /*******************************************************************************\r
2  * Copyright (c) 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.diagram.connection;\r
13 \r
14 import gnu.trove.map.hash.THashMap;\r
15 \r
16 import java.util.Comparator;\r
17 \r
18 public abstract class RoutePoint {\r
19     \r
20     public static final Comparator<RoutePoint> X_COMPARATOR = new Comparator<RoutePoint>() {\r
21         @Override\r
22         public int compare(RoutePoint a, RoutePoint b) {\r
23             return Double.compare(a.x, b.x);\r
24         }\r
25     };\r
26     \r
27     public static final Comparator<RoutePoint> Y_COMPARATOR = new Comparator<RoutePoint>() {\r
28         @Override\r
29         public int compare(RoutePoint a, RoutePoint b) {\r
30             return Double.compare(a.y, b.y);\r
31         }\r
32     };\r
33     \r
34     double x;\r
35     double y;\r
36 \r
37     public RoutePoint() {\r
38     }\r
39     \r
40     public RoutePoint(double x, double y) {\r
41         this.x = x;\r
42         this.y = y;\r
43     }\r
44     \r
45     public double getX() {\r
46         return x;\r
47     }\r
48     \r
49     public double getY() {\r
50         return y;\r
51     }\r
52 \r
53     void removeFromOther(RouteLine routeLine) {\r
54     }\r
55 \r
56     public boolean isNear(double x2, double y2, double tolerance) {\r
57         double dx = x2-x;\r
58         double dy = y2-y;\r
59         \r
60         return dx*dx + dy*dy <= tolerance*tolerance;\r
61     }\r
62 \r
63         abstract RoutePoint copy(THashMap<Object, Object> map);\r
64         \r
65         \r
66         public void setX(double x) {\r
67                 this.x = x;\r
68         }\r
69         \r
70         public void setY(double y) {\r
71                 this.y = y;\r
72         }\r
73 }\r