| 169 | //========================================================================== |
| 170 | |
| 171 | double SquareDistToSector(double px, double py, const sectortype* sect, DVector2* point) |
| 172 | { |
| 173 | if (inside(px, py, sect)) |
| 174 | { |
| 175 | if (point) |
| 176 | *point = { px, py }; |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | double bestdist = DBL_MAX; |
| 181 | DVector2 bestpt = { px, py }; |
| 182 | for (auto& wal : sect->walls) |
| 183 | { |
| 184 | DVector2 pt; |
| 185 | auto dist = SquareDistToWall(px, py, &wal, &pt); |
| 186 | if (dist < bestdist) |
| 187 | { |
| 188 | bestdist = dist; |
| 189 | bestpt = pt; |
| 190 | } |
| 191 | } |
| 192 | if (point) *point = bestpt; |
| 193 | return bestdist; |
| 194 | } |
| 195 | |
| 196 | //========================================================================== |
| 197 | // |
no test coverage detected