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/LrsCreateRouteAlgorithm.java
LrsCreateRouteAlgorithm.java | ||
---|---|---|
280 | 280 |
Point fork = getPossibleFork(auxMultiLine, vertex); |
281 | 281 |
if(fork!=null){ |
282 | 282 |
previousPoint = fork; |
283 |
// OJO, aqu? previousPoint pasa a ser 2DM |
|
283 | 284 |
} |
284 |
// OJO, aqu? previousPoint pasa a ser 2DM |
|
285 | 285 |
} else { |
286 | 286 |
// En caso de salto, calculamos el previousPoint |
287 | 287 |
// buscando el v?rtice m?s cercano |
... | ... | |
298 | 298 |
if(areInSame2DLocation(previousPoint,previousVertex)){ |
299 | 299 |
Point nextVertex = getNextVertexToPoint(auxMultiLine, previousPoint); |
300 | 300 |
double distanceToNextPoint = nextVertex.distance(previousPoint); |
301 |
previousM = strightLineThroughTwoPointsEquation(0, distanceToNextPoint,
|
|
301 |
previousM = LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(0, distanceToNextPoint,
|
|
302 | 302 |
previousM, nextVertex.getCoordinateAt(previousVertex.getDimension() - 1), |
303 | 303 |
previousPoint.distance(point)); |
304 | 304 |
} else { |
305 | 305 |
double distanceToPreviousPoint = previousVertex.distance(previousPoint); |
306 |
previousM = strightLineThroughTwoPointsEquation(0, distanceToPreviousPoint,
|
|
306 |
previousM = LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(0, distanceToPreviousPoint,
|
|
307 | 307 |
previousVertex.getCoordinateAt(previousVertex.getDimension() - 1), previousM, |
308 | 308 |
distanceToPreviousPoint + previousPoint.distance(point)); |
309 | 309 |
} |
... | ... | |
314 | 314 |
distance += previousPoint.distance(vertex); |
315 | 315 |
} |
316 | 316 |
double m = |
317 |
strightLineThroughTwoPointsEquation(0, geometryLength, firstM, firstM + mSegment.fromValue,
|
|
317 |
LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(0, geometryLength, firstM, firstM + mSegment.fromValue,
|
|
318 | 318 |
distance); |
319 | 319 |
point.setCoordinateAt(point.getDimension() - 1, m); |
320 | 320 |
auxLine.addVertex(point); |
... | ... | |
342 | 342 |
// OJO, aqu? previousPoint pasa a ser 2DM |
343 | 343 |
} else { |
344 | 344 |
// En caso de salto, calculamos el previousPoint |
345 |
// buscando el v?rtice m?s cercano |
|
345 | 346 |
previousPoint = getClosestVertex(auxMultiLine, vertex); |
346 | 347 |
// OJO, aqu? previousPoint pasa a ser 2DM |
347 | 348 |
gap = true; |
... | ... | |
354 | 355 |
Point previousVertex = getPreviousVertexToPoint(auxMultiLine, previousPoint); |
355 | 356 |
previousVertex.getCoordinateAt(previousVertex.getDimension() - 1); |
356 | 357 |
previousM = |
357 |
strightLineThroughTwoPointsEquation(0, previousVertex.distance(previousPoint),
|
|
358 |
LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(0, previousVertex.distance(previousPoint),
|
|
358 | 359 |
previousVertex.getCoordinateAt(previousVertex.getDimension() - 1), previousM, |
359 | 360 |
previousVertex.distance(previousPoint) + previousPoint.distance(point)); |
360 | 361 |
firstM = previousM; |
... | ... | |
364 | 365 |
distance += previousPoint.distance(vertex); |
365 | 366 |
} |
366 | 367 |
double m = |
367 |
strightLineThroughTwoPointsEquation(0, geometryLength, firstM, firstM + mSegment.fromValue,
|
|
368 |
LrsAlgorithmUtils.straightLineThroughTwoPointsEquation(0, geometryLength, firstM, firstM + mSegment.fromValue,
|
|
368 | 369 |
distance); |
369 | 370 |
point.setCoordinateAt(point.getDimension() - 1, m); |
370 | 371 |
auxLine.addVertex(point); |
... | ... | |
604 | 605 |
Double distance = Double.valueOf(0); |
605 | 606 |
for (Line line : geometryLines) { |
606 | 607 |
Double lineLength = getLineLength(line); |
607 |
Double mFirstPoint = calculateM(geometryMLastPoint, geometryMFirstPoint, distance, geometryLength);
|
|
608 |
Double mFirstPoint = LrsAlgorithmUtils.calculateM(geometryLength, geometryMFirstPoint, geometryMLastPoint, distance);
|
|
608 | 609 |
distance += lineLength; |
609 |
Double mLastPoint = calculateM(geometryMLastPoint, geometryMFirstPoint, distance, geometryLength);
|
|
610 |
Double mLastPoint = LrsAlgorithmUtils.calculateM(geometryLength, geometryMFirstPoint, geometryMLastPoint, distance);
|
|
610 | 611 |
Line mLine = lineToMLine(line, mFirstPoint, mLastPoint); |
611 | 612 |
mGeometry.addPrimitive(mLine); |
612 | 613 |
} |
... | ... | |
646 | 647 |
else { |
647 | 648 |
Point previousVertex = line.getVertex(i - 1); |
648 | 649 |
inLineDistance += vertex.distance(previousVertex); |
649 |
mValue = calculateM(maxMValue, minMValue, inLineDistance, lineLength);
|
|
650 |
mValue = LrsAlgorithmUtils.calculateM(lineLength, minMValue, maxMValue, inLineDistance);
|
|
650 | 651 |
} |
651 | 652 |
|
652 | 653 |
mVertex.setCoordinateAt(mVertex.getDimension() - 1, mValue); |
... | ... | |
655 | 656 |
return lineM; |
656 | 657 |
} |
657 | 658 |
|
658 |
/** |
|
659 |
* Reduced versi?n of stright line through two points equation to calculate M's |
|
660 |
* |
|
661 |
* @param maxValue |
|
662 |
* @param minValue |
|
663 |
* @param relativeDistance |
|
664 |
* @param totalLength |
|
665 |
* @return |
|
666 |
*/ |
|
667 |
private Double calculateM(Double maxValue, Double minValue, Double relativeDistance, Double totalLength) { |
|
668 |
if (totalLength.equals(Double.valueOf(0))) |
|
669 |
return Double.POSITIVE_INFINITY; |
|
670 |
return ((maxValue - minValue) * (relativeDistance) / (totalLength)) + minValue; |
|
671 |
} |
|
672 | 659 |
|
673 | 660 |
/** |
674 |
* Stright line through two points equation. |
|
675 |
* |
|
676 |
* @param x1 |
|
677 |
* @param x2 |
|
678 |
* @param y1 |
|
679 |
* @param y2 |
|
680 |
* @param x |
|
681 |
* @return |
|
682 |
*/ |
|
683 |
private double strightLineThroughTwoPointsEquation(double x1, double x2, double y1, double y2, double x) { |
|
684 |
if (x2 - x1 == 0.0) { |
|
685 |
return Double.POSITIVE_INFINITY; |
|
686 |
} |
|
687 |
return ((y2 - y1) * (x - x1) / (x2 - x1)) + y1; |
|
688 |
} |
|
689 |
|
|
690 |
/** |
|
691 | 661 |
* Simplify the multilines in mList calling simplifyMultiline method |
692 | 662 |
* |
693 | 663 |
* @param mList |
Also available in: Unified diff