Small float values should be true
parent
5143044cc8
commit
d18709b899
|
@ -163,16 +163,21 @@ AI_FORCE_INLINE
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case aiPTI_Float:
|
case aiPTI_Float:
|
||||||
case aiPTI_Double:
|
case aiPTI_Double: {
|
||||||
case aiPTI_Integer: {
|
// Read as float and cast to bool
|
||||||
// Read as integer and cast to bool
|
float value = 0.0f;
|
||||||
int value = 0;
|
if (AI_SUCCESS == ::aiGetMaterialFloat(this, pKey, type, idx, &value)) {
|
||||||
if (AI_SUCCESS == ::aiGetMaterialInteger(this, pKey, type, idx, &value)) {
|
|
||||||
pOut = static_cast<bool>(value);
|
pOut = static_cast<bool>(value);
|
||||||
return AI_SUCCESS;
|
return AI_SUCCESS;
|
||||||
}
|
}
|
||||||
return AI_FAILURE;
|
return AI_FAILURE;
|
||||||
}
|
}
|
||||||
|
case aiPTI_Integer: {
|
||||||
|
// Cast to bool
|
||||||
|
const int value = static_cast<int>(*prop->mData);
|
||||||
|
pOut = static_cast<bool>(value);
|
||||||
|
return AI_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -151,6 +151,8 @@ TEST_F(MaterialSystemTest, testCastIntProperty) {
|
||||||
EXPECT_EQ(AI_SUCCESS, pcMat->AddProperty(&value, 1, "integer"));
|
EXPECT_EQ(AI_SUCCESS, pcMat->AddProperty(&value, 1, "integer"));
|
||||||
value = 0;
|
value = 0;
|
||||||
EXPECT_EQ(AI_SUCCESS, pcMat->AddProperty(&value, 1, "zero"));
|
EXPECT_EQ(AI_SUCCESS, pcMat->AddProperty(&value, 1, "zero"));
|
||||||
|
value = -1;
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->AddProperty(&value, 1, "negative"));
|
||||||
|
|
||||||
// To float
|
// To float
|
||||||
float valFloat = 0.0f;
|
float valFloat = 0.0f;
|
||||||
|
@ -158,6 +160,8 @@ TEST_F(MaterialSystemTest, testCastIntProperty) {
|
||||||
EXPECT_EQ(10.0f, valFloat);
|
EXPECT_EQ(10.0f, valFloat);
|
||||||
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valFloat));
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valFloat));
|
||||||
EXPECT_EQ(0.0f, valFloat);
|
EXPECT_EQ(0.0f, valFloat);
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("negative", 0, 0, valFloat));
|
||||||
|
EXPECT_EQ(-1.0f, valFloat);
|
||||||
|
|
||||||
// To bool
|
// To bool
|
||||||
bool valBool = false;
|
bool valBool = false;
|
||||||
|
@ -165,6 +169,8 @@ TEST_F(MaterialSystemTest, testCastIntProperty) {
|
||||||
EXPECT_EQ(true, valBool);
|
EXPECT_EQ(true, valBool);
|
||||||
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valBool));
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valBool));
|
||||||
EXPECT_EQ(false, valBool);
|
EXPECT_EQ(false, valBool);
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("negative", 0, 0, valBool));
|
||||||
|
EXPECT_EQ(true, valBool);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -188,3 +194,25 @@ TEST_F(MaterialSystemTest, testCastFloatProperty) {
|
||||||
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valBool));
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valBool));
|
||||||
EXPECT_EQ(false, valBool);
|
EXPECT_EQ(false, valBool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
TEST_F(MaterialSystemTest, testCastSmallFloatProperty) {
|
||||||
|
float value = 0.0078125f;
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->AddProperty(&value, 1, "float"));
|
||||||
|
value = 0;
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->AddProperty(&value, 1, "zero"));
|
||||||
|
|
||||||
|
// To int
|
||||||
|
int valInt = 0.0f;
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("float", 0, 0, valInt));
|
||||||
|
EXPECT_EQ(0, valInt);
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valInt));
|
||||||
|
EXPECT_EQ(0, valInt);
|
||||||
|
|
||||||
|
// To bool
|
||||||
|
bool valBool = false;
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("float", 0, 0, valBool));
|
||||||
|
EXPECT_EQ(true, valBool);
|
||||||
|
EXPECT_EQ(AI_SUCCESS, pcMat->Get("zero", 0, 0, valBool));
|
||||||
|
EXPECT_EQ(false, valBool);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue