Revision 48 org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/LrsAlgorithmUtils.java

View differences:

LrsAlgorithmUtils.java
458 458
        }
459 459
    }
460 460

  
461
    static protected Double calculateM(Double maxValue, Double minValue,
462
        Double relativeDistance, Double totalLength) {
463
        // mValue=((newMax-newMin)*(mCoordinate-oldMin)/(oldMax-oldMin))+newMin;
464
        if (totalLength.equals(Double.valueOf(0)))
465
            return Double.POSITIVE_INFINITY;
466
        return ((maxValue - minValue) * (relativeDistance) / (totalLength))
467
            + minValue;
461
    /**
462
     * Reduced versi?n of straight line through two points equation to calculate M's
463
     *
464
     * @param totalLength
465
     * @param minValue
466
     * @param maxValue
467
     * @param relativeDistance
468
     * @return
469
     */
470
    static protected double calculateM(Double totalLength, Double minValue, Double maxValue, Double relativeDistance) {
471
        return LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(0, totalLength, minValue, maxValue, relativeDistance);
468 472
    }
469 473

  
470
    static protected double calculateNewM(double oldMax, double oldMin, double newMax, double newMin, double mCoordinate){
471
        double result;
472
        if (oldMax==oldMin){
474
    /**
475
     * Same as straightLineThroughTwoPointsEquation but with more human readable arguments
476
     *
477
     * @param oldMin
478
     * @param oldMax
479
     * @param newMin
480
     * @param newMax
481
     * @param m
482
     * @return double
483
     *
484
     * @deprecated Use {@link #straightLineThroughTwoPointsEquation()} instead.
485
     */
486
    @Deprecated
487
    static protected double calculateNewM(double oldMin, double oldMax, double newMin, double newMax, double m){
488
        //TO REMOVE
489
        return straightLineThroughTwoPointsEquation(oldMin, oldMax, newMin, newMax, m);
490
    }
491

  
492

  
493
    /**
494
     * Straight line through two points equation.
495
     *
496
     * @param x1
497
     * @param x2
498
     * @param y1
499
     * @param y2
500
     * @param x
501
     * @return
502
     */
503
    static protected double straightLineThroughTwoPointsEquation(double x1, double x2, double y1, double y2, double x) {
504
        if (x2 - x1 == 0.0) {
473 505
            return Double.POSITIVE_INFINITY;
474 506
        }
475
        result=((newMax-newMin)*(mCoordinate-oldMin)/(oldMax-oldMin))+newMin;
476

  
477
        return result;
507
        return ((y2 - y1) * (x - x1) / (x2 - x1)) + y1;
478 508
    }
479 509

  
480 510
}

Also available in: Unified diff