Opened 4 months ago

Closed 4 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 tag2015, 4 months ago

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

comment:2 by tag2015, 4 months ago

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

comment:4 by tag2015, 4 months ago

Owner: set to tag2015
Resolution: fixed
Status: newclosed

In 78ee37a1:

AGS: Common: fixed wrong calculation in DistanceBetween()

From upstream c5f8c5374024b71493d276a27daa38d1aac84a89
Fix #15292

Note: See TracTickets for help on using tickets.