[Scummvm-cvs-logs] scummvm master -> 121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f
dreammaster
dreammaster at scummvm.org
Thu Jul 2 02:12:48 CEST 2015
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
121ee4d40c SHERLOCK: RT: Fix zone checks in closestZone method
Commit: 121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f
https://github.com/scummvm/scummvm/commit/121ee4d40c2cd203d1a0dfef2b8e1d8d83b0b43f
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2015-07-01T20:07:37-04:00
Commit Message:
SHERLOCK: RT: Fix zone checks in closestZone method
Changed paths:
engines/sherlock/scene.cpp
diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp
index c3917fb..69deede 100644
--- a/engines/sherlock/scene.cpp
+++ b/engines/sherlock/scene.cpp
@@ -1380,16 +1380,45 @@ int Scene::whichZone(const Common::Point &pt) {
}
int Scene::closestZone(const Common::Point &pt) {
- int dist = 1000;
int zone = -1;
+ int dist = 9999;
+ int d;
for (uint idx = 0; idx < _zones.size(); ++idx) {
- Common::Point zc((_zones[idx].left + _zones[idx].right) / 2,
- (_zones[idx].top + _zones[idx].bottom) / 2);
- int d = ABS(zc.x - pt.x) + ABS(zc.y - pt.y);
+ Common::Rect &r = _zones[idx];
+ // Check the distance from the point to the center of the zone
+ d = ABS(r.left + (r.width() / 2) - pt.x) + ABS(r.top + (r.height() / 2) - pt.y);
+ if (d < dist) {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the upper left of the zone
+ d = ABS((int)(r.left - pt.x)) + ABS((int)(r.top - pt.y));
+ if (d < dist)
+ {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the upper right of the zone
+ d = ABS(r.left + r.width() - pt.x) + ABS(r.top - pt.y);
+ if (d < dist) {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the lower left of the zone
+ d = ABS(r.left - pt.x) + ABS(r.top + r.height() - pt.y);
+ if (d < dist) {
+ dist = d;
+ zone = idx;
+ }
+
+ // Check the distance from the point to the lower right of the zone
+ d = ABS(r.left + r.width() - pt.x) + ABS(r.top + r.height() - pt.y);
if (d < dist) {
- // Found a closer zone
dist = d;
zone = idx;
}
More information about the Scummvm-git-logs
mailing list