Formatted source
[jalview.git] / src / MCview / Bond.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 package MCview;\r
20 \r
21 import java.awt.*;\r
22 \r
23 \r
24 public class Bond {\r
25     float[] start;\r
26     float[] end;\r
27     Color startCol;\r
28     Color endCol;\r
29     public myAtom at1;\r
30     public myAtom at2;\r
31 \r
32     public Bond(float[] start, float[] end, myAtom at1, myAtom at2) {\r
33         this.start = start;\r
34         this.end = end;\r
35         this.startCol = at1.color;\r
36         this.endCol = at2.color;\r
37         this.at1 = at1;\r
38         this.at2 = at2;\r
39     }\r
40 \r
41     public Bond(Bond bond) {\r
42         this.start = new float[3];\r
43 \r
44         this.start[0] = bond.start[0];\r
45         this.start[1] = bond.start[1];\r
46         this.start[2] = bond.start[2];\r
47 \r
48         this.end = new float[3];\r
49 \r
50         this.end[0] = bond.end[0];\r
51         this.end[1] = bond.end[1];\r
52         this.end[2] = bond.end[2];\r
53 \r
54         this.startCol = bond.startCol;\r
55         this.endCol = bond.endCol;\r
56     }\r
57 \r
58     public void print() {\r
59         System.out.println("Start " + start[0] + " " + start[1] + " " +\r
60             start[2]);\r
61         System.out.println("End   " + end[0] + " " + end[1] + " " + end[2]);\r
62     }\r
63 \r
64     public float length() {\r
65         float len = ((end[0] - start[0]) * (end[0] - start[0])) +\r
66             ((end[1] - start[1]) * (end[1] - start[1])) +\r
67             ((end[2] - start[2]) * (end[2] - start[2]));\r
68 \r
69         len = (float) (Math.sqrt(len));\r
70 \r
71         return len;\r
72     }\r
73 \r
74     public void translate(float x, float y, float z) {\r
75         start[0] = (start[0] + x);\r
76         end[0] = (end[0] + x);\r
77 \r
78         start[1] = (start[1] + y);\r
79         end[1] = (end[1] + y);\r
80 \r
81         start[2] = (start[2] + z);\r
82         end[2] = (end[2] + z);\r
83     }\r
84 }\r