Skip to content

Commit

Permalink
Fix #719 Invalid result for CBA_fnc_getNearest
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsms committed Jul 5, 2017
1 parent 1e4387d commit 94d7680
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 2 additions & 7 deletions addons/common/fnc_getNearest.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ private _return = [[], objNull] select (isNil {param [2]});

if (_distance < _radius) then {
if !(call _code) exitWith {}; // don't move up. condition has to return false, vs. has to return true. Can be nil!

if !(_return isEqualType objNull) then {
_return pushBack _x;
} else {
_radius = _distance;
_return = _x;
};
_radius = _distance;
_return = _x;
};
} forEach _array;

Expand Down
7 changes: 7 additions & 0 deletions addons/common/test_position.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ _value set [0,-1];
TEST_TRUE(_result isEqualTo EXPECTED,_funcName);

////////////////////////////////////////////////////////////////////////////////////////////////////

#define EXPECTED [1,1,0] //Pos nearest to [0,0,0]

_value = [[0,0,0], [[10,10,0],[1,1,0], [5,5,0]]];
_result = _value call CBA_fnc_getNearest;

TEST_TRUE(_result isEqualTo EXPECTED,_funcName);

0 comments on commit 94d7680

Please sign in to comment.