| 1071 | */ |
| 1072 | |
| 1073 | SHORT GetOppositeSector (SHORT ld1, BOOL firstside) |
| 1074 | { |
| 1075 | SHORT x0, y0, dx0, dy0; |
| 1076 | SHORT x1, y1, dx1, dy1; |
| 1077 | SHORT x2, y2, dx2, dy2; |
| 1078 | SHORT ld2, dist; |
| 1079 | SHORT bestld, bestdist, bestmdist; |
| 1080 | |
| 1081 | /* get the coords for this LineDef */ |
| 1082 | LineDef *pLineDef1 = &LineDefs[ld1]; |
| 1083 | Vertex v1s = Vertexes[pLineDef1->start]; |
| 1084 | Vertex v1e = Vertexes[pLineDef1->end]; |
| 1085 | |
| 1086 | x0 = v1s.x; |
| 1087 | y0 = v1s.y; |
| 1088 | dx0 = v1e.x - x0; |
| 1089 | dy0 = v1e.y - y0; |
| 1090 | |
| 1091 | /* find the normal vector for this LineDef */ |
| 1092 | x1 = (dx0 + x0 + x0) / 2; |
| 1093 | y1 = (dy0 + y0 + y0) / 2; |
| 1094 | if (firstside == TRUE) |
| 1095 | { |
| 1096 | dx1 = dy0; |
| 1097 | dy1 = -dx0; |
| 1098 | } |
| 1099 | else |
| 1100 | { |
| 1101 | dx1 = -dy0; |
| 1102 | dy1 = dx0; |
| 1103 | } |
| 1104 | |
| 1105 | bestld = -1; |
| 1106 | // use a parallel to an axis instead of the normal vector (faster method) |
| 1107 | if ( abs(dy1) > abs(dx1) ) |
| 1108 | { |
| 1109 | if (dy1 > 0) |
| 1110 | { |
| 1111 | // get the nearest LineDef in that direction (increasing Y's: North) |
| 1112 | bestdist = 32767; |
| 1113 | bestmdist = 32767; |
| 1114 | for (ld2 = 0; ld2 < NumLineDefs; ld2++) |
| 1115 | { |
| 1116 | LineDef *pLineDef2 = &LineDefs[ld2]; |
| 1117 | Vertex v2s = Vertexes[pLineDef2->start]; |
| 1118 | Vertex v2e = Vertexes[pLineDef2->end]; |
| 1119 | if (ld2 != ld1 && ((v2s.x > x1) != (v2e.x > x1))) |
| 1120 | { |
| 1121 | x2 = v2s.x; |
| 1122 | y2 = v2s.y; |
| 1123 | dx2 = v2e.x - x2; |
| 1124 | dy2 = v2e.y - y2; |
| 1125 | dist = y2 + (SHORT) (((LONG) (x1 - x2) * dy2) / dx2); |
| 1126 | if (dist > y1 && |
| 1127 | (dist < bestdist || |
| 1128 | (dist == bestdist && (y2 + dy2 / 2) < bestmdist))) |
| 1129 | { |
| 1130 | bestld = ld2; |
no outgoing calls
no test coverage detected