GPL license added
[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 \r
20 package MCview;\r
21 \r
22 import java.awt.*;\r
23 \r
24 public class Bond {\r
25 \r
26   float start[];\r
27   float end[];\r
28 \r
29   Color startCol;\r
30   Color endCol;\r
31 \r
32   public myAtom at1;\r
33   public myAtom at2;\r
34 \r
35   public Bond(float[] start, float[] end, myAtom at1, myAtom at2) {\r
36     this.start    = start;\r
37     this.end      = end;\r
38     this.startCol = at1.color;\r
39     this.endCol   = at2.color;\r
40     this.at1      = at1;\r
41     this.at2      = at2;\r
42   }\r
43   public Bond(Bond bond) {\r
44     this.start    = new float[3];\r
45 \r
46     this.start[0] = bond.start[0];\r
47     this.start[1] = bond.start[1];\r
48     this.start[2] = bond.start[2];\r
49 \r
50     this.end    = new float[3];\r
51 \r
52     this.end[0] = bond.end[0];\r
53     this.end[1] = bond.end[1];\r
54     this.end[2] = bond.end[2];\r
55 \r
56     this.startCol = bond.startCol;\r
57     this.endCol   = bond.endCol;\r
58   }\r
59 \r
60   public void print() {\r
61     System.out.println("Start " + start[0] + " "+ start[1] + " " + start[2]);\r
62     System.out.println("End   " + end[0] + " "+ end[1] + " " + end[2]);\r
63   }\r
64 \r
65   public float length() {\r
66     float len = (end[0] - start[0])*(end[0] - start[0]) +\r
67                 (end[1] - start[1])*(end[1] - start[1]) +\r
68                 (end[2] - start[2])*(end[2] - start[2]);\r
69 \r
70     len = (float)(Math.sqrt(len));\r
71 \r
72     return len;\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