Debian Codegraph @

src/dr/geo/contouring/ContourPath.java

raw symbols SCIP
1 /*
2 * ContourPath.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.geo.contouring;
27
28 import dr.geo.contouring.ContourAttrib;
29
30
31 /**
32 * <p> This object represents a single contour line or
33 * path and all the data that is associated with
34 * it.
35 * </p>
36 *
37 * <p> Modified by: Joseph A. Huwaldt </p>
38 *
39 * @author Joseph A. Huwaldt Date: November 11, 2000
40 * @version November 17, 2000
41 *
42 *
43 * @author Marc Suchard
44 **/
45 public class ContourPath implements Cloneable, java.io.Serializable {
46
47 // Tolerance for path closure.
48 private static final double kSmallX = 0.001;
49 private static final double kSmallY = kSmallX;
50
51 // X & Y coordinate arrays.
52 private double[] xArr, yArr;
53
54 // The level index for this contour path.
55 private int levelIndex;
56
57 // Indicates if this path is open or closed.
58 private boolean closed = false;
59
60 // The attributes assigned to this contour level.
61 private ContourAttrib attributes;
62
63
64 /**
65 * Construct a contour path or line using the given arrays
66 * of X & Y values.
67 *
68 * @param attr Attributes assigned to this contour path.
69 * @param levelIndex The index to then level this path belongs to.
70 * @param x Array of X coordinate values.
71 * @param y Array of Y coordinate values.
72 **/
73 public ContourPath(ContourAttrib attr, int levelIndex, double[] x, double[] y) {
74
75 xArr = x;
76 yArr = y;
77 this.levelIndex = levelIndex;
78 attributes = attr;
79 int np = xArr.length;
80
81 // Determine if the contour path is open or closed.
82 if (Math.abs(x[0] - x[np-1]) < kSmallX && Math.abs(y[0] - y[np-1]) < kSmallY) {
83 closed = true;
84 x[np-1] = x[0]; y[np-1] = y[0]; // Guarantee closure.
85 } else
86 closed = false; // Contour not closed.
87
88 }
89
90
91 /**
92 * Return the X coordinate values for this contour path.
93 **/
94 public double[] getAllX() {
95 return xArr;
96 }
97
98 /**
99 * Return the Y coordinate values for this contour path.
100 **/
101 public double[] getAllY() {
102 return yArr;
103 }
104
105 /**
106 * Return the level index for this contour path. The level index
107 * is an index to the level that this path belongs to: the i'th level.
108 **/
109 public int getLevelIndex() {
110 return levelIndex;
111 }
112
113 /**
114 * Return the attributes assigned to this contour path.
115 **/
116 public ContourAttrib getAttributes() {
117 return attributes;
118 }
119
120 /**
121 * Returns true if this contour path is closed (loops back
122 * on itself) or false if it is not.
123 **/
124 public boolean isClosed() {
125 return closed;
126 }
127
128 /**
129 * Make a copy of this ContourPath object.
130 *
131 * @return Returns a clone of this object.
132 **/
133 public Object clone() {
134 ContourPath newObject = null;
135
136 try {
137 // Make a shallow copy of this object.
138 newObject = (ContourPath) super.clone();
139
140 // There is no "deep" data to be cloned.
141
142 } catch (CloneNotSupportedException e) {
143 // Can't happen.
144 e.printStackTrace();
145 }
146
147 // Output the newly cloned object.
148 return newObject;
149 }
150
151
152 }