Revision 49 org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/LrsCalibrateRouteAlgorithm.java

View differences:

LrsCalibrateRouteAlgorithm.java
301 301

  
302 302
        switch (calculationMethod) {
303 303
        case DISTANCE:
304
            expandedRoute.resetMeasuresToDistances();
304
            if (extrapolateBeforeCalibrationPoints||interpolateBetweenCalibrationPoints||extrapolateAfterCalibrationPoints){
305
                expandedRoute.resetMeasuresToDistances();
306
            }
305 307
        case MEASURES:
306 308
        default:
307 309
            expandedRoute.addFixedPoints(points);
308
            if (interpolateBetweenCalibrationPoints){
309
                expandedRoute.interpolateBetweenCalibrationPoints();
310
            }
311
            if (extrapolateBeforeCalibrationPoints){
312
                expandedRoute.extrapolateBeforeCalibrationPoints();
313
            }
314
            if (extrapolateAfterCalibrationPoints){
315
                expandedRoute.extrapolateAfterCalibrationPoints();
316
            }
310
            expandedRoute.calculateCalibrationPoints(extrapolateBeforeCalibrationPoints,interpolateBetweenCalibrationPoints,extrapolateAfterCalibrationPoints);
317 311
            return expandedRoute.getRoute();
318 312
        }
319 313

  
......
321 315

  
322 316

  
323 317

  
324

  
325

  
326

  
327 318
    class ExpandedRoute{
328 319
        private Geometry route;
329 320
        private List<Boolean> isFixedPoint;
330 321
        private List<Double> distances;
331 322
        private List<Double>oldMValues;
332 323
        private List<Point> vertices;
324
        private List<Integer> lineIndexes;
333 325
        private int MDIMENSION;
334
        private int maxMFixedPointPos;
335
        private int minMFixedPointPos;
336
        private final Double PRECISION=new Double(1.0e-10);
337 326

  
327
        private final Double PRECISION=new Double(1.0e-5);
328

  
338 329
        public Geometry getRoute(){
339 330
            return route;
340 331
        }
......
344 335
            distances=new ArrayList<Double>();
345 336
            oldMValues=new ArrayList<Double>();
346 337
            vertices=new ArrayList<Point>();
338
            lineIndexes=new ArrayList<Integer>();
347 339
            route=geometry.cloneGeometry();
348 340

  
349 341
            double distance = 0;
......
366 358
                       }else{
367 359
                           if (previousVertex!=null){
368 360
                               try {
369
                                   if (!ignoreSpatialGaps){
370
                                       distance+=previousVertex.distance(vertex);
361
                                   if(!LrsAlgorithmUtils.equalPoints(vertex, previousVertex)){
362
                                       Integer nearestVertexPos=getIndexNearestVisitedVertex(vertex);
363
                                       if (ignoreSpatialGaps){
364
                                           distance=distances.get(nearestVertexPos);
365
                                       }else{
366
                                           Point nearestVertex=vertices.get(nearestVertexPos);
367
                                           distance=distances.get(nearestVertexPos);
368
                                           distance+=vertex.distance(nearestVertex);
369
                                       }
371 370
                                   }
372 371
                               } catch (Exception e) {
373 372
                                   distance=Double.NaN;
......
387 386
                    vertices.add(vertex);
388 387
                    distances.add(distance);
389 388
                    oldMValues.add(mValue);
389
                    lineIndexes.add(i);
390 390

  
391 391
                    previousVertex = vertex;
392 392
                }
393 393
            }
394 394
        }
395 395

  
396
        private Integer getIndexNearestVisitedVertex(Point vertex) throws GeometryOperationNotSupportedException, GeometryOperationException{
397
            double nearestDistance = Double.POSITIVE_INFINITY;
398
            Integer nearestPointPos=null;
399
            for (int i=0;i<vertices.size();i++){
400
                Double distance=vertex.distance(vertices.get(i));
401
                if(nearestDistance>distance && distance>Double.valueOf(0)){
402
                    nearestDistance=distance;
403
                    nearestPointPos=i;
404
                }
405
            }
406
            return nearestPointPos;
407
        }
408

  
396 409
        private Integer getIndexVisitedVertex(Point point){
397 410
            double distance = Double.NEGATIVE_INFINITY;
398 411
            Integer index = null;
......
417 430
                List<Integer>insertAtList=new ArrayList<Integer>();
418 431
                List<Double>lengths=new ArrayList<Double>();
419 432
                List<Double>oldValues=new ArrayList<Double>();
433
                List<Integer>lineReference=new ArrayList<Integer>();
420 434
                for (int i=0; i<lines.size();i++){
421 435
                    Line line=lines.get(i);
422 436
                    try{
......
432 446
                                }else{
433 447
                                    nextVertex=null;
434 448
                                }
435
                                if(LrsAlgorithmUtils.equalPoints(vertex, fixedPoint)){
436
                                    oldMValues.add(index, vertex.getCoordinateAt(MDIMENSION));
449
                                if(LrsAlgorithmUtils.equalPoints(vertex, fixedPoint)||vertex.distance(fixedPoint)<=PRECISION){
450
                                    oldMValues.set(index, vertex.getCoordinateAt(MDIMENSION));
437 451
                                    Double mValue=fixedPoint.getCoordinateAt(MDIMENSION);
438 452
                                    vertex.setCoordinateAt(MDIMENSION, mValue);
439 453
                                    isFixedPoint.set(index, true);
440 454
                                    vertices.set(index, vertex);
441

  
442
                                    if (minMValue==null||mValue.compareTo(minMValue)<0){
443
                                        minMValue=mValue;
444
                                        minMFixedPointPos=index;
445
                                    }
446
                                    if (maxMValue==null||mValue.compareTo(maxMValue)>=0){
447
                                        maxMValue=mValue;
448
                                        maxMFixedPointPos=index;
449
                                    }
450 455
                                }else{
451 456
                                    if (nextVertex!=null && !LrsAlgorithmUtils.equalPoints(nextVertex, fixedPoint)){
452 457
                                        GeometryManager geomanager = GeometryLocator.getGeometryManager();
......
458 463
                                        //if (line.intersects(fixedPoint)){
459 464
                                        if (segment.isWithinDistance(fixedPoint, PRECISION)){
460 465
                                            length+=vertex.distance(fixedPoint);
461
                                            Double oldMValue=LrsAlgorithmUtils.calculateNewM(
466
                                            Double oldMValue=LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(
467
                                                vertex.getCoordinateAt(MDIMENSION),
462 468
                                                nextVertex.getCoordinateAt(MDIMENSION),
463
                                                vertex.getCoordinateAt(MDIMENSION),
469
                                                distances.get(index),
464 470
                                                distances.get(index+1),
465
                                                distances.get(index),
466 471
                                                length);
467 472
                                            insertAtList.add(index+1);
468 473
                                            lengths.add(length);
469 474
                                            oldValues.add(oldMValue);
475
                                            lineReference.add(i);
470 476
                                        }
471 477
                                    }
472 478
                                }
......
483 489
                for (Integer insertAt:insertAtList){
484 490
                    Double distance=lengths.get(pos);
485 491
                    Double oldMValue=oldValues.get(pos);
492
                    Integer linePos=lineReference.get(pos);
486 493
                    int correctedPosition=insertAt+pos;
487
                    LrsAlgorithmUtils.insertVertex(route, fixedPoint, correctedPosition);
494
                    route=LrsAlgorithmUtils.insertVertex(route, fixedPoint, correctedPosition);
488 495
                    isFixedPoint.add(correctedPosition, true);
489 496
                    distances.add(correctedPosition, distance);
490 497
                    oldMValues.add(correctedPosition, oldMValue);
491

  
498
                    lineIndexes.add(correctedPosition, linePos);
492 499
                    vertices.add(correctedPosition, fixedPoint);
493
                    correctPosteriorPositions(correctedPosition);
494

  
495
                    Double mValue=fixedPoint.getCoordinateAt(MDIMENSION);
496
                    if (minMValue==null||mValue.compareTo(minMValue)<0){
497
                        minMValue=mValue;
498
                        minMFixedPointPos=correctedPosition;
499
                    }
500
                    if (maxMValue==null||mValue.compareTo(maxMValue)>=0){
501
                        maxMValue=mValue;
502
                        maxMFixedPointPos=correctedPosition;
503
                    }
504 500
                    pos++;
505 501
                }
506 502
            }
507 503
        }
508 504

  
509
        private void correctPosteriorPositions(int pos){
510
            if (minMFixedPointPos>=pos){
511
                minMFixedPointPos++;
512
            }
513
            if (maxMFixedPointPos>=pos){
514
                maxMFixedPointPos++;
515
            }
516 505

  
517
        }
518 506

  
519 507
        public void resetMeasuresToDistances(){
520 508
             List<Point> points=LrsAlgorithmUtils.extractPoints(route);
......
522 510
                 if (!isFixedPoint.get(i)){
523 511
                     points.get(i).setCoordinateAt(MDIMENSION, distances.get(i));
524 512
                     vertices.get(i).setCoordinateAt(MDIMENSION, distances.get(i));
513
                     oldMValues.set(i, distances.get(i));
525 514
                 }
526 515
             }
527 516
        }
528 517

  
529
        public void interpolateBetweenCalibrationPoints(){
530
            Double newMValueBeforePoint=Double.NaN;
531
            Double oldMValueBeforePoint=Double.NaN;
532
            Double calibrationRatio=Double.NaN;
533
            for (int i=minMFixedPointPos; i<=maxMFixedPointPos-1;i++){
534
                if (isFixedPoint.get(i)){
535
                    int pointBeforePos=i;
536
                    int pointAfterPos=getNextPosFixedPoint(i);
518
//        public void interpolateBetweenCalibrationPoints(){
519
//            Double newMValueBeforePoint=Double.NaN;
520
//            Double oldMValueBeforePoint=Double.NaN;
521
//            Double calibrationRatio=Double.NaN;
522
//            for (int i=firstFixedPointPos; i<=lastFixedPointPos-1;i++){
523
//                if (isFixedPoint.get(i)){
524
//                    int pointBeforePos=i;
525
//                    int pointAfterPos=getNextPosFixedPoint(i);
526
//
527
//                    newMValueBeforePoint=vertices.get(pointBeforePos).getCoordinateAt(MDIMENSION);
528
//                    Double newMValueAfterPoint=vertices.get(pointAfterPos).getCoordinateAt(MDIMENSION);
529
//
530
//                    oldMValueBeforePoint=oldMValues.get(pointBeforePos);
531
//                    Double oldMValueAfterPoint=oldMValues.get(pointAfterPos);
532
//
533
//                    Double distanceBetweenFixedPoints=newMValueAfterPoint-newMValueBeforePoint;
534
//                    Double distanceBetweenOldFixedPoints=oldMValueAfterPoint-oldMValueBeforePoint;
535
//
536
//                    calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints;
537
//                }else{
538
//                    Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION);
539
//                    Double distanceBetween=valueToRecalculate-oldMValueBeforePoint;
540
//                    Double mValue=newMValueBeforePoint+(distanceBetween/calibrationRatio);
541
//                    refreshMValueGeometryVertex(i,mValue);
542
//                }
543
//            }
544
//        }
537 545

  
538
                    newMValueBeforePoint=vertices.get(pointBeforePos).getCoordinateAt(MDIMENSION);
539
                    Double newMValueAfterPoint=vertices.get(pointAfterPos).getCoordinateAt(MDIMENSION);
546
        public void calculateCalibrationPoints(boolean before, boolean between, boolean after){
547
            for (int i=0; i<vertices.size();i++){
548
                if(!isFixedPoint.get(i)){
549
                    Integer prevFixedPointPos=getPreviousPosFixedPoint(i);
550
                    Integer nextFixedPointPos=getNextPosFixedPoint(i);
540 551

  
541
                    oldMValueBeforePoint=oldMValues.get(pointBeforePos);
542
                    Double oldMValueAfterPoint=oldMValues.get(pointAfterPos);
543

  
544
                    Double distanceBetweenFixedPoints=newMValueAfterPoint-newMValueBeforePoint;
545
                    Double distanceBetweenOldFixedPoints=oldMValueAfterPoint-oldMValueBeforePoint;
546

  
547
                    calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints;
548
                }else{
549
                    Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION);
550
                    Double distanceBetween=valueToRecalculate-oldMValueBeforePoint;
551
                    Double mValue=newMValueBeforePoint+(distanceBetween/calibrationRatio);
552
                    refreshMValueGeometryVertex(i,mValue);
552
                    if (prevFixedPointPos==null && nextFixedPointPos!=null  && before){
553
                        //TODO
554
                        //extrapolateBeforeCalibrationPoints(nextFixedPointPos,i);
555
                    }
556
                    if (prevFixedPointPos!=null && nextFixedPointPos!=null && between){
557
                        calculateMValue(prevFixedPointPos,nextFixedPointPos,i);
558
                    }
559
                    if (prevFixedPointPos!=null && nextFixedPointPos==null && after){
560
                        //TODO
561
                        //extrapolateAfterCalibrationPoints(prevFixedPointPos,i);
562
                    }
553 563
                }
554 564
            }
555 565
        }
556 566

  
567
        public void calculateMValue(int prevFixedPointPos,int nextFixedPointPos,int pos){
568
            Double newMValueBeforePoint=vertices.get(prevFixedPointPos).getCoordinateAt(MDIMENSION);
569
            Double newMValueAfterPoint=vertices.get(nextFixedPointPos).getCoordinateAt(MDIMENSION);
557 570

  
558
        public void extrapolateBeforeCalibrationPoints(){
559
            int nextFixedPointPos=getNextPosFixedPoint(minMFixedPointPos);
560
            Double newMValueFirstPoint=vertices.get(minMFixedPointPos).getCoordinateAt(MDIMENSION);
561
            Double newMValueSecondPoint=vertices.get(nextFixedPointPos).getCoordinateAt(MDIMENSION);
571
            Double oldMValueBeforePoint=oldMValues.get(prevFixedPointPos);
572
            Double oldMValueAfterPoint=oldMValues.get(nextFixedPointPos);
562 573

  
563
            Double oldMValueFirstPoint=oldMValues.get(minMFixedPointPos);
564
            Double oldMValueSecondPoint=oldMValues.get(nextFixedPointPos);
574
            Double distanceBetweenFixedPoints=newMValueAfterPoint-newMValueBeforePoint;
575
            Double distanceBetweenOldFixedPoints=oldMValueAfterPoint-oldMValueBeforePoint;
565 576

  
566
            Double distanceBetweenFixedPoints=newMValueSecondPoint-newMValueFirstPoint;
567
            Double distanceBetweenOldFixedPoints=oldMValueSecondPoint-oldMValueFirstPoint;
577
            Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints;
568 578

  
569
            Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints;
570
            for (int i=0; i<minMFixedPointPos;i++){
571
                Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION);
572
                Double distanceBetween=oldMValueFirstPoint-valueToRecalculate;
573
                Double mValue=newMValueFirstPoint-(distanceBetween/calibrationRatio);
574
                refreshMValueGeometryVertex(i,mValue);
575
            }
579
            Double valueToRecalculate=vertices.get(pos).getCoordinateAt(MDIMENSION);
580
            Double distanceBetween=valueToRecalculate-oldMValueBeforePoint;
581
            Double mValue=newMValueBeforePoint+(distanceBetween/calibrationRatio);
582
            refreshMValueGeometryVertex(pos,mValue);
576 583
        }
577 584

  
578
        public void extrapolateAfterCalibrationPoints(){
579
            int prevFixedPointPos=getPreviousPosFixedPoint(maxMFixedPointPos);
580
            Double newMValueLastPoint=vertices.get(maxMFixedPointPos).getCoordinateAt(MDIMENSION);
581
            Double newMValuePrevPoint=vertices.get(prevFixedPointPos).getCoordinateAt(MDIMENSION);
582 585

  
583
            Double oldMValueLastPoint=oldMValues.get(maxMFixedPointPos);
584
            Double oldMValuePrevPoint=oldMValues.get(prevFixedPointPos);
586
//        public void extrapolateBeforeCalibrationPoints(){
587
//            Integer nextFixedPointPos=getNextPosFixedPoint(firstFixedPointPos);
588
//            if (nextFixedPointPos!=null){
589
//                Double newMValueFirstPoint=vertices.get(firstFixedPointPos).getCoordinateAt(MDIMENSION);
590
//                Double newMValueSecondPoint=vertices.get(nextFixedPointPos).getCoordinateAt(MDIMENSION);
591
//
592
//                Double oldMValueFirstPoint=oldMValues.get(firstFixedPointPos);
593
//                Double oldMValueSecondPoint=oldMValues.get(nextFixedPointPos);
594
//
595
//                Double distanceBetweenFixedPoints=newMValueSecondPoint-newMValueFirstPoint;
596
//                Double distanceBetweenOldFixedPoints=oldMValueSecondPoint-oldMValueFirstPoint;
597
//
598
//                Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints;
599
//                for (int i=0; i<firstFixedPointPos;i++){
600
//                    Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION);
601
//                    Double distanceBetween=oldMValueFirstPoint-valueToRecalculate;
602
//                    Double mValue=newMValueFirstPoint-(distanceBetween/calibrationRatio);
603
//                    refreshMValueGeometryVertex(i,mValue);
604
//                }
605
//            }
606
//        }
607
//
608
//        public void extrapolateAfterCalibrationPoints(){
609
//            Integer prevFixedPointPos=getPreviousPosFixedPoint(lastFixedPointPos);
610
//            if (prevFixedPointPos!=null){
611
//                Double newMValueLastPoint=vertices.get(lastFixedPointPos).getCoordinateAt(MDIMENSION);
612
//                Double newMValuePrevPoint=vertices.get(prevFixedPointPos).getCoordinateAt(MDIMENSION);
613
//
614
//                Double oldMValueLastPoint=oldMValues.get(lastFixedPointPos);
615
//                Double oldMValuePrevPoint=oldMValues.get(prevFixedPointPos);
616
//
617
//                Double distanceBetweenFixedPoints=newMValueLastPoint-newMValuePrevPoint;
618
//                Double distanceBetweenOldFixedPoints=oldMValueLastPoint-oldMValuePrevPoint;
619
//
620
//                Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints;
621
//                for (int i=lastFixedPointPos+1; i<vertices.size();i++){
622
//                    Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION);
623
//                    Double distanceBetween=valueToRecalculate-oldMValueLastPoint;
624
//                    Double mValue=newMValueLastPoint+(distanceBetween/calibrationRatio);
625
//                    refreshMValueGeometryVertex(i,mValue);
626
//                }
627
//            }
628
//        }
629
//
630
//        private Integer getNextPosFixedPoint(int pos){
631
//            for (int i=pos+1;i<isFixedPoint.size();i++){
632
//                if (isFixedPoint.get(i)){
633
//                    if( !distances.get(pos).equals(distances.get(i)) ){
634
//                        return i;
635
//                    }
636
//                }
637
//            }
638
//            return null;
639
//        }
585 640

  
586
            Double distanceBetweenFixedPoints=newMValueLastPoint-newMValuePrevPoint;
587
            Double distanceBetweenOldFixedPoints=oldMValueLastPoint-oldMValuePrevPoint;
588 641

  
589
            Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints;
590
            for (int i=maxMFixedPointPos+1; i<vertices.size();i++){
591
                Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION);
592
                Double distanceBetween=valueToRecalculate-oldMValueLastPoint;
593
                Double mValue=newMValueLastPoint+(distanceBetween/calibrationRatio);
594
                refreshMValueGeometryVertex(i,mValue);
642

  
643
        private Integer getNextPosFixedPoint(int pos){
644
            Integer nextFixedPointPos= findNextFixedPointInLine(pos);
645
            if (nextFixedPointPos!=null){
646
                return nextFixedPointPos;
647
            }else{
648
                Integer lineVisited=lineIndexes.get(pos);
649
                for (int i=pos+1;i<vertices.size();i++){
650
                    if (!lineVisited.equals(lineIndexes.get(i))){//Line has changed
651
                        int lastPositionInLine=i-1;
652
                        nextFixedPointPos=findNextFixedPointInNextLines(lastPositionInLine,new ArrayList<Integer>());
653
                        if (nextFixedPointPos!=null){
654
                            return nextFixedPointPos;
655
                        }
656
                        try{
657
                            return findNearestNextFixedPoint(lastPositionInLine);
658
                        }catch (Exception e){
659
                            return null;
660
                        }
661
                    }
662
                }
595 663
            }
664
            return null;
596 665
        }
597 666

  
598
        private Integer getNextPosFixedPoint(int pos){
599
            for (int i=pos+1;i<isFixedPoint.size();i++){
600
                if (isFixedPoint.get(i)){
601
                    if( !distances.get(pos).equals(distances.get(i)) ){
602
                        return i;
667
        private Integer findNextFixedPointInNextLines(int pos,List<Integer> visitedLines){
668
            Integer nextFixedPointPos= findNextFixedPointInLine(pos);
669
            if (nextFixedPointPos!=null){
670
                return nextFixedPointPos;
671
            }else{
672
                Point vertex=vertices.get(pos);
673
                for (int j=pos;j<vertices.size();j++){
674
                    if (LrsAlgorithmUtils.equalPoints(vertex, vertices.get(j))){
675
                        Integer fixedPointPos=findNextFixedPointInLine(j);
676
                        if (fixedPointPos!=null){
677
                            return fixedPointPos;
678
                        }
603 679
                    }
604 680
                }
605 681
            }
606 682
            return null;
607 683
        }
608 684

  
609
        private Integer getPreviousPosFixedPoint(int pos){
610
            for (int i=pos-1;i>=0;i--){
685
        private Integer findNextFixedPointInLine(int vertexPos){
686
            int lineIndex=lineIndexes.get(vertexPos);
687
            for (int i=vertexPos;i<vertices.size();i++){
688
                if(!lineIndexes.get(i).equals(lineIndex)){
689
                    return null;
690
                }
611 691
                if (isFixedPoint.get(i)){
612
                    if( !distances.get(pos).equals(distances.get(i)) ){
613
                        return i;
692
                    return i;
693
                }
694
            }
695
            return null;
696
        }
697
        private Integer findNearestNextFixedPoint(int vertexPos) throws GeometryOperationNotSupportedException, GeometryOperationException{
698
            Point vertex=vertices.get(vertexPos);
699
            double nearestDistance = Double.POSITIVE_INFINITY;
700
            Integer nearestPointPos=null;
701
            for (int i=vertexPos+1;i<vertices.size();i++){
702
                if (isFixedPoint.get(i)){
703
                    Double distance=vertex.distance(vertices.get(i));
704
                    if(nearestDistance>distance){
705
                        nearestDistance=distance;
706
                        nearestPointPos=i;
614 707
                    }
615 708
                }
616 709
            }
710
            return nearestPointPos;
711
        }
712

  
713

  
714
        private Integer getPreviousPosFixedPoint(int pos){
715
            Integer prevFixedPointPos= findPrevFixedPointInLine(pos);
716
            if (prevFixedPointPos!=null){
717
                return prevFixedPointPos;
718
            }else{
719
                Integer lineVisited=lineIndexes.get(pos);
720
                for (int i=pos-1;i>=0;i--){
721
                    if (!lineVisited.equals(lineIndexes.get(i))){//Line has changed
722
                        int lastPositionInLine=i+1;
723
                        for (int j=lastPositionInLine;j>=0;j--){
724
                            if (LrsAlgorithmUtils.equalPoints(vertices.get(lastPositionInLine), vertices.get(j))){
725
                                if (isFixedPoint.get(j)){
726
                                    return j;
727
                                }
728
                            }
729
                        }
730
                        try{
731
                            return findNearestPrevFixedPoint(lastPositionInLine);
732
                        }catch (Exception e){
733
                            return null;
734
                        }
735
                    }
736
                }
737
            }
617 738
            return null;
618 739
        }
740
        private Integer findPrevFixedPointInLine(int vertexPos){
741
            int lineIndex=lineIndexes.get(vertexPos);
742
            for (int i=vertexPos;i>=0;i--){
743
                if(!lineIndexes.get(i).equals(lineIndex)){
744
                    return null;
745
                }
746
                if (isFixedPoint.get(i)){
747
                    return i;
748
                }
749
            }
750
            return null;
751
        }
752
        private Integer findNearestPrevFixedPoint(int vertexPos) throws GeometryOperationNotSupportedException, GeometryOperationException{
753
            Point vertex=vertices.get(vertexPos);
754
            double nearestDistance = Double.POSITIVE_INFINITY;
755
            Integer nearestPointPos=null;
756
            for (int i=vertexPos-1;i>=0;i--){
757
                if (isFixedPoint.get(i)){
758
                    Double distance=vertex.distance(vertices.get(i));
759
                    if(nearestDistance>distance){
760
                        nearestDistance=distance;
761
                        nearestPointPos=i;
762
                    }
763
                }
764
            }
765
            return nearestPointPos;
766
        }
619 767

  
768

  
620 769
        private void refreshMValueGeometryVertex(int i, Double mValue){
621 770
            List<Point> points=LrsAlgorithmUtils.extractPoints(route);
622 771
            vertices.get(i).setCoordinateAt(MDIMENSION, mValue);
623 772
            points.get(i).setCoordinateAt(MDIMENSION,mValue);
773
            isFixedPoint.set(i, true);
624 774
        }
625 775

  
626 776
    }

Also available in: Unified diff