sascha@422: package de.intevation.gnv.jfreechart;
sascha@422:
sascha@422: import java.io.Serializable;
sascha@422:
sascha@422: /**
sascha@780: * @author Sascha Teichmann
sascha@780: * @author Ingo Weinzierl
sascha@422: */
sascha@422: public class CompactXYItems
sascha@422: implements Serializable
sascha@422: {
sascha@422: protected double [] data;
sascha@422:
sascha@422: public CompactXYItems(double [] data) {
sascha@422: this.data = data;
sascha@422: }
sascha@422:
sascha@422: public double getX(int index) {
sascha@422: return data[index << 1];
sascha@422: }
sascha@422:
sascha@422: public double getY(int index) {
sascha@422: return data[(index << 1)+1];
sascha@422: }
sascha@422:
sascha@422: public void get(int index, double [] xy) {
sascha@422: xy[0] = data[index = (index << 1) + 1];
sascha@422: xy[1] = data[index + 1];
sascha@422: }
sascha@422:
sascha@422: public double [] getData() {
sascha@422: return data;
sascha@422: }
sascha@422:
sascha@422: public void setData(double [] data) {
sascha@422: this.data = data;
sascha@422: }
sascha@422:
sascha@422: public int size() {
sascha@422: return data.length >> 1;
sascha@422: }
sascha@422:
sascha@422: public double [] calculateBoundingBox(double [] bbox) {
sascha@422: for (int i = 0; i < data.length;) {
sascha@422: double x = data[i++];
sascha@422: double y = data[i++];
sascha@422: if (x < bbox[0]) bbox[0] = x;
sascha@422: if (y < bbox[1]) bbox[1] = y;
sascha@422: if (x > bbox[2]) bbox[2] = x;
sascha@422: if (y > bbox[3]) bbox[3] = y;
sascha@422: }
sascha@422: return bbox;
sascha@422: }
sascha@422:
sascha@422: public String toString() {
sascha@422: StringBuilder sb = new StringBuilder();
sascha@422: for (int i = 0; i < data.length;) {
sascha@422: if (i > 0) sb.append("; ");
sascha@422: sb.append('(');
sascha@422: sb.append(data[i++]);
sascha@422: sb.append(", ");
sascha@422: sb.append(data[i++]);
sascha@422: sb.append(')');
sascha@422: }
sascha@422: return sb.toString();
sascha@422: }
sascha@422:
sascha@422:
sascha@422: public double getMinX() {
sascha@422: double lower = Double.POSITIVE_INFINITY;
sascha@422:
sascha@422: for (int i = 0; i < data.length; i += 2) {
sascha@422: double x = data[i];
sascha@422:
sascha@422: if (!Double.isNaN(x)) {
sascha@422: lower = Math.min(lower, x);
sascha@422: }
sascha@422: }
sascha@422:
sascha@422: return lower;
sascha@422: }
sascha@422:
sascha@422:
sascha@422: public double getMaxX() {
sascha@422: double upper = Double.NEGATIVE_INFINITY;
sascha@422:
sascha@422: for (int i = 0; i < data.length; i += 2) {
sascha@422: double x = data[i];
sascha@422:
sascha@422: if (!Double.isNaN(x)) {
sascha@422: upper = Math.max(upper, x);
sascha@422: }
sascha@422: }
sascha@422:
sascha@422: return upper;
sascha@422: }
sascha@422:
sascha@422:
sascha@422: public double getMinY() {
sascha@422: double lower = Double.POSITIVE_INFINITY;
sascha@422:
sascha@422: for (int i = 1; i < data.length; i += 2) {
sascha@422: double y = data[i];
sascha@422:
sascha@422: if (!Double.isNaN(y)) {
sascha@422: lower = Math.min(lower, y);
sascha@422: }
sascha@422: }
sascha@422:
sascha@422: return lower;
sascha@422: }
sascha@422:
sascha@422:
sascha@422: public double getMaxY() {
sascha@422: double upper = Double.NEGATIVE_INFINITY;
sascha@422:
sascha@422: for (int i = 1; i < data.length; i += 2) {
sascha@422: double y = data[i];
sascha@422:
sascha@422: if (!Double.isNaN(y)) {
sascha@422: upper = Math.max(upper, y);
sascha@422: }
sascha@422: }
sascha@422:
sascha@422: return upper;
sascha@422: }
sascha@422: }
sascha@422: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :