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