Opened 3 months ago

Closed 3 months ago

## #15292 closed defect (fixed)

# AGS: Incorrect Use of Bitwise XOR Operator in Distance Calculation [upstream bug]

Reported by: | RainRat | Owned by: | tag2015 |
---|---|---|---|

Priority: | low | Component: | Engine: AGS |

Version: | Keywords: | ||

Cc: | Game: |

## Description

scummvm/blob/master/engines/ags/shared/util/geometry.cpp:

The function DistanceBetween in this code uses the bitwise XOR operator (`^`

) instead of the multiplication operator (`*`

) when calculating the square of distances. This results in incorrect distance calculations.

Current Code:

return static_cast<float>(std::sqrt((inner_width ^ 2) + (inner_height ^ 2)));

Expected Code:

return static_cast<float>(std::sqrt(inner_width * inner_width + inner_height * inner_height));

### Change History (4)

### comment:1 by , 3 months ago

### comment:2 by , 3 months ago

Summary: | AGS: Incorrect Use of Bitwise XOR Operator in Distance Calculation → AGS: Incorrect Use of Bitwise XOR Operator in Distance Calculation [upstream bug] |
---|

### comment:3 by , 3 months ago

Reported and fixed upstream https://github.com/adventuregamestudio/ags/issues/2485

**Note:**See TracTickets for help on using tickets.

Well spotted! This is an upstream bug, as you can see here

https://github.com/adventuregamestudio/ags/blob/master/Common/util/geometry.cpp

This should definitely be fixed, hopefully it won't break games that expect this "broken" calculation (it seems this function is only used by FindNearestViewport, though)

I'll open a bugreport on the AGS bugtracker