Skip to content

Commit

Permalink
[UNI-218] refactor : 길 찾기 상세경로 좌회전,우회전 로직 수정 (#185)
Browse files Browse the repository at this point in the history
* [UNI-218] refactor : 방향 비교할 때 i-1, i, i+1 비교가 아닌 i-2, i, i+2를 비교하도록 변경

* [UNI-218] refactor : 메서드 2개를 하나로 병합
  • Loading branch information
thdgustjd1 authored Feb 20, 2025
1 parent afb5d11 commit 0419713
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,30 @@ private boolean isBuildingRoute(Route route){
}

// 두 route 간의 각도를 통한 계산으로 방향성을 정하는 메서드
private DirectionType calculateDirection(Node secondNode, Route inBoundRoute, Route outBoundRoute) {
Node firstNode = inBoundRoute.getNode1().equals(secondNode) ? inBoundRoute.getNode2() : inBoundRoute.getNode1();
Node thirdNode = outBoundRoute.getNode1().equals(secondNode) ? outBoundRoute.getNode2() : outBoundRoute.getNode1();
private DirectionType calculateDirection(Node secondNode, List<Route> shortestRoutes, int idx) {
Node firstNode = shortestRoutes.get(idx).getNode1().equals(secondNode) ?
shortestRoutes.get(idx).getNode2() : shortestRoutes.get(idx).getNode1();
Node thirdNode = shortestRoutes.get(idx+1).getNode2().equals(secondNode) ?
shortestRoutes.get(idx+1).getNode1() : shortestRoutes.get(idx+1).getNode2();

if(idx-1 >= 0){
firstNode = shortestRoutes.get(idx-1).getNode1().equals(secondNode) ?
shortestRoutes.get(idx-1).getNode2() : shortestRoutes.get(idx-1).getNode1();
}

if(idx+2 <= shortestRoutes.size()-1){
thirdNode = shortestRoutes.get(idx+2).getNode2().equals(secondNode) ?
shortestRoutes.get(idx+2).getNode1() : shortestRoutes.get(idx+2).getNode2();
}

Point p1 = firstNode.getCoordinates();
Point p2 = secondNode.getCoordinates();
Point p3 = thirdNode.getCoordinates();

return calculateAngle(p1, p2, p3);
}

private DirectionType calculateAngle(Point p1, Point p2, Point p3) {
double v1x = p2.getX() - p1.getX();
double v1y = p2.getY() - p1.getY();

Expand Down Expand Up @@ -366,7 +382,8 @@ private List<RouteDetailResDTO> getRouteDetail(Node startNode, Node endNode, Lis
break;
}
if(nxt.isCore()){
DirectionType directionType = calculateDirection(nxt, nowRoute, shortestRoutes.get(i+1));
DirectionType directionType = calculateDirection(nxt, shortestRoutes, i);

if(directionType == DirectionType.STRAIGHT){
now = nxt;
continue;
Expand Down

0 comments on commit 0419713

Please sign in to comment.