]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Penalty.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / routing / algorithm1 / Penalty.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in 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.g2d.routing.algorithm1;\r
13 \r
14 import org.simantics.g2d.routing.algorithm1.StaticRouter.Cost;\r
15 \r
16 public class Penalty {\r
17         static final double BEND_PENALTY = 1.0;\r
18         static final double CONNECTION_MARGINAL = 10.0;\r
19         static final Cost INFINITE_COST = new Cost(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);\r
20         \r
21         static final Penalty OBSTACLE_PENALTY = new Penalty(20.0, 0.0);\r
22         static final Penalty CONNECTION_SIDE_PENALTY = new Penalty(10.0, 0.0);\r
23         static final Penalty CONNECTION_CROSS_PENALTY = new Penalty(0.4, 2*CONNECTION_MARGINAL);\r
24         \r
25         double penalty;\r
26         double minDistance;     \r
27         \r
28         public Penalty(double penalty, double minDistance) {\r
29                 this.penalty = penalty;\r
30                 this.minDistance = minDistance;\r
31         }\r
32         \r
33         @Override\r
34         public int hashCode() {\r
35                 final int prime = 31;\r
36                 int result = 1;\r
37                 long temp;\r
38                 temp = Double.doubleToLongBits(minDistance);\r
39                 result = prime * result + (int) (temp ^ (temp >>> 32));\r
40                 temp = Double.doubleToLongBits(penalty);\r
41                 result = prime * result + (int) (temp ^ (temp >>> 32));\r
42                 return result;\r
43         }\r
44         @Override\r
45         public boolean equals(Object obj) {\r
46                 if (this == obj)\r
47                         return true;\r
48                 if (obj == null)\r
49                         return false;\r
50                 if (getClass() != obj.getClass())\r
51                         return false;\r
52                 Penalty other = (Penalty) obj;\r
53                 if (Double.doubleToLongBits(minDistance) != Double\r
54                         .doubleToLongBits(other.minDistance))\r
55                         return false;\r
56                 if (Double.doubleToLongBits(penalty) != Double\r
57                         .doubleToLongBits(other.penalty))\r
58                         return false;\r
59                 return true;\r
60         }\r
61         \r
62         \r
63 }\r