comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java @ 2558:33e4481933e2

WstValueTable: Added method to find the w extent for a given km range. flys-artifacts/trunk@4080 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 17 Feb 2012 11:59:30 +0000
parents adb8641f5b5d
children 407bbc74fe0b
comparison
equal deleted inserted replaced
2557:adb8641f5b5d 2558:33e4481933e2
495 } 495 }
496 496
497 return qs.toNativeArray(); 497 return qs.toNativeArray();
498 } 498 }
499 499
500 public double [] getMinMaxW() { 500 public double [] getMinMaxW(double [] result) {
501 double minW = Double.MAX_VALUE; 501 double minW = Double.MAX_VALUE;
502 double maxW = -Double.MAX_VALUE; 502 double maxW = -Double.MAX_VALUE;
503 for (int i = 0; i < ws.length; ++i) { 503 for (int i = 0; i < ws.length; ++i) {
504 double w = ws[i]; 504 double w = ws[i];
505 if (w < minW) minW = w; 505 if (w < minW) minW = w;
506 if (w > maxW) maxW = w; 506 if (w > maxW) maxW = w;
507 } 507 }
508 return new double [] { minW, maxW }; 508 result[0] = minW;
509 } 509 result[1] = maxW;
510 510 return result;
511 public double [] getMinMaxW(Row other, double km) { 511 }
512 double [] m1 = this .getMinMaxW(); 512
513 double [] m2 = other.getMinMaxW(); 513 public double [] getMinMaxW(Row other, double km, double [] result) {
514 double [] m1 = this .getMinMaxW(new double [2]);
515 double [] m2 = other.getMinMaxW(new double [2]);
514 double factor = Linear.factor(km, this.km, other.km); 516 double factor = Linear.factor(km, this.km, other.km);
515 return new double [] { 517 result[0] = Linear.weight(factor, m1[0], m2[0]);
516 Linear.weight(factor, m1[0], m2[0]), 518 result[1] = Linear.weight(factor, m1[1], m2[1]);
517 Linear.weight(factor, m1[1], m2[1]) 519 return result;
518 };
519 } 520 }
520 } // class Row 521 } // class Row
521 522
522 /** Rows in table. */ 523 /** Rows in table. */
523 protected List<Row> rows; 524 protected List<Row> rows;
605 606
606 return ws; 607 return ws;
607 } 608 }
608 609
609 public double [] getMinMaxW(double km) { 610 public double [] getMinMaxW(double km) {
611 return getMinMaxW(km, new double [2]);
612
613 }
614 public double [] getMinMaxW(double km, double [] result) {
610 int rowIndex = Collections.binarySearch(rows, new Row(km)); 615 int rowIndex = Collections.binarySearch(rows, new Row(km));
611 616
612 if (rowIndex >= 0) { 617 if (rowIndex >= 0) {
613 return rows.get(rowIndex).getMinMaxW(); 618 return rows.get(rowIndex).getMinMaxW(result);
614 } 619 }
615 620
616 rowIndex = -rowIndex -1; 621 rowIndex = -rowIndex -1;
617 622
618 if (rowIndex < 1 || rowIndex >= rows.size()) { 623 if (rowIndex < 1 || rowIndex >= rows.size()) {
621 } 626 }
622 627
623 Row r1 = rows.get(rowIndex-1); 628 Row r1 = rows.get(rowIndex-1);
624 Row r2 = rows.get(rowIndex); 629 Row r2 = rows.get(rowIndex);
625 630
626 return r1.getMinMaxW(r2, km); 631 return r1.getMinMaxW(r2, km, result);
627 } 632 }
628 633
634 public double [] getMinMaxW(double from, double to, double step) {
635 double [] result = new double[2];
636
637 double minW = Double.MAX_VALUE;
638 double maxW = -Double.MAX_VALUE;
639
640 if (from > to) {
641 double tmp = from;
642 from = to;
643 to = tmp;
644 }
645
646 step = Math.max(Math.abs(step), 0.0001);
647
648 double d = from;
649 for (; d <= to; d += step) {
650 if (getMinMaxW(d, result) != null) {
651 if (result[0] < minW) minW = result[0];
652 if (result[1] > maxW) maxW = result[1];
653 }
654 }
655
656 if (d != to) {
657 if (getMinMaxW(to, result) != null) {
658 if (result[0] < minW) minW = result[0];
659 if (result[1] > maxW) maxW = result[1];
660 }
661 }
662
663 return minW < Double.MAX_VALUE
664 ? new double [] { minW, maxW }
665 : null;
666 }
629 667
630 /** 668 /**
631 * Interpolate W and Q values at a given km. 669 * Interpolate W and Q values at a given km.
632 */ 670 */
633 public double [][] interpolateWQ(double km) { 671 public double [][] interpolateWQ(double km) {

http://dive4elements.wald.intevation.org