I get a weird issue with Math_IsInBounds in the sm1.7 branch of smlib (didn't tested with old syntax).
#pragma semicolon 1
#include <sourcemod>
#include <smlib>
#pragma newdecls required
#define print_vec(%1) %1[0], %1[1], %1[2]
#define print_bool(%1) %1 ? "true" : "false"
public Plugin myinfo =
{
name = "Math_IsInBound Bug test",
author = "No'",
description = "",
version = "1.0",
url = "http://www.sourcemod.net"
};
public void OnPluginStart() {
float min[3], max[3], pos1[3], pos2[3], pos3[3];
bool result_1, result_2, result_3;
// Min and max vectors
Math_MakeVector(-384.0, -384.0, -63.0, min);
Math_MakeVector(384.0, 384.0, 384.0, max);
// Point to check
Math_MakeVector(-3186.0, -2474.0, -63.9, pos1); // out
Math_MakeVector(-2465.0, 2113.0, -63.9, pos2); // out
Math_MakeVector(-93.0, 12.0, -47.9, pos3); // in
// With Math_IsInBounds
PrintToServer("Min : [%f, %f, %f]", print_vec(min));
PrintToServer("Max : [%f, %f, %f]", print_vec(max));
PrintToServer("Position #1 : [%f, %f, %f]", print_vec(pos1));
PrintToServer("Position #2 : [%f, %f, %f]", print_vec(pos2));
PrintToServer("Position #3 : [%f, %f, %f]", print_vec(pos3));
result_1 = (
Math_IsInBounds(pos1[0], min[0], max[0]) &&
Math_IsInBounds(pos1[1], min[1], max[1]) &&
Math_IsInBounds(pos1[2], min[2], max[2])
);
PrintToServer("Resutl #1 : %s", print_bool(result_1));
result_2 = (
Math_IsInBounds(pos2[0], min[0], max[0]) &&
Math_IsInBounds(pos2[1], min[1], max[1]) &&
Math_IsInBounds(pos2[2], min[2], max[2])
);
PrintToServer("Resutl #2 : %s", print_bool(result_2));
result_3 = (
Math_IsInBounds(pos3[0], min[0], max[0]) &&
Math_IsInBounds(pos3[1], min[1], max[1]) &&
Math_IsInBounds(pos3[2], min[2], max[2])
);
PrintToServer("Resutl #2 : %s", print_bool(result_3));
/*
Min : [-384.000000, -384.000000, -63.000000]
Max : [384.000000, 384.000000, 384.000000]
Position #1 : [-3186.000000, -2474.000000, -63.900001]
Position #2 : [-2465.000000, 2113.000000, -63.900001]
Position #3 : [-93.000000, 12.000000, -47.900001]
Resutl #1 : true
Resutl #2 : false
Resutl #3 : false
*/
// Without Math_IsInBounds
PrintToServer("Min : [%f, %f, %f]", print_vec(min));
PrintToServer("Max : [%f, %f, %f]", print_vec(max));
PrintToServer("Position #1 : [%f, %f, %f]", print_vec(pos1));
PrintToServer("Position #2 : [%f, %f, %f]", print_vec(pos2));
PrintToServer("Position #3 : [%f, %f, %f]", print_vec(pos3));
result_1 = (
(min[0] <= pos1[0] <= max[0]) &&
(min[1] <= pos1[1] <= max[1]) &&
(min[2] <= pos1[2] <= max[2])
);
PrintToServer("Resutl #1 : %s", print_bool(result_1));
result_2 = (
(min[0] <= pos2[0] <= max[0]) &&
(min[1] <= pos2[1] <= max[1]) &&
(min[2] <= pos2[2] <= max[2])
);
PrintToServer("Resutl #2 : %s", print_bool(result_2));
result_3 = (
(min[0] <= pos3[0] <= max[0]) &&
(min[1] <= pos3[1] <= max[1]) &&
(min[2] <= pos3[2] <= max[2])
);
PrintToServer("Resutl #2 : %s", print_bool(result_3));
/*
Min : [-384.000000, -384.000000, -63.000000]
Max : [384.000000, 384.000000, 384.000000]
Position #1 : [-3186.000000, -2474.000000, -63.900001]
Position #2 : [-2465.000000, 2113.000000, -63.900001]
Position #3 : [-93.000000, 12.000000, -47.900001]
Resutl #1 : false
Resutl #2 : false
Resutl #3 : true
*/
}
I don't know where this issue come from but, the code inside the function is ok.
So it's maybe a Sourcemod bug.
sm version
SourceMod Version Information:
SourceMod Version: 1.8.0.5964
SourcePawn Engine: SourcePawn 1.8, jit-x86 (build 1.8.0.5964)
SourcePawn API: v1 = 4, v2 = 11
Compiled on: Dec 9 2016 10:38:26
Built from: https://github.com/alliedmodders/sourcemod/commit/9eae3c7
Build ID: 5964:9eae3c7
http://www.sourcemod.net/