Switch from Nz prefix to namespace Nz
What a huge commit Former-commit-id: 38ac5eebf70adc1180f571f6006192d28fb99897
This commit is contained in:
@@ -7,7 +7,7 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
{
|
||||
GIVEN("Allocate and raw constructor")
|
||||
{
|
||||
NzByteArray byteArray(3);
|
||||
Nz::ByteArray byteArray(3);
|
||||
|
||||
THEN("Capacity is 3 and size is 0")
|
||||
{
|
||||
@@ -23,7 +23,7 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
{
|
||||
REQUIRE(byteArray.GetSize() == 4);
|
||||
REQUIRE(byteArray.GetCapacity() >= 4);
|
||||
REQUIRE(byteArray == NzByteArray("data", 4));
|
||||
REQUIRE(byteArray == Nz::ByteArray("data", 4));
|
||||
REQUIRE(byteArray.ToString() == "data");
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,8 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
GIVEN("Iterator and default constructor")
|
||||
{
|
||||
std::string anotherDataString("anotherData");
|
||||
NzByteArray defaultByte;
|
||||
NzByteArray anotherData(anotherDataString.begin(), anotherDataString.end());
|
||||
Nz::ByteArray defaultByte;
|
||||
Nz::ByteArray anotherData(anotherDataString.begin(), anotherDataString.end());
|
||||
|
||||
WHEN("We assign 'anotherData' with iterator")
|
||||
{
|
||||
@@ -48,11 +48,11 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
|
||||
GIVEN("Copy and Move constructor")
|
||||
{
|
||||
NzByteArray originalArray(3, 64);
|
||||
Nz::ByteArray originalArray(3, 64);
|
||||
|
||||
WHEN("We copy")
|
||||
{
|
||||
NzByteArray copyByteArray(originalArray);
|
||||
Nz::ByteArray copyByteArray(originalArray);
|
||||
|
||||
THEN("We get a copy")
|
||||
{
|
||||
@@ -60,13 +60,13 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
|
||||
AND_WHEN("We modify one")
|
||||
{
|
||||
for (NzByteArray::size_type i = 0; i < copyByteArray.GetSize(); ++i)
|
||||
for (Nz::ByteArray::size_type i = 0; i < copyByteArray.GetSize(); ++i)
|
||||
copyByteArray[i] = 46;
|
||||
|
||||
THEN("They are no more equal")
|
||||
{
|
||||
REQUIRE(copyByteArray != originalArray);
|
||||
REQUIRE(copyByteArray == NzByteArray(3, 46));
|
||||
REQUIRE(copyByteArray == Nz::ByteArray(3, 46));
|
||||
REQUIRE(copyByteArray.GetConstBuffer() != originalArray.GetConstBuffer());
|
||||
}
|
||||
}
|
||||
@@ -75,18 +75,18 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
|
||||
WHEN("We move")
|
||||
{
|
||||
NzByteArray moveByteArray(std::move(originalArray));
|
||||
Nz::ByteArray moveByteArray(std::move(originalArray));
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(moveByteArray == NzByteArray(3, 64));
|
||||
REQUIRE(moveByteArray == Nz::ByteArray(3, 64));
|
||||
CHECK(originalArray.IsEmpty());
|
||||
REQUIRE(originalArray.GetCapacity() == 0);
|
||||
REQUIRE(moveByteArray.GetConstBuffer() != originalArray.GetConstBuffer());
|
||||
|
||||
AND_WHEN("We modify the empty one")
|
||||
{
|
||||
originalArray.Prepend(NzByteArray(3, 64));
|
||||
originalArray.Prepend(Nz::ByteArray(3, 64));
|
||||
|
||||
THEN("They are no more equal")
|
||||
{
|
||||
@@ -100,9 +100,9 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
|
||||
GIVEN("Two byte array (abc) and (cba)")
|
||||
{
|
||||
NzByteArray abc("abc", 3);
|
||||
NzByteArray cba;
|
||||
cba = std::move(NzByteArray("cba", 3));
|
||||
Nz::ByteArray abc("abc", 3);
|
||||
Nz::ByteArray cba;
|
||||
cba = std::move(Nz::ByteArray("cba", 3));
|
||||
|
||||
WHEN("We do some antagonists operations")
|
||||
{
|
||||
@@ -116,34 +116,34 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
cba.Erase(cba.end() - 1, cba.end());
|
||||
cba.Erase(cba.end() - 1);
|
||||
|
||||
REQUIRE(abc == NzByteArray("c", 1));
|
||||
REQUIRE(cba == NzByteArray("c", 1));
|
||||
REQUIRE(abc == Nz::ByteArray("c", 1));
|
||||
REQUIRE(cba == Nz::ByteArray("c", 1));
|
||||
|
||||
std::string ab("ab");
|
||||
abc.Insert(abc.begin(), ab.begin(), ab.end());
|
||||
cba += NzByteArray("ba", 2);
|
||||
cba += Nz::ByteArray("ba", 2);
|
||||
|
||||
REQUIRE(abc == NzByteArray("abc", 3));
|
||||
REQUIRE(cba == NzByteArray("cba", 3));
|
||||
REQUIRE(abc == Nz::ByteArray("abc", 3));
|
||||
REQUIRE(cba == Nz::ByteArray("cba", 3));
|
||||
|
||||
abc.PopBack();
|
||||
cba.PopFront();
|
||||
|
||||
REQUIRE(abc == NzByteArray("ab", 2));
|
||||
REQUIRE(cba == NzByteArray("ba", 2));
|
||||
REQUIRE(abc == Nz::ByteArray("ab", 2));
|
||||
REQUIRE(cba == Nz::ByteArray("ba", 2));
|
||||
|
||||
abc.PushBack('c');
|
||||
cba.PushFront('c');
|
||||
|
||||
REQUIRE(abc == NzByteArray("abc", 3));
|
||||
REQUIRE(cba == NzByteArray("cba", 3));
|
||||
REQUIRE(abc == Nz::ByteArray("abc", 3));
|
||||
REQUIRE(cba == Nz::ByteArray("cba", 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("One byte array of capacity 10")
|
||||
{
|
||||
NzByteArray capacityArray(10);
|
||||
Nz::ByteArray capacityArray(10);
|
||||
|
||||
WHEN("We reserve for 100")
|
||||
{
|
||||
@@ -167,7 +167,7 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
}
|
||||
}
|
||||
|
||||
NzByteArray::const_pointer oldBuffer = capacityArray.GetConstBuffer();
|
||||
Nz::ByteArray::const_pointer oldBuffer = capacityArray.GetConstBuffer();
|
||||
WHEN("We reserve for 5, add 'data' for 4 and then shrink to fit")
|
||||
{
|
||||
capacityArray.Reserve(5);
|
||||
@@ -192,14 +192,14 @@ SCENARIO("ByteArray", "[CORE][BYTEARRAY]")
|
||||
|
||||
GIVEN("Three byte array")
|
||||
{
|
||||
NzByteArray first("hello", 5);
|
||||
NzByteArray second("world", 5);
|
||||
NzByteArray third;
|
||||
Nz::ByteArray first("hello", 5);
|
||||
Nz::ByteArray second("world", 5);
|
||||
Nz::ByteArray third;
|
||||
|
||||
WHEN("We swap first and third, then second and third and finally third and first")
|
||||
{
|
||||
NzByteArray oldFirst(first);
|
||||
NzByteArray oldSecond(second);
|
||||
Nz::ByteArray oldFirst(first);
|
||||
Nz::ByteArray oldSecond(second);
|
||||
|
||||
first.Swap(third);
|
||||
std::swap(second, third);
|
||||
|
||||
@@ -6,8 +6,8 @@ SCENARIO("Clock", "[CORE][CLOCK]")
|
||||
{
|
||||
GIVEN("A clock paused")
|
||||
{
|
||||
nzUInt64 initialTime = 1;
|
||||
NzClock clock(initialTime, true);
|
||||
Nz::UInt64 initialTime = 1;
|
||||
Nz::Clock clock(initialTime, true);
|
||||
|
||||
WHEN("We get time")
|
||||
{
|
||||
@@ -21,7 +21,7 @@ SCENARIO("Clock", "[CORE][CLOCK]")
|
||||
clock.Unpause();
|
||||
THEN("Time must not be the initialTime")
|
||||
{
|
||||
NzThread::Sleep(1);
|
||||
Nz::Thread::Sleep(1);
|
||||
REQUIRE(clock.GetMicroseconds() != initialTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ SCENARIO("Color", "[CORE][COLOR]")
|
||||
{
|
||||
GIVEN("Two colors, one red (255) and one gray (128)")
|
||||
{
|
||||
NzColor red(255, 0, 0);
|
||||
NzColor grey(128);
|
||||
Nz::Color red(255, 0, 0);
|
||||
Nz::Color grey(128);
|
||||
|
||||
WHEN("We do operations")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
red += NzColor(0, 0, 0);
|
||||
grey *= NzColor(255);
|
||||
REQUIRE((red + grey) == NzColor(255, 128, 128));
|
||||
REQUIRE((red * grey) == NzColor(128, 0, 0));
|
||||
red += Nz::Color(0, 0, 0);
|
||||
grey *= Nz::Color(255);
|
||||
REQUIRE((red + grey) == Nz::Color(255, 128, 128));
|
||||
REQUIRE((red * grey) == Nz::Color(128, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,28 +5,28 @@ SCENARIO("Directory", "[CORE][DIRECTORY]")
|
||||
{
|
||||
GIVEN("The current directory")
|
||||
{
|
||||
NzDirectory currentDirectory(NzDirectory::GetCurrent());
|
||||
Nz::Directory currentDirectory(Nz::Directory::GetCurrent());
|
||||
CHECK(currentDirectory.Exists());
|
||||
currentDirectory.Open();
|
||||
|
||||
WHEN("We create a new directory Test Directory")
|
||||
{
|
||||
NzDirectory::Create("Test Directory");
|
||||
Nz::Directory::Create("Test Directory");
|
||||
|
||||
THEN("A new directory has been created")
|
||||
{
|
||||
CHECK(NzDirectory::Exists(currentDirectory.GetCurrent() + "/Test Directory"));
|
||||
CHECK(Nz::Directory::Exists(currentDirectory.GetCurrent() + "/Test Directory"));
|
||||
CHECK(currentDirectory.IsOpen());
|
||||
}
|
||||
}
|
||||
|
||||
AND_WHEN("We delete it")
|
||||
{
|
||||
NzDirectory::Remove(currentDirectory.GetCurrent() + "/Test Directory", true);
|
||||
Nz::Directory::Remove(currentDirectory.GetCurrent() + "/Test Directory", true);
|
||||
|
||||
THEN("It doesn't exist anymore")
|
||||
{
|
||||
CHECK(!NzDirectory::Exists(currentDirectory.GetCurrent() + "/Test Directory"));
|
||||
CHECK(!Nz::Directory::Exists(currentDirectory.GetCurrent() + "/Test Directory"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
SCENARIO("Error", "[CORE][ERROR]")
|
||||
{
|
||||
nzUInt32 oldFlags = NzError::GetFlags();
|
||||
Nz::UInt32 oldFlags = Nz::Error::GetFlags();
|
||||
|
||||
GIVEN("Multiple errors")
|
||||
{
|
||||
@@ -11,18 +11,18 @@ SCENARIO("Error", "[CORE][ERROR]")
|
||||
{
|
||||
THEN("These errors should be written in the log file")
|
||||
{
|
||||
NzError::Error(nzErrorType_Internal, "nzErrorType_Internal");
|
||||
NzError::Error(nzErrorType_Internal, "nzErrorType_Internal", 2, "Error.cpp", "2nd place Internal");
|
||||
REQUIRE("nzErrorType_Internal" == NzError::GetLastError());
|
||||
NzError::Error(nzErrorType_Normal, "nzErrorType_Normal");
|
||||
NzError::Error(nzErrorType_Normal, "nzErrorType_Normal", 2, "Error.cpp", "2nd place Normal");
|
||||
REQUIRE("nzErrorType_Normal" == NzError::GetLastError());
|
||||
NzError::Error(nzErrorType_Warning, "nzErrorType_Warning");
|
||||
NzError::Error(nzErrorType_Warning, "nzErrorType_Warning", 2, "Error.cpp", "2nd place Warning");
|
||||
REQUIRE("nzErrorType_Warning" == NzError::GetLastError());
|
||||
Nz::Error::Trigger(Nz::ErrorType_Internal, "ErrorType_Internal");
|
||||
Nz::Error::Trigger(Nz::ErrorType_Internal, "ErrorType_Internal", 2, "Error.cpp", "2nd place Internal");
|
||||
REQUIRE("ErrorType_Internal" == Nz::Error::GetLastError());
|
||||
Nz::Error::Trigger(Nz::ErrorType_Normal, "ErrorType_Normal");
|
||||
Nz::Error::Trigger(Nz::ErrorType_Normal, "ErrorType_Normal", 2, "Error.cpp", "2nd place Normal");
|
||||
REQUIRE("ErrorType_Normal" == Nz::Error::GetLastError());
|
||||
Nz::Error::Trigger(Nz::ErrorType_Warning, "ErrorType_Warning");
|
||||
Nz::Error::Trigger(Nz::ErrorType_Warning, "ErrorType_Warning", 2, "Error.cpp", "2nd place Warning");
|
||||
REQUIRE("ErrorType_Warning" == Nz::Error::GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NzError::SetFlags(oldFlags);
|
||||
Nz::Error::SetFlags(oldFlags);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ SCENARIO("File", "[CORE][FILE]")
|
||||
{
|
||||
WHEN("We create a new file")
|
||||
{
|
||||
NzFile file("Test File.txt", nzOpenMode_ReadWrite);
|
||||
REQUIRE(file.GetDirectory() == NzDirectory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR);
|
||||
Nz::File file("Test File.txt", Nz::OpenMode_ReadWrite);
|
||||
REQUIRE(file.GetDirectory() == Nz::Directory::GetCurrent() + NAZARA_DIRECTORY_SEPARATOR);
|
||||
CHECK(file.IsOpen());
|
||||
|
||||
THEN("We are allowed to write 3 times 'Test String'")
|
||||
{
|
||||
const char message[12] = "Test String"; // 11 + '\0'
|
||||
NzByteArray byteArray(message, 11);
|
||||
Nz::ByteArray byteArray(message, 11);
|
||||
file.Write("Test String");
|
||||
file.Write(byteArray);
|
||||
file.Write(message, sizeof(char), 11);
|
||||
@@ -25,11 +25,11 @@ SCENARIO("File", "[CORE][FILE]")
|
||||
char message[12];
|
||||
REQUIRE(file.Read(message, 11) == 11);
|
||||
message[11] = '\0';
|
||||
REQUIRE(NzString(message) == "Test String");
|
||||
REQUIRE(Nz::String(message) == "Test String");
|
||||
|
||||
REQUIRE(file.Read(message, sizeof(char), 11) == 11);
|
||||
message[11] = '\0';
|
||||
REQUIRE(NzString(message) == "Test String");
|
||||
REQUIRE(Nz::String(message) == "Test String");
|
||||
}
|
||||
|
||||
AND_THEN("We close it")
|
||||
@@ -42,11 +42,11 @@ SCENARIO("File", "[CORE][FILE]")
|
||||
|
||||
WHEN("We delete this file")
|
||||
{
|
||||
NzFile::Delete("Test File.txt");
|
||||
Nz::File::Delete("Test File.txt");
|
||||
|
||||
THEN("It doesn't exist anymore")
|
||||
{
|
||||
CHECK(!NzFile::Exists("Test File.txt"));
|
||||
CHECK(!Nz::File::Exists("Test File.txt"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ SCENARIO("String", "[CORE][STRING]")
|
||||
{
|
||||
GIVEN("One string 'a'")
|
||||
{
|
||||
NzString aDefaultString(1, 'a');
|
||||
Nz::String aDefaultString(1, 'a');
|
||||
|
||||
WHEN("We add information")
|
||||
{
|
||||
@@ -25,12 +25,12 @@ SCENARIO("String", "[CORE][STRING]")
|
||||
{
|
||||
CHECK(aDefaultString.Contains('D'));
|
||||
CHECK(aDefaultString.Contains("String", 3));
|
||||
CHECK(aDefaultString.Contains(NzString("sTRING"), 3, NzString::CaseInsensitive));
|
||||
CHECK(aDefaultString.Contains(Nz::String("sTRING"), 3, Nz::String::CaseInsensitive));
|
||||
REQUIRE(aDefaultString.FindLast('g') == aDefaultString.GetSize() - 1);
|
||||
CHECK(aDefaultString.EndsWith('G', NzString::CaseInsensitive));
|
||||
CHECK(aDefaultString.EndsWith('G', Nz::String::CaseInsensitive));
|
||||
aDefaultString.Append(" ng bla");
|
||||
REQUIRE(aDefaultString.FindWord("ng") == aDefaultString.GetSize() - 6);
|
||||
//TODO REQUIRE(aDefaultString.FindWord(NzString("ng")) == aDefaultString.GetSize() - 6);
|
||||
//TODO REQUIRE(aDefaultString.FindWord(String("ng")) == aDefaultString.GetSize() - 6);
|
||||
CHECK(aDefaultString.StartsWith("aD"));
|
||||
}
|
||||
}
|
||||
@@ -62,14 +62,14 @@ SCENARIO("String", "[CORE][STRING]")
|
||||
|
||||
GIVEN("The string of number 16 in base 16")
|
||||
{
|
||||
NzString number16;
|
||||
Nz::String number16;
|
||||
|
||||
CHECK(number16.IsEmpty());
|
||||
CHECK(number16.IsNull());
|
||||
|
||||
WHEN("We assign to number 16")
|
||||
{
|
||||
number16 = NzString::Number(16, 16);
|
||||
number16 = Nz::String::Number(16, 16);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
@@ -85,7 +85,7 @@ SCENARIO("String", "[CORE][STRING]")
|
||||
/* TODO
|
||||
GIVEN("One unicode string")
|
||||
{
|
||||
NzString unicodeString = NzString::Unicode(U"àéçœÂ官話");
|
||||
String unicodeString = String::Unicode(U"àéçœÂ官話");
|
||||
|
||||
WHEN("We convert to other UTF")
|
||||
{
|
||||
@@ -96,11 +96,11 @@ SCENARIO("String", "[CORE][STRING]")
|
||||
THEN("The result should be the identity")
|
||||
{
|
||||
char* utf8 = unicodeString.GetUtf8Buffer();
|
||||
NzString utf8String = NzString::Unicode(utf8);
|
||||
String utf8String = String::Unicode(utf8);
|
||||
char16_t* utf16 = unicodeString.GetUtf16Buffer();
|
||||
NzString utf16String = NzString::Unicode(utf16);
|
||||
String utf16String = String::Unicode(utf16);
|
||||
char32_t* utf32 = unicodeString.GetUtf32Buffer();
|
||||
NzString utf32String = NzString::Unicode(utf32);
|
||||
String utf32String = String::Unicode(utf32);
|
||||
|
||||
REQUIRE(utf8String == utf16String);
|
||||
REQUIRE(utf16String == utf32String);
|
||||
|
||||
@@ -5,67 +5,67 @@ SCENARIO("StringStream", "[CORE][STRINGSTREAM]")
|
||||
{
|
||||
GIVEN("A string stream")
|
||||
{
|
||||
NzStringStream stringstream("default");
|
||||
Nz::StringStream stringStream("default");
|
||||
|
||||
WHEN("We add bool and char")
|
||||
{
|
||||
stringstream << true;
|
||||
stringStream << true;
|
||||
|
||||
char valueCharSigned = 64;
|
||||
stringstream << valueCharSigned;
|
||||
stringStream << valueCharSigned;
|
||||
unsigned char valueCharUnsigned = 64;
|
||||
stringstream << valueCharUnsigned;
|
||||
stringStream << valueCharUnsigned;
|
||||
|
||||
REQUIRE(stringstream.ToString() == "defaulttrue@@");
|
||||
REQUIRE(stringStream.ToString() == "defaulttrue@@");
|
||||
}
|
||||
|
||||
AND_WHEN("We add short and int")
|
||||
{
|
||||
short valueShortSigned = -3;
|
||||
stringstream << valueShortSigned;
|
||||
stringStream << valueShortSigned;
|
||||
unsigned short valueShortUnsigned = 3;
|
||||
stringstream << valueShortUnsigned;
|
||||
stringStream << valueShortUnsigned;
|
||||
|
||||
int valueIntSigned = -3;
|
||||
stringstream << valueIntSigned;
|
||||
stringStream << valueIntSigned;
|
||||
unsigned int valueIntUnsigned = 3;
|
||||
stringstream << valueIntUnsigned;
|
||||
stringStream << valueIntUnsigned;
|
||||
|
||||
REQUIRE(stringstream.ToString() == "default-33-33");
|
||||
REQUIRE(stringStream.ToString() == "default-33-33");
|
||||
}
|
||||
|
||||
AND_WHEN("We add long and long long")
|
||||
{
|
||||
long valueLongSigned = -3;
|
||||
stringstream << valueLongSigned;
|
||||
stringStream << valueLongSigned;
|
||||
unsigned long valueLongUnsigned = 3;
|
||||
stringstream << valueLongUnsigned;
|
||||
stringStream << valueLongUnsigned;
|
||||
|
||||
long long valueLongLongSigned = -3;
|
||||
stringstream << valueLongLongSigned;
|
||||
stringStream << valueLongLongSigned;
|
||||
unsigned long long valueLongLongUnsigned = 3;
|
||||
stringstream << valueLongLongUnsigned;
|
||||
stringStream << valueLongLongUnsigned;
|
||||
|
||||
REQUIRE(stringstream.ToString() == "default-33-33");
|
||||
REQUIRE(stringStream.ToString() == "default-33-33");
|
||||
}
|
||||
|
||||
AND_WHEN("We add floating points")
|
||||
{
|
||||
stringstream << 3.f;
|
||||
stringstream << 3.0;
|
||||
stringstream << 3.0L;
|
||||
stringStream << 3.f;
|
||||
stringStream << 3.0;
|
||||
stringStream << 3.0L;
|
||||
|
||||
REQUIRE(stringstream.ToString() == "default333");
|
||||
REQUIRE(stringStream.ToString() == "default333");
|
||||
}
|
||||
|
||||
AND_WHEN("We add string and pointer")
|
||||
{
|
||||
stringstream << "3";
|
||||
stringstream << std::string("3");
|
||||
stringstream << NzString("3");
|
||||
stringstream << static_cast<void*>(nullptr);
|
||||
stringStream << "3";
|
||||
stringStream << std::string("3");
|
||||
stringStream << Nz::String("3");
|
||||
stringStream << static_cast<void*>(nullptr);
|
||||
|
||||
REQUIRE(stringstream.ToString() == (NzString("default333") + NzString::Pointer(nullptr)));
|
||||
REQUIRE(stringStream.ToString() == (Nz::String("default333") + Nz::String::Pointer(nullptr)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,17 @@ TEST_CASE("Approach", "[MATH][ALGORITHM]" )
|
||||
{
|
||||
SECTION("Approach 8 with 5 by 2")
|
||||
{
|
||||
REQUIRE(NzApproach(5, 8, 2) == 7);
|
||||
REQUIRE(Nz::Approach(5, 8, 2) == 7);
|
||||
}
|
||||
|
||||
SECTION("Approach 5 with 8 by 2")
|
||||
{
|
||||
REQUIRE(NzApproach(8, 5, 2) == 6);
|
||||
REQUIRE(Nz::Approach(8, 5, 2) == 6);
|
||||
}
|
||||
|
||||
SECTION("Approach 8 with 8 by 2")
|
||||
{
|
||||
REQUIRE(NzApproach(8, 8, 2) == 8);
|
||||
REQUIRE(Nz::Approach(8, 8, 2) == 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@ TEST_CASE("Clamp", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("Clamp 8 between 5 and 10")
|
||||
{
|
||||
REQUIRE(NzClamp(8, 5, 10) == 8);
|
||||
REQUIRE(Nz::Clamp(8, 5, 10) == 8);
|
||||
}
|
||||
|
||||
SECTION("Clamp 4 between 5 and 10")
|
||||
{
|
||||
REQUIRE(NzClamp(4, 5, 10) == 5);
|
||||
REQUIRE(Nz::Clamp(4, 5, 10) == 5);
|
||||
}
|
||||
|
||||
SECTION("Clamp 12 between 5 and 10")
|
||||
{
|
||||
REQUIRE(NzClamp(12, 5, 10) == 10);
|
||||
REQUIRE(Nz::Clamp(12, 5, 10) == 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ TEST_CASE("DegreeToRadian", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("Convert 45.f degree to radian")
|
||||
{
|
||||
REQUIRE(NzDegreeToRadian(45.f) == Approx(M_PI / 4));
|
||||
REQUIRE(Nz::NzDegreeToRadian(45.f) == Approx(M_PI / 4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ TEST_CASE("GetNearestPowerOfTwo", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("Nearest power of two of 16 = 16")
|
||||
{
|
||||
REQUIRE(NzGetNearestPowerOfTwo(16) == 16);
|
||||
REQUIRE(Nz::GetNearestPowerOfTwo(16) == 16);
|
||||
}
|
||||
|
||||
SECTION("Nearest power of two of 17 = 32")
|
||||
{
|
||||
REQUIRE(NzGetNearestPowerOfTwo(17) == 32);
|
||||
REQUIRE(Nz::GetNearestPowerOfTwo(17) == 32);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,55 +63,55 @@ TEST_CASE("GetNumberLength", "[ALGORITHM]" )
|
||||
SECTION("GetNumberLength of -127 signed char")
|
||||
{
|
||||
signed char minus127 = -127;
|
||||
REQUIRE(NzGetNumberLength(minus127) == 4);
|
||||
REQUIRE(Nz::GetNumberLength(minus127) == 4);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of 255 unsigned char")
|
||||
{
|
||||
unsigned char plus255 = 255;
|
||||
REQUIRE(NzGetNumberLength(plus255) == 3);
|
||||
REQUIRE(Nz::GetNumberLength(plus255) == 3);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of -1270 signed int")
|
||||
{
|
||||
signed int minus1270 = -1270;
|
||||
REQUIRE(NzGetNumberLength(minus1270) == 5);
|
||||
REQUIRE(Nz::GetNumberLength(minus1270) == 5);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of 2550 unsigned int")
|
||||
{
|
||||
unsigned int plus2550 = 2550;
|
||||
REQUIRE(NzGetNumberLength(plus2550) == 4);
|
||||
REQUIRE(Nz::GetNumberLength(plus2550) == 4);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of -1270 signed long long")
|
||||
{
|
||||
signed long long minus12700 = -12700;
|
||||
REQUIRE(NzGetNumberLength(minus12700) == 6);
|
||||
REQUIRE(Nz::GetNumberLength(minus12700) == 6);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of 2550 unsigned long long")
|
||||
{
|
||||
unsigned long long plus25500 = 25500;
|
||||
REQUIRE(NzGetNumberLength(plus25500) == 5);
|
||||
REQUIRE(Nz::GetNumberLength(plus25500) == 5);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of -2.456f float")
|
||||
{
|
||||
float minus2P456 = -2.456f;
|
||||
REQUIRE(NzGetNumberLength(minus2P456, 3) == 6);
|
||||
REQUIRE(Nz::GetNumberLength(minus2P456, 3) == 6);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of -2.456 double")
|
||||
{
|
||||
double minus2P456 = -2.456;
|
||||
REQUIRE(NzGetNumberLength(minus2P456, 3) == 6);
|
||||
REQUIRE(Nz::GetNumberLength(minus2P456, 3) == 6);
|
||||
}
|
||||
|
||||
SECTION("GetNumberLength of -2.456 long double")
|
||||
{
|
||||
long double minus2P456 = -2.456L;
|
||||
REQUIRE(NzGetNumberLength(minus2P456, 3) == 6);
|
||||
REQUIRE(Nz::GetNumberLength(minus2P456, 3) == 6);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ TEST_CASE("IntegralPow", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("2 to power 4")
|
||||
{
|
||||
REQUIRE(NzIntegralPow(2, 4) == 16);
|
||||
REQUIRE(Nz::IntegralPow(2, 4) == 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ TEST_CASE("Lerp", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("Lerp 2 to 6 with 0.5")
|
||||
{
|
||||
REQUIRE(NzLerp(2, 6, 0.5) == 4);
|
||||
REQUIRE(Nz::Lerp(2, 6, 0.5) == 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ TEST_CASE("MultiplyAdd", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("2 * 3 + 1")
|
||||
{
|
||||
REQUIRE(NzMultiplyAdd(2, 3, 1) == 7);
|
||||
REQUIRE(Nz::MultiplyAdd(2, 3, 1) == 7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,12 +143,12 @@ TEST_CASE("NumberEquals", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("2.35 and 2.351 should be the same at 0.01")
|
||||
{
|
||||
CHECK(NzNumberEquals(2.35, 2.35, 0.01));
|
||||
CHECK(Nz::NumberEquals(2.35, 2.35, 0.01));
|
||||
}
|
||||
|
||||
SECTION("3 and 4 unsigned should be the same at 1")
|
||||
{
|
||||
CHECK(NzNumberEquals(3U, 4U, 1U));
|
||||
CHECK(Nz::NumberEquals(3U, 4U, 1U));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,17 +156,17 @@ TEST_CASE("NumberToString", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("235 to string")
|
||||
{
|
||||
REQUIRE(NzNumberToString(235) == "235");
|
||||
REQUIRE(Nz::NumberToString(235) == "235");
|
||||
}
|
||||
|
||||
SECTION("-235 to string")
|
||||
{
|
||||
REQUIRE(NzNumberToString(-235) == "-235");
|
||||
REQUIRE(Nz::NumberToString(-235) == "-235");
|
||||
}
|
||||
|
||||
SECTION("16 in base 16 to string")
|
||||
{
|
||||
REQUIRE(NzNumberToString(16, 16) == "10");
|
||||
REQUIRE(Nz::NumberToString(16, 16) == "10");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ TEST_CASE("RadianToDegree", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("PI / 4 to degree")
|
||||
{
|
||||
REQUIRE(NzRadianToDegree(M_PI / 4) == Approx(45.f));
|
||||
REQUIRE(Nz::RadianToDegree(M_PI / 4) == Approx(45.f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,16 +182,16 @@ TEST_CASE("StringToNumber", "[ALGORITHM]" )
|
||||
{
|
||||
SECTION("235 in string")
|
||||
{
|
||||
REQUIRE(NzStringToNumber("235") == 235);
|
||||
REQUIRE(Nz::StringToNumber("235") == 235);
|
||||
}
|
||||
|
||||
SECTION("-235 in string")
|
||||
{
|
||||
REQUIRE(NzStringToNumber("-235") == -235);
|
||||
REQUIRE(Nz::StringToNumber("-235") == -235);
|
||||
}
|
||||
|
||||
SECTION("16 in base 16 in string")
|
||||
{
|
||||
REQUIRE(NzStringToNumber("10", 16) == 16);
|
||||
REQUIRE(Nz::StringToNumber("10", 16) == 16);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
|
||||
{
|
||||
GIVEN("With a null bounding volume and an infinite")
|
||||
{
|
||||
NzBoundingVolumef nullVolume = NzBoundingVolumef::Null();
|
||||
NzBoundingVolumef infiniteVolume = NzBoundingVolumef::Infinite();
|
||||
Nz::BoundingVolumef nullVolume = Nz::BoundingVolumef::Null();
|
||||
Nz::BoundingVolumef infiniteVolume = Nz::BoundingVolumef::Infinite();
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -49,18 +49,18 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
|
||||
{
|
||||
THEN("Everything should be ok")
|
||||
{
|
||||
REQUIRE(NzBoundingVolumef::Null() == NzBoundingVolumef::Null());
|
||||
REQUIRE(NzBoundingVolumef::Infinite() == NzBoundingVolumef::Infinite());
|
||||
REQUIRE(Nz::BoundingVolumef::Null() == Nz::BoundingVolumef::Null());
|
||||
REQUIRE(Nz::BoundingVolumef::Infinite() == Nz::BoundingVolumef::Infinite());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Two same bounding volume with different constructor")
|
||||
{
|
||||
NzBoundingVolumef firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
|
||||
NzBoundingVolumef secondCenterAndUnit(NzVector3f::Zero(), NzVector3f::Unit());
|
||||
firstCenterAndUnit.Update(NzMatrix4f::Identity());
|
||||
secondCenterAndUnit.Update(NzMatrix4f::Identity());
|
||||
Nz::BoundingVolumef firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
|
||||
Nz::BoundingVolumef secondCenterAndUnit(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
|
||||
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
|
||||
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -83,15 +83,15 @@ SCENARIO("BoundingVolume", "[MATH][BOUNDINGVOLUME]")
|
||||
{
|
||||
THEN("There's no problem")
|
||||
{
|
||||
NzBoundingVolume<int> intVolumeCenterAndUnit(NzBoxi(NzVector3i::Zero(), NzVector3i::Unit()));
|
||||
NzBoundingVolumef thirdCenterAndUnit(intVolumeCenterAndUnit);
|
||||
Nz::BoundingVolume<int> intVolumeCenterAndUnit(Nz::Boxi(Nz::Vector3i::Zero(), Nz::Vector3i::Unit()));
|
||||
Nz::BoundingVolumef thirdCenterAndUnit(intVolumeCenterAndUnit);
|
||||
REQUIRE(thirdCenterAndUnit == secondCenterAndUnit);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We make one twice bigger with a matrix")
|
||||
{
|
||||
firstCenterAndUnit.Update(NzMatrix4f::Scale(NzVector3f::Unit() * 2.f));
|
||||
firstCenterAndUnit.Update(Nz::Matrix4f::Scale(Nz::Vector3f::Unit() * 2.f));
|
||||
|
||||
THEN("The local box should be the same but the aabb different")
|
||||
{
|
||||
|
||||
@@ -5,13 +5,13 @@ SCENARIO("Box", "[MATH][BOX]")
|
||||
{
|
||||
GIVEN("Two zero boxes")
|
||||
{
|
||||
NzBoxf firstZero(NzBoxf::Zero());
|
||||
NzBoxf secondZero(NzVector3f::Zero(), NzVector3f::Zero());
|
||||
Nz::Boxf firstZero(Nz::Boxf::Zero());
|
||||
Nz::Boxf secondZero(Nz::Vector3f::Zero(), Nz::Vector3f::Zero());
|
||||
|
||||
WHEN("We multiply them")
|
||||
{
|
||||
firstZero = firstZero * 1.f;
|
||||
secondZero = secondZero * NzVector3f::Unit() * 3.f;
|
||||
secondZero = secondZero * Nz::Vector3f::Unit() * 3.f;
|
||||
|
||||
THEN("They should stay the same")
|
||||
{
|
||||
@@ -24,24 +24,24 @@ SCENARIO("Box", "[MATH][BOX]")
|
||||
|
||||
GIVEN("Two unit and center boxes")
|
||||
{
|
||||
NzBoxf firstCenterAndUnit(NzRectf(NzVector2f::Zero(), NzVector2f::Unit()));
|
||||
NzBoxf secondCenterAndUnit(1.f, 1.f, 1.f);
|
||||
Nz::Boxf firstCenterAndUnit(Nz::Rectf(Nz::Vector2f::Zero(), Nz::Vector2f::Unit()));
|
||||
Nz::Boxf secondCenterAndUnit(1.f, 1.f, 1.f);
|
||||
|
||||
WHEN("We ask for some informations")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit.GetBoundingSphere() == NzSpheref(NzVector3f::Unit() * 0.5f, std::sqrt(3.f * 0.5f * 0.5f)));
|
||||
REQUIRE(firstCenterAndUnit.GetCenter() == (NzVector3f::Unit() * 0.5f));
|
||||
REQUIRE(firstCenterAndUnit.GetCorner(nzBoxCorner_FarLeftTop) == NzVector3f::UnitY());
|
||||
REQUIRE(firstCenterAndUnit.GetLengths() == NzVector3f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMaximum() == NzVector3f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMinimum() == NzVector3f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetNegativeVertex(NzVector3f::Unit()) == NzVector3f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPosition() == NzVector3f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPositiveVertex(NzVector3f::Unit()) == NzVector3f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetBoundingSphere() == Nz::Spheref(Nz::Vector3f::Unit() * 0.5f, std::sqrt(3.f * 0.5f * 0.5f)));
|
||||
REQUIRE(firstCenterAndUnit.GetCenter() == (Nz::Vector3f::Unit() * 0.5f));
|
||||
REQUIRE(firstCenterAndUnit.GetCorner(Nz::BoxCorner_FarLeftTop) == Nz::Vector3f::UnitY());
|
||||
REQUIRE(firstCenterAndUnit.GetLengths() == Nz::Vector3f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMaximum() == Nz::Vector3f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMinimum() == Nz::Vector3f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetNegativeVertex(Nz::Vector3f::Unit()) == Nz::Vector3f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPosition() == Nz::Vector3f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPositiveVertex(Nz::Vector3f::Unit()) == Nz::Vector3f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetRadius() == Approx(std::sqrt(3.f * 0.5f * 0.5f)));
|
||||
REQUIRE(firstCenterAndUnit.GetSquaredBoundingSphere() == NzSpheref(NzVector3f::Unit() * 0.5f, 3.f * 0.5f * 0.5f));
|
||||
REQUIRE(firstCenterAndUnit.GetSquaredBoundingSphere() == Nz::Spheref(Nz::Vector3f::Unit() * 0.5f, 3.f * 0.5f * 0.5f));
|
||||
REQUIRE(firstCenterAndUnit.GetSquaredRadius() == Approx(3.f * 0.5f * 0.5f));
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ SCENARIO("Box", "[MATH][BOX]")
|
||||
{
|
||||
THEN("We should have a center and unit")
|
||||
{
|
||||
NzBoxf thirdCenterAndUnit;
|
||||
Nz::Boxf thirdCenterAndUnit;
|
||||
CHECK(firstCenterAndUnit.Intersect(secondCenterAndUnit, &thirdCenterAndUnit));
|
||||
REQUIRE(firstCenterAndUnit == secondCenterAndUnit);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ SCENARIO("Box", "[MATH][BOX]")
|
||||
{
|
||||
THEN("Shouldn't be a problem")
|
||||
{
|
||||
NzBoxf tmp(NzBoxi(0, 0, 0, 1, 1, 1));
|
||||
Nz::Boxf tmp(Nz::Boxi(0, 0, 0, 1, 1, 1));
|
||||
REQUIRE(tmp == firstCenterAndUnit);
|
||||
}
|
||||
}
|
||||
@@ -68,8 +68,8 @@ SCENARIO("Box", "[MATH][BOX]")
|
||||
|
||||
GIVEN("Two wrong box (negative width, height and depth")
|
||||
{
|
||||
NzBoxf firstWrongBox(-NzVector3f::Unit());
|
||||
NzBoxf secondWrongBox(-NzVector3f::Unit());
|
||||
Nz::Boxf firstWrongBox(-Nz::Vector3f::Unit());
|
||||
Nz::Boxf secondWrongBox(-Nz::Vector3f::Unit());
|
||||
|
||||
WHEN("We check if valid")
|
||||
{
|
||||
@@ -82,8 +82,8 @@ SCENARIO("Box", "[MATH][BOX]")
|
||||
|
||||
WHEN("We correct them")
|
||||
{
|
||||
firstWrongBox.ExtendTo(NzVector3f::Unit());
|
||||
secondWrongBox.Transform(NzMatrix4f::Scale(-NzVector3f::Unit()));
|
||||
firstWrongBox.ExtendTo(Nz::Vector3f::Unit());
|
||||
secondWrongBox.Transform(Nz::Matrix4f::Scale(-Nz::Vector3f::Unit()));
|
||||
|
||||
THEN("They should be valid")
|
||||
{
|
||||
@@ -98,13 +98,13 @@ SCENARIO("Box", "[MATH][BOX]")
|
||||
CHECK(firstWrongBox.Contains(0.f, 0.f, 0.f));
|
||||
CHECK(secondWrongBox.Contains(0.f, 0.f, 0.f));
|
||||
|
||||
secondWrongBox = secondWrongBox.Lerp(NzBoxf::Zero(), secondWrongBox, 0.f); // Zeroed
|
||||
secondWrongBox.ExtendTo(NzBoxf(NzVector3f(0.1f, 0.1f, 0.1f), NzVector3f(0.9f, 0.9f, 0.9f)));
|
||||
secondWrongBox.Translate(NzVector3f(0.05f, 0.05f, 0.05f)); // Box 0.15 to 0.95
|
||||
secondWrongBox = secondWrongBox.Lerp(Nz::Boxf::Zero(), secondWrongBox, 0.f); // Zeroed
|
||||
secondWrongBox.ExtendTo(Nz::Boxf(Nz::Vector3f(0.1f, 0.1f, 0.1f), Nz::Vector3f(0.9f, 0.9f, 0.9f)));
|
||||
secondWrongBox.Translate(Nz::Vector3f(0.05f, 0.05f, 0.05f)); // Box 0.15 to 0.95
|
||||
CHECK(firstWrongBox.Contains(secondWrongBox));
|
||||
|
||||
NzBoxf test(1.f, -500.f, -500.f, 1000.f, 1000.f, 1000.f);
|
||||
CHECK(test.Contains(NzBoxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
|
||||
Nz::Boxf test(1.f, -500.f, -500.f, 1000.f, 1000.f, 1000.f);
|
||||
CHECK(test.Contains(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
|
||||
CHECK(test.Contains(500.f, 0.f, 0.f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
|
||||
{
|
||||
GIVEN("Two zero euler angles")
|
||||
{
|
||||
NzEulerAnglesf firstZero(0.f, 0.f, 0.f);
|
||||
NzEulerAnglesf secondZero(NzEulerAngles<int>::Zero());
|
||||
Nz::EulerAnglesf firstZero(0.f, 0.f, 0.f);
|
||||
Nz::EulerAnglesf secondZero(Nz::EulerAngles<int>::Zero());
|
||||
|
||||
THEN("They should be equal")
|
||||
{
|
||||
@@ -15,12 +15,12 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
|
||||
|
||||
WHEN("We do some operations")
|
||||
{
|
||||
NzEulerAnglesf euler90(90.f, 90.f, 90.f);
|
||||
NzEulerAnglesf euler270(270.f, 270.f, 270.f);
|
||||
Nz::EulerAnglesf euler90(90.f, 90.f, 90.f);
|
||||
Nz::EulerAnglesf euler270(270.f, 270.f, 270.f);
|
||||
|
||||
NzEulerAnglesf euler360 = euler90 + euler270;
|
||||
Nz::EulerAnglesf euler360 = euler90 + euler270;
|
||||
euler360.Normalize();
|
||||
NzEulerAnglesf euler0 = euler270 - euler90;
|
||||
Nz::EulerAnglesf euler0 = euler270 - euler90;
|
||||
euler0 -= euler90;
|
||||
euler0 -= euler90;
|
||||
|
||||
@@ -36,8 +36,8 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
|
||||
THEN("They are the same")
|
||||
{
|
||||
REQUIRE(firstZero.ToQuaternion() == secondZero.ToQuaternion());
|
||||
REQUIRE(firstZero.ToQuaternion() == NzEulerAnglesf(NzQuaternionf(1.f, 0.f, 0.f, 0.f)));
|
||||
REQUIRE(secondZero.ToQuaternion() == NzEulerAnglesf(NzQuaternionf(1.f, 0.f, 0.f, 0.f)));
|
||||
REQUIRE(firstZero.ToQuaternion() == Nz::EulerAnglesf(Nz::Quaternionf(1.f, 0.f, 0.f, 0.f)));
|
||||
REQUIRE(secondZero.ToQuaternion() == Nz::EulerAnglesf(Nz::Quaternionf(1.f, 0.f, 0.f, 0.f)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,32 +48,32 @@ SCENARIO("EulerAngles", "[MATH][EULERANGLES]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(NzEulerAngles<int>(NzFromDegrees(45.f), 0.f, 0.f) == NzEulerAngles<int>(NzQuaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()));
|
||||
REQUIRE(NzEulerAngles<int>(0.f, NzFromDegrees(45.f), 0.f) == NzEulerAngles<int>(NzQuaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()));
|
||||
REQUIRE(NzEulerAngles<int>(0.f, 0.f, NzFromDegrees(45.f)) == NzEulerAngles<int>(NzQuaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()));
|
||||
REQUIRE(Nz::EulerAngles<int>(Nz::FromDegrees(45.f), 0.f, 0.f) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.382683455944f, 0.f, 0.f).ToEulerAngles()));
|
||||
REQUIRE(Nz::EulerAngles<int>(0.f, Nz::FromDegrees(45.f), 0.f) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.f, 0.382683455944f, 0.f).ToEulerAngles()));
|
||||
REQUIRE(Nz::EulerAngles<int>(0.f, 0.f, Nz::FromDegrees(45.f)) == Nz::EulerAngles<int>(Nz::Quaternionf(0.923879504204f, 0.f, 0.f, 0.382683455944f).ToEulerAngles()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("Three euler angles: (0, 22.5, 22.5), (90, 90, 0) and (30, 0, 30)")
|
||||
{
|
||||
NzEulerAnglesf euler45(NzFromDegrees(0.f), NzFromDegrees(22.5f), NzFromDegrees(22.5f));
|
||||
NzEulerAnglesf euler90(NzFromDegrees(90.f), NzFromDegrees(90.f), NzFromDegrees(0.f));
|
||||
NzEulerAnglesf euler30(NzFromDegrees(30.f), NzFromDegrees(0.f), NzFromDegrees(30.f));
|
||||
Nz::EulerAnglesf euler45(Nz::FromDegrees(0.f), Nz::FromDegrees(22.5f), Nz::FromDegrees(22.5f));
|
||||
Nz::EulerAnglesf euler90(Nz::FromDegrees(90.f), Nz::FromDegrees(90.f), Nz::FromDegrees(0.f));
|
||||
Nz::EulerAnglesf euler30(Nz::FromDegrees(30.f), Nz::FromDegrees(0.f), Nz::FromDegrees(30.f));
|
||||
|
||||
WHEN("We convert them to quaternion")
|
||||
{
|
||||
THEN("And then convert to euler angles, we have identity")
|
||||
{
|
||||
NzEulerAnglesf tmp = NzQuaternionf(euler45.ToQuaternion()).ToEulerAngles();
|
||||
Nz::EulerAnglesf tmp = Nz::Quaternionf(euler45.ToQuaternion()).ToEulerAngles();
|
||||
REQUIRE(tmp.pitch == Approx(0.f));
|
||||
REQUIRE(tmp.yaw == Approx(22.5f));
|
||||
REQUIRE(tmp.roll == Approx(22.5f));
|
||||
tmp = NzQuaternionf(euler90.ToQuaternion()).ToEulerAngles();
|
||||
tmp = Nz::Quaternionf(euler90.ToQuaternion()).ToEulerAngles();
|
||||
REQUIRE(tmp.pitch == Approx(90.f));
|
||||
REQUIRE(tmp.yaw == Approx(90.f));
|
||||
REQUIRE(tmp.roll == Approx(0.f));
|
||||
tmp = NzQuaternionf(euler30.ToQuaternion()).ToEulerAngles();
|
||||
tmp = Nz::Quaternionf(euler30.ToQuaternion()).ToEulerAngles();
|
||||
REQUIRE(tmp.pitch == Approx(30.f));
|
||||
REQUIRE(tmp.yaw == Approx(0.f));
|
||||
REQUIRE(tmp.roll == Approx(30.f));
|
||||
|
||||
@@ -5,25 +5,25 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
|
||||
{
|
||||
GIVEN("One frustum (90, 1, 1, 1000, (0, 0, 0), (1, 0, 0))")
|
||||
{
|
||||
NzFrustumf frustum;
|
||||
frustum.Build(NzFromDegrees(90.f), 1.f, 1.f, 1000.f, NzVector3f::Zero(), NzVector3f::UnitX());
|
||||
Nz::Frustumf frustum;
|
||||
frustum.Build(Nz::FromDegrees(90.f), 1.f, 1.f, 1000.f, Nz::Vector3f::Zero(), Nz::Vector3f::UnitX());
|
||||
|
||||
WHEN("We ask for intersection with objects outside the frustum")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
NzBoundingVolumef bv(NzVector3f::Zero(), NzVector3f::Unit());
|
||||
bv.Update(NzMatrix4f::Identity());
|
||||
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(bv));
|
||||
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.9f)));
|
||||
NzOrientedBoxf obb(NzVector3f::Zero(), NzVector3f::Unit() * 0.9f);
|
||||
obb.Update(NzMatrix4f::Identity());
|
||||
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(obb));
|
||||
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(NzSpheref(NzVector3f::Zero(), 0.5f)));
|
||||
NzVector3f tmp = NzVector3f::Zero();
|
||||
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(&tmp, 1));
|
||||
tmp = NzVector3f::UnitX() * -10.f;
|
||||
REQUIRE(nzIntersectionSide_Outside == frustum.Intersect(&tmp, 1));
|
||||
Nz::BoundingVolumef bv(Nz::Vector3f::Zero(), Nz::Vector3f::Unit());
|
||||
bv.Update(Nz::Matrix4f::Identity());
|
||||
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(bv));
|
||||
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f)));
|
||||
Nz::OrientedBoxf obb(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.9f);
|
||||
obb.Update(Nz::Matrix4f::Identity());
|
||||
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(obb));
|
||||
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
|
||||
Nz::Vector3f tmp = Nz::Vector3f::Zero();
|
||||
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(&tmp, 1));
|
||||
tmp = Nz::Vector3f::UnitX() * -10.f;
|
||||
REQUIRE(Nz::IntersectionSide_Outside == frustum.Intersect(&tmp, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,17 +31,17 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
NzBoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
|
||||
bv.Update(NzMatrix4f::Identity());
|
||||
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
|
||||
bv.Update(Nz::Matrix4f::Identity());
|
||||
|
||||
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(bv));
|
||||
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(NzBoxf(NzVector3f::UnitX() * 500.f, NzVector3f::Unit())));
|
||||
NzOrientedBoxf obb(NzVector3f::UnitX() * 100.f, NzVector3f::Unit());
|
||||
obb.Update(NzMatrix4f::Identity());
|
||||
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(obb));
|
||||
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(NzSpheref(NzVector3f::UnitX() * 100.f, 0.5f)));
|
||||
NzVector3f tmp = NzVector3f::UnitX() * 100.f;
|
||||
REQUIRE(nzIntersectionSide_Inside == frustum.Intersect(&tmp, 1));
|
||||
REQUIRE(Nz::IntersectionSide_Inside == frustum.Intersect(bv));
|
||||
REQUIRE(Nz::IntersectionSide_Inside == frustum.Intersect(Nz::Boxf(Nz::Vector3f::UnitX() * 500.f, Nz::Vector3f::Unit())));
|
||||
Nz::OrientedBoxf obb(Nz::Vector3f::UnitX() * 100.f, Nz::Vector3f::Unit());
|
||||
obb.Update(Nz::Matrix4f::Identity());
|
||||
REQUIRE(Nz::IntersectionSide_Inside == frustum.Intersect(obb));
|
||||
REQUIRE(Nz::IntersectionSide_Inside == frustum.Intersect(Nz::Spheref(Nz::Vector3f::UnitX() * 100.f, 0.5f)));
|
||||
Nz::Vector3f tmp = Nz::Vector3f::UnitX() * 100.f;
|
||||
REQUIRE(Nz::IntersectionSide_Inside == frustum.Intersect(&tmp, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,15 +49,15 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
NzBoundingVolumef bv(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
|
||||
bv.Update(NzMatrix4f::Identity());
|
||||
Nz::BoundingVolumef bv(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
|
||||
bv.Update(Nz::Matrix4f::Identity());
|
||||
CHECK(!frustum.Contains(bv));
|
||||
CHECK(!frustum.Contains(NzBoxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f)));
|
||||
NzOrientedBoxf obb(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
|
||||
obb.Update(NzMatrix4f::Identity());
|
||||
CHECK(!frustum.Contains(Nz::Boxf(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f)));
|
||||
Nz::OrientedBoxf obb(0.f, -0.25f, -0.25f, 0.5f, 0.5f, 0.5f);
|
||||
obb.Update(Nz::Matrix4f::Identity());
|
||||
CHECK(!frustum.Contains(obb));
|
||||
CHECK(!frustum.Contains(NzSpheref(NzVector3f::Zero(), 0.5f)));
|
||||
NzVector3f tmp = NzVector3f::Zero();
|
||||
CHECK(!frustum.Contains(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
|
||||
Nz::Vector3f tmp = Nz::Vector3f::Zero();
|
||||
CHECK(!frustum.Contains(&tmp, 1));
|
||||
}
|
||||
}
|
||||
@@ -66,15 +66,15 @@ SCENARIO("Frustum", "[MATH][FRUSTUM]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
NzBoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
|
||||
bv.Update(NzMatrix4f::Identity());
|
||||
Nz::BoundingVolumef bv(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
|
||||
bv.Update(Nz::Matrix4f::Identity());
|
||||
CHECK(frustum.Contains(bv));
|
||||
CHECK(frustum.Contains(NzBoxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
|
||||
NzOrientedBoxf obb(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
|
||||
obb.Update(NzMatrix4f::Identity());
|
||||
CHECK(frustum.Contains(Nz::Boxf(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f)));
|
||||
Nz::OrientedBoxf obb(500.f, -0.5f, -0.5f, 1.f, 1.f, 1.f);
|
||||
obb.Update(Nz::Matrix4f::Identity());
|
||||
CHECK(frustum.Contains(obb));
|
||||
CHECK(frustum.Contains(NzSpheref(NzVector3f::UnitX() * 500.f, 1.f)));
|
||||
NzVector3f tmp = NzVector3f::UnitX() * 500.f;
|
||||
CHECK(frustum.Contains(Nz::Spheref(Nz::Vector3f::UnitX() * 500.f, 1.f)));
|
||||
Nz::Vector3f tmp = Nz::Vector3f::UnitX() * 500.f;
|
||||
CHECK(frustum.Contains(&tmp, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("Matrix4", "[MATH][MATRIX4]")
|
||||
SCENARIO("Matrix4", "[MATH][Matrix4]")
|
||||
{
|
||||
GIVEN("Two identity matrix")
|
||||
{
|
||||
NzMatrix4f firstIdentity(NzMatrix4<int>::Identity());
|
||||
NzMatrix4f secondIdentity(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f);
|
||||
Nz::Matrix4f firstIdentity(Nz::Matrix4<int>::Identity());
|
||||
Nz::Matrix4f secondIdentity(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -16,13 +16,13 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We multiply the first with a vector")
|
||||
WHEN("We multiply the first with a Nz::Vector")
|
||||
{
|
||||
THEN("Vector stay the same")
|
||||
THEN("Nz::Vector stay the same")
|
||||
{
|
||||
REQUIRE(firstIdentity.Transform(NzVector2f::Unit()) == NzVector2f::Unit());
|
||||
REQUIRE(firstIdentity.Transform(NzVector3f::Unit()) == NzVector3f::Unit());
|
||||
REQUIRE(firstIdentity.Transform(NzVector4f(1.f, 1.f, 1.f, 1.f)) == NzVector4f(1.f, 1.f, 1.f, 1.f));
|
||||
REQUIRE(firstIdentity.Transform(Nz::Vector2f::Unit()) == Nz::Vector2f::Unit());
|
||||
REQUIRE(firstIdentity.Transform(Nz::Vector3f::Unit()) == Nz::Vector3f::Unit());
|
||||
REQUIRE(firstIdentity.Transform(Nz::Vector4f(1.f, 1.f, 1.f, 1.f)) == Nz::Vector4f(1.f, 1.f, 1.f, 1.f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
|
||||
|
||||
GIVEN("Two different matrix")
|
||||
{
|
||||
NzMatrix4f matrix1(1.0f, 0.0f, 0.0f, 0.0f,
|
||||
Nz::Matrix4f matrix1(1.0f, 0.0f, 0.0f, 0.0f,
|
||||
7.0f, 2.0f, 0.0f, 0.0f,
|
||||
1.0f, 5.0f, 3.0f, 0.0f,
|
||||
8.0f, 9.0f, 2.0f, 4.0f);
|
||||
|
||||
NzMatrix4f matrix2(1.0f, 1.0f, 2.0f, -1.0f,
|
||||
Nz::Matrix4f matrix2(1.0f, 1.0f, 2.0f, -1.0f,
|
||||
-2.0f, -1.0f, -2.0f, 2.0f,
|
||||
4.0f, 2.0f, 5.0f, -4.0f,
|
||||
5.0f, -3.0f, -7.0f, -6.0f);
|
||||
@@ -62,71 +62,71 @@ SCENARIO("Matrix4", "[MATH][MATRIX4]")
|
||||
|
||||
WHEN("We multiply the matrix and its inverse")
|
||||
{
|
||||
NzMatrix4f invMatrix1;
|
||||
Nz::Matrix4f invMatrix1;
|
||||
matrix1.GetInverse(&invMatrix1);
|
||||
|
||||
NzMatrix4f invMatrix2;
|
||||
Nz::Matrix4f invMatrix2;
|
||||
matrix2.GetInverse(&invMatrix2);
|
||||
|
||||
THEN("We get the identity")
|
||||
{
|
||||
NzMatrix4f tmp = matrix1 * invMatrix1;
|
||||
Nz::Matrix4f tmp = matrix1 * invMatrix1;
|
||||
REQUIRE(tmp.m32 == Approx(0.f));
|
||||
REQUIRE(tmp.m42 == Approx(0.f));
|
||||
tmp.m32 = 0.f;
|
||||
tmp.m42 = 0.f;
|
||||
REQUIRE(tmp == NzMatrix4f::Identity());
|
||||
REQUIRE((matrix2 * invMatrix2) == NzMatrix4f::Identity());
|
||||
REQUIRE(tmp == Nz::Matrix4f::Identity());
|
||||
REQUIRE((matrix2 * invMatrix2) == Nz::Matrix4f::Identity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("One transformed matrix from rotation 45 and translation 0")
|
||||
{
|
||||
NzMatrix4f transformedMatrix = NzMatrix4f::Transform(NzVector3f::Zero(), NzQuaternionf::Identity());
|
||||
REQUIRE(transformedMatrix == NzMatrix4f::Identity());
|
||||
Nz::Matrix4f transformedMatrix = Nz::Matrix4f::Transform(Nz::Vector3f::Zero(), Nz::Quaternionf::Identity());
|
||||
REQUIRE(transformedMatrix == Nz::Matrix4f::Identity());
|
||||
|
||||
WHEN("We compare with the right matrix")
|
||||
{
|
||||
THEN("Rotation around X")
|
||||
{
|
||||
transformedMatrix.MakeTransform(NzVector3f::Zero(), NzEulerAnglesf(NzFromDegrees(45.f), 0.f, 0.f).ToQuaternion());
|
||||
NzMatrix4f rotation45X(1.f, 0.f, 0.f, 0.f,
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f).ToQuaternion());
|
||||
Nz::Matrix4f rotation45X(1.f, 0.f, 0.f, 0.f,
|
||||
0.f, std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, -std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
REQUIRE(transformedMatrix == rotation45X);
|
||||
transformedMatrix.MakeTransform(NzVector3f::Unit(), NzEulerAnglesf(NzFromDegrees(45.f), 0.f, 0.f).ToQuaternion());
|
||||
rotation45X.ApplyTranslation(NzVector3f::Unit());
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f).ToQuaternion());
|
||||
rotation45X.ApplyTranslation(Nz::Vector3f::Unit());
|
||||
REQUIRE(transformedMatrix == rotation45X);
|
||||
}
|
||||
|
||||
THEN("Rotation around Y")
|
||||
{
|
||||
transformedMatrix.MakeTransform(NzVector3f::Zero(), NzEulerAnglesf(0.f, NzFromDegrees(45.f), 0.f).ToQuaternion());
|
||||
NzMatrix4f rotation45Y(std::sqrt(2.f) / 2.f, 0.f, -std::sqrt(2.f) / 2.f, 0.f,
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f).ToQuaternion());
|
||||
Nz::Matrix4f rotation45Y(std::sqrt(2.f) / 2.f, 0.f, -std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, 1.f, 0.f, 0.f,
|
||||
std::sqrt(2.f) / 2.f, 0.f, std::sqrt(2.f) / 2.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
REQUIRE(transformedMatrix == rotation45Y);
|
||||
transformedMatrix.MakeTransform(NzVector3f::Unit(), NzEulerAnglesf(0.f, NzFromDegrees(45.f), 0.f).ToQuaternion());
|
||||
rotation45Y.ApplyTranslation(NzVector3f::Unit());
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f).ToQuaternion());
|
||||
rotation45Y.ApplyTranslation(Nz::Vector3f::Unit());
|
||||
REQUIRE(transformedMatrix == rotation45Y);
|
||||
}
|
||||
|
||||
THEN("Rotation around Z")
|
||||
{
|
||||
transformedMatrix.MakeTransform(NzVector3f::Zero(), NzEulerAnglesf(0.f, 0.f, NzFromDegrees(45.f)).ToQuaternion());
|
||||
NzMatrix4f rotation45Z( std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Zero(), Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)).ToQuaternion());
|
||||
Nz::Matrix4f rotation45Z( std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
|
||||
-std::sqrt(2.f) / 2.f, std::sqrt(2.f) / 2.f, 0.f, 0.f,
|
||||
0.f, 0.f, 1.f, 0.f,
|
||||
0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
REQUIRE(transformedMatrix == rotation45Z);
|
||||
transformedMatrix.MakeTransform(NzVector3f::Unit(), NzEulerAnglesf(NzEulerAnglesf(0.f, 0.f, NzFromDegrees(45.f)).ToQuaternion()));
|
||||
rotation45Z.ApplyTranslation(NzVector3f::Unit());
|
||||
transformedMatrix.MakeTransform(Nz::Vector3f::Unit(), Nz::EulerAnglesf(Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)).ToQuaternion()));
|
||||
rotation45Z.ApplyTranslation(Nz::Vector3f::Unit());
|
||||
REQUIRE(transformedMatrix == rotation45Z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
|
||||
{
|
||||
GIVEN("Two center and unit oriented boxes")
|
||||
{
|
||||
NzOrientedBoxf firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
|
||||
NzOrientedBoxf secondCenterAndUnit(NzOrientedBox<int>(NzVector3i::Zero(), NzVector3i::Unit()));
|
||||
Nz::OrientedBoxf firstCenterAndUnit(0.f, 0.f, 0.f, 1.f, 1.f, 1.f);
|
||||
Nz::OrientedBoxf secondCenterAndUnit(Nz::OrientedBox<int>(Nz::Vector3i::Zero(), Nz::Vector3i::Unit()));
|
||||
|
||||
firstCenterAndUnit.Update(NzMatrix4f::Identity());
|
||||
secondCenterAndUnit.Update(NzMatrix4f::Identity());
|
||||
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
|
||||
secondCenterAndUnit.Update(Nz::Matrix4f::Identity());
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -33,11 +33,11 @@ SCENARIO("OrientedBox", "[MATH][ORIENTEDBOX]")
|
||||
THEN("Results are different between operator * and update(ScaleMatrix) but corners are the same")
|
||||
{
|
||||
firstCenterAndUnit *= 2.f;
|
||||
firstCenterAndUnit.Update(NzMatrix4f::Identity());
|
||||
secondCenterAndUnit.Update(NzMatrix4f::Scale(NzVector3f::Unit() * 2.f));
|
||||
firstCenterAndUnit.Update(Nz::Matrix4f::Identity());
|
||||
secondCenterAndUnit.Update(Nz::Matrix4f::Scale(Nz::Vector3f::Unit() * 2.f));
|
||||
|
||||
REQUIRE(firstCenterAndUnit != secondCenterAndUnit);
|
||||
for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i)
|
||||
for (unsigned int i = 0; i <= Nz::BoxCorner_Max; ++i)
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit(i) == secondCenterAndUnit(i));
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ SCENARIO("Plane", "[MATH][PLANE]")
|
||||
{
|
||||
GIVEN("Two planes normal(1, 1, 1), distance 1")
|
||||
{
|
||||
NzPlanef firstPlane(NzVector3f::Unit().Normalize(), 1.f);
|
||||
NzPlanef secondPlane(NzPlaned(NzVector3d::Unit().Normalize(), 1.0));
|
||||
Nz::Planef firstPlane(Nz::Vector3f::Unit().Normalize(), 1.f);
|
||||
Nz::Planef secondPlane(Nz::Planed(Nz::Vector3d::Unit().Normalize(), 1.0));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -17,36 +17,36 @@ SCENARIO("Plane", "[MATH][PLANE]")
|
||||
|
||||
AND_THEN("We compare with normal(-1, -1, -1), distance -1")
|
||||
{
|
||||
REQUIRE(firstPlane == NzPlanef(-NzVector3f::Unit().Normalize(), -1.f));
|
||||
REQUIRE(firstPlane == Nz::Planef(-Nz::Vector3f::Unit().Normalize(), -1.f));
|
||||
}
|
||||
|
||||
AND_THEN("They have the same distance from the same point")
|
||||
{
|
||||
NzVector3f point(-2.f, 3.f, 1.f);
|
||||
Nz::Vector3f point(-2.f, 3.f, 1.f);
|
||||
REQUIRE(firstPlane.Distance(point) == Approx(secondPlane.Distance(point)));
|
||||
REQUIRE(firstPlane.Distance(-2.f, 3.f, 1.f) == Approx(0.1547f));
|
||||
}
|
||||
|
||||
AND_THEN("Distance between Plane (0, 1, 0), distance 1 and point (0, 2, 0) should be 1")
|
||||
{
|
||||
REQUIRE(NzPlanef(NzVector3f::UnitY(), 1.f).Distance(NzVector3f::UnitY() * 2.f) == Approx(1.f));
|
||||
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Approx(1.f));
|
||||
}
|
||||
|
||||
AND_THEN("Distance between Plane (0, 1, 0), distance 5 and point (0, 2, 0) should be -3")
|
||||
{
|
||||
REQUIRE(NzPlanef(NzVector3f::UnitY(), 5.f).Distance(NzVector3f::UnitY() * 2.f) == Approx(-3.f));
|
||||
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 5.f).Distance(Nz::Vector3f::UnitY() * 2.f) == Approx(-3.f));
|
||||
}
|
||||
|
||||
AND_THEN("Distance between Plane (0, 1, 0), distance 1000 and point (0, 500, 0) and (0, 1500, 0)")
|
||||
{
|
||||
REQUIRE(NzPlanef(NzVector3f::UnitY(), 1000.f).Distance(NzVector3f::UnitY() * 500.f) == Approx(-500.f));
|
||||
REQUIRE(NzPlanef(NzVector3f::UnitY(), 1000.f).Distance(NzVector3f::UnitY() * 1500.f) == Approx(500.f));
|
||||
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Approx(-500.f));
|
||||
REQUIRE(Nz::Planef(Nz::Vector3f::UnitY(), 1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Approx(500.f));
|
||||
}
|
||||
|
||||
AND_THEN("Distance between Plane (0, -1, 0), distance -1000 and point (0, 500, 0) and (0, 1500, 0)")
|
||||
{
|
||||
REQUIRE(NzPlanef(-NzVector3f::UnitY(), -1000.f).Distance(NzVector3f::UnitY() * 500.f) == Approx(500.f));
|
||||
REQUIRE(NzPlanef(-NzVector3f::UnitY(), -1000.f).Distance(NzVector3f::UnitY() * 1500.f) == Approx(-500.f));
|
||||
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 500.f) == Approx(500.f));
|
||||
REQUIRE(Nz::Planef(-Nz::Vector3f::UnitY(), -1000.f).Distance(Nz::Vector3f::UnitY() * 1500.f) == Approx(-500.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,20 +55,20 @@ SCENARIO("Plane", "[MATH][PLANE]")
|
||||
{
|
||||
WHEN("We do a positive plane")
|
||||
{
|
||||
NzPlanef xy(NzVector3f(2.f, 1.f, 0.f), NzVector3f(-1.f, 1.f, -1.f), NzVector3f(-1.f, 1.f, 0.f));
|
||||
Nz::Planef xy(Nz::Vector3f(2.f, 1.f, 0.f), Nz::Vector3f(-1.f, 1.f, -1.f), Nz::Vector3f(-1.f, 1.f, 0.f));
|
||||
|
||||
THEN("It must be equal to XZ distance 1")
|
||||
{
|
||||
REQUIRE(xy == NzPlanef(NzVector3f::UnitY(), 1.f));
|
||||
REQUIRE(xy == Nz::Planef(Nz::Vector3f::UnitY(), 1.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We do a negative plane")
|
||||
{
|
||||
NzPlanef xy(NzVector3f(0.f, 1.f, 0.f), NzVector3f(1.f, 1.f, 1.f), NzVector3f(-1.f, 1.f, 0.f));
|
||||
Nz::Planef xy(Nz::Vector3f(0.f, 1.f, 0.f), Nz::Vector3f(1.f, 1.f, 1.f), Nz::Vector3f(-1.f, 1.f, 0.f));
|
||||
THEN("It must be equal to XZ distance 1")
|
||||
{
|
||||
REQUIRE(xy == NzPlanef(-NzVector3f::UnitY(), -1.f));
|
||||
REQUIRE(xy == Nz::Planef(-Nz::Vector3f::UnitY(), -1.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
GIVEN("Two quaternions (0, 1, 0, 0)")
|
||||
{
|
||||
NzQuaternionf firstQuaternion(NzFromDegrees(180.f), NzVector3f::UnitX());
|
||||
NzQuaternionf secondQuaternion(0.f, 1.f, 0.f, 0.f);
|
||||
Nz::Quaternionf firstQuaternion(Nz::FromDegrees(180.f), Nz::Vector3f::UnitX());
|
||||
Nz::Quaternionf secondQuaternion(0.f, 1.f, 0.f, 0.f);
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -23,25 +23,25 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
THEN("Multiply with a vectorX is identity")
|
||||
{
|
||||
REQUIRE((firstQuaternion * NzVector3f::UnitX()) == NzVector3f::UnitX());
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitX()) == Nz::Vector3f::UnitX());
|
||||
}
|
||||
|
||||
AND_THEN("Multiply with a vectorY or Z is opposite")
|
||||
{
|
||||
REQUIRE((firstQuaternion * NzVector3f::UnitY()) == -NzVector3f::UnitY());
|
||||
REQUIRE((firstQuaternion * NzVector3f::UnitZ()) == -NzVector3f::UnitZ());
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitY()) == -Nz::Vector3f::UnitY());
|
||||
REQUIRE((firstQuaternion * Nz::Vector3f::UnitZ()) == -Nz::Vector3f::UnitZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GIVEN("The four unit quaternions")
|
||||
{
|
||||
NzQuaternionf w(1.f, 0.f, 0.f, 0.f);
|
||||
NzQuaternionf x(0.f, 1.f, 0.f, 0.f);
|
||||
NzQuaternionf y(0.f, 0.f, 1.f, 0.f);
|
||||
NzQuaternionf z(0.f, 0.f, 0.f, 1.f);
|
||||
Nz::Quaternionf w(1.f, 0.f, 0.f, 0.f);
|
||||
Nz::Quaternionf x(0.f, 1.f, 0.f, 0.f);
|
||||
Nz::Quaternionf y(0.f, 0.f, 1.f, 0.f);
|
||||
Nz::Quaternionf z(0.f, 0.f, 0.f, 1.f);
|
||||
|
||||
NzQuaternionf xyzw = x * y * z * w;
|
||||
Nz::Quaternionf xyzw = x * y * z * w;
|
||||
|
||||
WHEN("We ask for the norm")
|
||||
{
|
||||
@@ -59,10 +59,10 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
THEN("Results shoud follow")
|
||||
{
|
||||
NzQuaternionf oppositeOfW(-1.f, 0.f, 0.f, 0.f);
|
||||
NzQuaternionf oppositeOfX = x.GetConjugate();
|
||||
NzQuaternionf oppositeOfY = y.GetConjugate();
|
||||
NzQuaternionf oppositeOfZ = z.GetConjugate();
|
||||
Nz::Quaternionf oppositeOfW(-1.f, 0.f, 0.f, 0.f);
|
||||
Nz::Quaternionf oppositeOfX = x.GetConjugate();
|
||||
Nz::Quaternionf oppositeOfY = y.GetConjugate();
|
||||
Nz::Quaternionf oppositeOfZ = z.GetConjugate();
|
||||
|
||||
REQUIRE((x * x) == oppositeOfW);
|
||||
REQUIRE((y * y) == oppositeOfW);
|
||||
@@ -81,32 +81,32 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
|
||||
GIVEN("Two different quaternions (10, (1, 0, 0) and (20, (1, 0, 0))")
|
||||
{
|
||||
NzQuaternionf x10 = NzQuaternionf(NzFromDegrees(10.f), NzVector3f::UnitX());
|
||||
NzQuaternionf x20 = x10 * x10;
|
||||
Nz::Quaternionf x10 = Nz::Quaternionf(Nz::FromDegrees(10.f), Nz::Vector3f::UnitX());
|
||||
Nz::Quaternionf x20 = x10 * x10;
|
||||
|
||||
NzQuaternionf x30a = x10 * x20;
|
||||
NzQuaternionf x30b = x20 * x10;
|
||||
Nz::Quaternionf x30a = x10 * x20;
|
||||
Nz::Quaternionf x30b = x20 * x10;
|
||||
|
||||
WHEN("We multiply them")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(x20 == NzQuaternionf(NzFromDegrees(20.f), NzVector3f::UnitX()));
|
||||
REQUIRE(x20 == Nz::Quaternionf(Nz::FromDegrees(20.f), Nz::Vector3f::UnitX()));
|
||||
REQUIRE(x30a == x30b);
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("Convert euler to quaternion")
|
||||
{
|
||||
NzQuaternionf X45(NzEulerAnglesf(NzFromDegrees(45.f), 0.f, 0.f));
|
||||
NzQuaternionf Y45(NzEulerAnglesf(0.f, NzFromDegrees(45.f), 0.f));
|
||||
NzQuaternionf Z45(NzEulerAnglesf(0.f, 0.f, NzFromDegrees(45.f)));
|
||||
Nz::Quaternionf X45(Nz::EulerAnglesf(Nz::FromDegrees(45.f), 0.f, 0.f));
|
||||
Nz::Quaternionf Y45(Nz::EulerAnglesf(0.f, Nz::FromDegrees(45.f), 0.f));
|
||||
Nz::Quaternionf Z45(Nz::EulerAnglesf(0.f, 0.f, Nz::FromDegrees(45.f)));
|
||||
|
||||
THEN("They must be equal")
|
||||
{
|
||||
REQUIRE(X45 == NzQuaternionf(0.9238795f, 0.38268346f, 0.f, 0.f));
|
||||
REQUIRE(Y45 == NzQuaternionf(0.9238795f, 0.f, 0.38268346f, 0.f));
|
||||
REQUIRE(Z45 == NzQuaternionf(0.9238795f, 0.f, 0.f, 0.38268346f));
|
||||
REQUIRE(X45 == Nz::Quaternionf(0.9238795f, 0.38268346f, 0.f, 0.f));
|
||||
REQUIRE(Y45 == Nz::Quaternionf(0.9238795f, 0.f, 0.38268346f, 0.f));
|
||||
REQUIRE(Z45 == Nz::Quaternionf(0.9238795f, 0.f, 0.f, 0.38268346f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
REQUIRE(x30a.ToEulerAngles() == x30b.ToEulerAngles());
|
||||
REQUIRE(x30a.ToEulerAngles().ToQuaternion() == x30b.ToEulerAngles().ToQuaternion());
|
||||
|
||||
NzQuaternionf tmp(1.f, 1.f, 0.f, 0.f);
|
||||
Nz::Quaternionf tmp(1.f, 1.f, 0.f, 0.f);
|
||||
tmp.Normalize();
|
||||
REQUIRE(tmp == tmp.ToEulerAngles().ToQuaternion());
|
||||
}
|
||||
@@ -127,27 +127,27 @@ SCENARIO("Quaternion", "[MATH][QUATERNION]")
|
||||
{
|
||||
THEN("The half of 10 and 30 is 20")
|
||||
{
|
||||
NzQuaternionf slerpx10x30a = NzQuaternionf::Slerp(x10, x30a, 0.5f);
|
||||
Nz::Quaternionf slerpx10x30a = Nz::Quaternionf::Slerp(x10, x30a, 0.5f);
|
||||
REQUIRE(slerpx10x30a.w == Approx(x20.w));
|
||||
REQUIRE(slerpx10x30a.x == Approx(x20.x));
|
||||
REQUIRE(slerpx10x30a.y == Approx(x20.y));
|
||||
REQUIRE(slerpx10x30a.z == Approx(x20.z));
|
||||
NzQuaternionf slerpx10x30b = NzQuaternionf::Slerp(x10, x30b, 0.5f);
|
||||
Nz::Quaternionf slerpx10x30b = Nz::Quaternionf::Slerp(x10, x30b, 0.5f);
|
||||
REQUIRE(slerpx10x30b.w == Approx(x20.w));
|
||||
REQUIRE(slerpx10x30b.x == Approx(x20.x));
|
||||
REQUIRE(slerpx10x30b.y == Approx(x20.y));
|
||||
REQUIRE(slerpx10x30b.z == Approx(x20.z));
|
||||
REQUIRE(NzQuaternionf::Slerp(x10, x30a, 0.f) == x10);
|
||||
REQUIRE(NzQuaternionf::Slerp(x10, x30a, 1.f) == x30a);
|
||||
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 0.f) == x10);
|
||||
REQUIRE(Nz::Quaternionf::Slerp(x10, x30a, 1.f) == x30a);
|
||||
}
|
||||
|
||||
AND_THEN("The half of 45 is 22.5")
|
||||
{
|
||||
NzQuaternionf quaterionA(NzFromDegrees(0.f), NzVector3f::UnitZ());
|
||||
NzQuaternionf quaterionB(NzFromDegrees(45.f), NzVector3f::UnitZ());
|
||||
NzQuaternionf quaternionC = NzQuaternionf::Slerp(quaterionA, quaterionB, 0.5f);
|
||||
Nz::Quaternionf quaterionA(Nz::FromDegrees(0.f), Nz::Vector3f::UnitZ());
|
||||
Nz::Quaternionf quaterionB(Nz::FromDegrees(45.f), Nz::Vector3f::UnitZ());
|
||||
Nz::Quaternionf quaternionC = Nz::Quaternionf::Slerp(quaterionA, quaterionB, 0.5f);
|
||||
|
||||
NzQuaternionf unitZ225(NzFromDegrees(22.5f), NzVector3f::UnitZ());
|
||||
Nz::Quaternionf unitZ225(Nz::FromDegrees(22.5f), Nz::Vector3f::UnitZ());
|
||||
REQUIRE(quaternionC.w == Approx(unitZ225.w));
|
||||
REQUIRE(quaternionC.x == Approx(unitZ225.x));
|
||||
REQUIRE(quaternionC.y == Approx(unitZ225.y));
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#include <Nazara/Math/Ray.hpp>
|
||||
#include <Catch/catch.hpp>
|
||||
|
||||
SCENARIO("Ray", "[RAY]")
|
||||
SCENARIO("Ray", "[MATH][RAY]")
|
||||
{
|
||||
GIVEN("Two same rays (0, 0, 0) -> (0, 1, 0)")
|
||||
GIVEN("Two same Rays (0, 0, 0) -> (0, 1, 0)")
|
||||
{
|
||||
NzRayf firstRay(NzRay<int>(NzPlane<int>::XY(), NzPlane<int>::YZ()));
|
||||
NzRayf secondRay(0.f, 0.f, 0.f, 0.f, 1.f, 0.f);
|
||||
Nz::Rayf ray(Nz::Ray<int>(Nz::Plane<int>::XY(), Nz::Plane<int>::YZ()));
|
||||
Nz::Rayf secondRay(0.f, 0.f, 0.f, 0.f, 1.f, 0.f);
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
THEN("They are the same and Y axis")
|
||||
{
|
||||
REQUIRE(firstRay == secondRay);
|
||||
REQUIRE(firstRay == NzRayf::AxisY());
|
||||
REQUIRE(ray == secondRay);
|
||||
REQUIRE(ray == Nz::Rayf::AxisY());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We ask for the closest point")
|
||||
{
|
||||
THEN("The point that is multiple on the ray, is at multiple")
|
||||
THEN("The point that is multiple on the Nz::Ray, is at multiple")
|
||||
{
|
||||
REQUIRE(firstRay.ClosestPoint(secondRay.GetPoint(1.f)) == Approx(1.f));
|
||||
REQUIRE(ray.ClosestPoint(secondRay.GetPoint(1.f)) == Approx(1.f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,24 +32,24 @@ SCENARIO("Ray", "[RAY]")
|
||||
float tmpClosest;
|
||||
float tmpFurthest;
|
||||
|
||||
CHECK(firstRay.Intersect(NzBoxf(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
|
||||
REQUIRE(firstRay.GetPoint(tmpClosest) == NzVector3f::UnitY());
|
||||
REQUIRE(firstRay.GetPoint(tmpFurthest) == (NzVector3f::UnitY() * 2.f));
|
||||
CHECK(!firstRay.Intersect(NzBoxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
|
||||
CHECK(ray.Intersect(Nz::Boxf(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
|
||||
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY());
|
||||
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 2.f));
|
||||
CHECK(!ray.Intersect(Nz::Boxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f), &tmpClosest, &tmpFurthest));
|
||||
}
|
||||
|
||||
THEN("For the Plane collision's")
|
||||
THEN("For the Nz::Plane collision's")
|
||||
{
|
||||
float tmpHit;
|
||||
|
||||
CHECK(firstRay.Intersect(NzPlanef(NzVector3f::UnitY(), 1.f), &tmpHit));
|
||||
REQUIRE(firstRay.GetPoint(tmpHit) == NzVector3f::UnitY());
|
||||
CHECK(firstRay.Intersect(NzPlanef::XZ(), &tmpHit));
|
||||
REQUIRE(firstRay.GetPoint(tmpHit) == NzVector3f::Zero());
|
||||
CHECK(firstRay.Intersect(NzPlanef(NzVector3f::UnitY(), 2.f), &tmpHit));
|
||||
REQUIRE(firstRay.GetPoint(tmpHit) == 2.f * NzVector3f::UnitY());
|
||||
CHECK(ray.Intersect(Nz::Planef(Nz::Vector3f::UnitY(), 1.f), &tmpHit));
|
||||
REQUIRE(ray.GetPoint(tmpHit) == Nz::Vector3f::UnitY());
|
||||
CHECK(ray.Intersect(Nz::Planef::XZ(), &tmpHit));
|
||||
REQUIRE(ray.GetPoint(tmpHit) == Nz::Vector3f::Zero());
|
||||
CHECK(ray.Intersect(Nz::Planef(Nz::Vector3f::UnitY(), 2.f), &tmpHit));
|
||||
REQUIRE(ray.GetPoint(tmpHit) == 2.f * Nz::Vector3f::UnitY());
|
||||
|
||||
CHECK(!firstRay.Intersect(NzPlanef(NzVector3f::UnitX(), 1.f)));
|
||||
CHECK(!ray.Intersect(Nz::Planef(Nz::Vector3f::UnitX(), 1.f)));
|
||||
}
|
||||
|
||||
THEN("For the Sphere collision's")
|
||||
@@ -57,11 +57,11 @@ SCENARIO("Ray", "[RAY]")
|
||||
float tmpClosest;
|
||||
float tmpFurthest;
|
||||
|
||||
CHECK(firstRay.Intersect(NzSpheref(NzVector3f::UnitY(), 0.1f), &tmpClosest, &tmpFurthest));
|
||||
REQUIRE(firstRay.GetPoint(tmpClosest) == NzVector3f::UnitY() * 0.9f);
|
||||
REQUIRE(firstRay.GetPoint(tmpFurthest) == (NzVector3f::UnitY() * 1.1f));
|
||||
CHECK(ray.Intersect(Nz::Spheref(Nz::Vector3f::UnitY(), 0.1f), &tmpClosest, &tmpFurthest));
|
||||
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY() * 0.9f);
|
||||
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 1.1f));
|
||||
|
||||
CHECK(!firstRay.Intersect(NzSpheref(NzVector3f::UnitX(), 0.9f)));
|
||||
CHECK(!ray.Intersect(Nz::Spheref(Nz::Vector3f::UnitX(), 0.9f)));
|
||||
}
|
||||
|
||||
THEN("For the OBB collision's")
|
||||
@@ -69,25 +69,25 @@ SCENARIO("Ray", "[RAY]")
|
||||
float tmpClosest;
|
||||
float tmpFurthest;
|
||||
|
||||
NzOrientedBoxf obb(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f);
|
||||
obb.Update(NzMatrix4f::Rotate(NzEulerAnglesf(0.f, 90.f, 0.f).ToQuaternion()));
|
||||
Nz::OrientedBoxf obb(-0.5f, 1.f, -0.5f, 1.f, 1.f, 1.f);
|
||||
obb.Update(Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 0.f).ToQuaternion()));
|
||||
|
||||
CHECK(firstRay.Intersect(obb, &tmpClosest, &tmpFurthest));
|
||||
REQUIRE(firstRay.GetPoint(tmpClosest) == NzVector3f::UnitY());
|
||||
REQUIRE(firstRay.GetPoint(tmpFurthest) == (NzVector3f::UnitY() * 2.f));
|
||||
CHECK(ray.Intersect(obb, &tmpClosest, &tmpFurthest));
|
||||
REQUIRE(ray.GetPoint(tmpClosest) == Nz::Vector3f::UnitY());
|
||||
REQUIRE(ray.GetPoint(tmpFurthest) == (Nz::Vector3f::UnitY() * 2.f));
|
||||
|
||||
obb = NzOrientedBoxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f);
|
||||
obb.Update(NzMatrix4f::Rotate(NzEulerAnglesf(0.f, 0.f, 90.f).ToQuaternion()));
|
||||
CHECK(!firstRay.Intersect(obb, &tmpClosest, &tmpFurthest));
|
||||
obb = Nz::OrientedBoxf(-10.f, 1.f, -10.f, 1.f, 1.f, 1.f);
|
||||
obb.Update(Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 0.f, 90.f).ToQuaternion()));
|
||||
CHECK(!ray.Intersect(obb, &tmpClosest, &tmpFurthest));
|
||||
}
|
||||
|
||||
THEN("For the bounding volume collision's")
|
||||
{
|
||||
NzBoundingVolumef nullVolume(nzExtend_Null);
|
||||
CHECK(!firstRay.Intersect(nullVolume));
|
||||
Nz::BoundingVolumef nullVolume(Nz::Extend_Null);
|
||||
CHECK(!ray.Intersect(nullVolume));
|
||||
|
||||
NzBoundingVolumef infiniteVolume(nzExtend_Infinite);
|
||||
CHECK(firstRay.Intersect(infiniteVolume));
|
||||
Nz::BoundingVolumef infiniteVolume(Nz::Extend_Infinite);
|
||||
CHECK(ray.Intersect(infiniteVolume));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
SCENARIO("Rect", "[MATH][RECT]")
|
||||
{
|
||||
GIVEN("Two same rectangles center and unit lengths")
|
||||
GIVEN("Two same Nz::Rectangles center and unit lengths")
|
||||
{
|
||||
NzRectf firstCenterAndUnit(0.f, 0.f, 1.f, 1.f);
|
||||
NzRectf secondCenterAndUnit(NzRecti(NzVector2i::Unit(), NzVector2i::Zero()));
|
||||
Nz::Rectf firstCenterAndUnit(0.f, 0.f, 1.f, 1.f);
|
||||
Nz::Rectf secondCenterAndUnit(Nz::Recti(Nz::Vector2i::Unit(), Nz::Vector2i::Zero()));
|
||||
|
||||
WHEN("We ask if they are the same")
|
||||
{
|
||||
@@ -14,20 +14,20 @@ SCENARIO("Rect", "[MATH][RECT]")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit == secondCenterAndUnit);
|
||||
REQUIRE(firstCenterAndUnit.GetCenter() == secondCenterAndUnit.GetCenter());
|
||||
REQUIRE(firstCenterAndUnit.GetCorner(nzRectCorner_LeftBottom) == secondCenterAndUnit.GetCorner(nzRectCorner_LeftBottom));
|
||||
REQUIRE(firstCenterAndUnit.GetCorner(Nz::RectCorner_LeftBottom) == secondCenterAndUnit.GetCorner(Nz::RectCorner_LeftBottom));
|
||||
CHECK(firstCenterAndUnit.IsValid());
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We move one from (0.5, 0.5)")
|
||||
{
|
||||
firstCenterAndUnit.Translate(NzVector2f(0.5f, 0.5f));
|
||||
firstCenterAndUnit.Translate(Nz::Vector2f(0.5f, 0.5f));
|
||||
|
||||
THEN("The collision should be (0.5, 0.5) -> (0.5, 0.5)")
|
||||
{
|
||||
NzRectf tmp;
|
||||
Nz::Rectf tmp;
|
||||
CHECK(firstCenterAndUnit.Intersect(secondCenterAndUnit, &tmp));
|
||||
REQUIRE(tmp == NzRectf(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
REQUIRE(tmp == Nz::Rectf(0.5f, 0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,12 +43,12 @@ SCENARIO("Rect", "[MATH][RECT]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit.GetLengths() == NzVector2f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMaximum() == NzVector2f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMinimum() == NzVector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetNegativeVertex(NzVector2f::Unit()) == NzVector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPosition() == NzVector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPositiveVertex(NzVector2f::Unit()) == NzVector2f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetLengths() == Nz::Vector2f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMaximum() == Nz::Vector2f::Unit());
|
||||
REQUIRE(firstCenterAndUnit.GetMinimum() == Nz::Vector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetNegativeVertex(Nz::Vector2f::Unit()) == Nz::Vector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPosition() == Nz::Vector2f::Zero());
|
||||
REQUIRE(firstCenterAndUnit.GetPositiveVertex(Nz::Vector2f::Unit()) == Nz::Vector2f::Unit());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
|
||||
{
|
||||
GIVEN("Two same sphere center and unit")
|
||||
{
|
||||
NzSpheref firstCenterAndUnit(0.f, 0.f, 0.f, 1.f);
|
||||
NzSpheref secondCenterAndUnit(NzSphere<int>(NzVector3i::Zero(), 1));
|
||||
Nz::Spheref firstCenterAndUnit(0.f, 0.f, 0.f, 1.f);
|
||||
Nz::Spheref secondCenterAndUnit(Nz::Sphere<int>(Nz::Vector3i::Zero(), 1));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -21,19 +21,19 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
|
||||
THEN("These results are expected for Contains")
|
||||
{
|
||||
CHECK(firstCenterAndUnit.Contains(0.5f, 0.5f, 0.5f));
|
||||
CHECK(firstCenterAndUnit.Contains(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.5f)));
|
||||
CHECK(!firstCenterAndUnit.Contains(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 5.f)));
|
||||
CHECK(firstCenterAndUnit.Contains(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f)));
|
||||
CHECK(!firstCenterAndUnit.Contains(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 5.f)));
|
||||
}
|
||||
|
||||
THEN("There are for Intersect")
|
||||
{
|
||||
CHECK(firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 0.5f)));
|
||||
CHECK(firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Zero(), NzVector3f::Unit() * 5.f)));
|
||||
CHECK(!firstCenterAndUnit.Intersect(NzBoxf(NzVector3f::Unit() * 5.f, NzVector3f::Unit())));
|
||||
CHECK(firstCenterAndUnit.Intersect(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 0.5f)));
|
||||
CHECK(firstCenterAndUnit.Intersect(Nz::Boxf(Nz::Vector3f::Zero(), Nz::Vector3f::Unit() * 5.f)));
|
||||
CHECK(!firstCenterAndUnit.Intersect(Nz::Boxf(Nz::Vector3f::Unit() * 5.f, Nz::Vector3f::Unit())));
|
||||
|
||||
CHECK(firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Zero(), 0.5f)));
|
||||
CHECK(firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Zero(), 5.f)));
|
||||
CHECK(!firstCenterAndUnit.Intersect(NzSpheref(NzVector3f::Unit() * 5.f, 1.f)));
|
||||
CHECK(firstCenterAndUnit.Intersect(Nz::Spheref(Nz::Vector3f::Zero(), 0.5f)));
|
||||
CHECK(firstCenterAndUnit.Intersect(Nz::Spheref(Nz::Vector3f::Zero(), 5.f)));
|
||||
CHECK(!firstCenterAndUnit.Intersect(Nz::Spheref(Nz::Vector3f::Unit() * 5.f, 1.f)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,22 +41,22 @@ SCENARIO("Sphere", "[MATH][SPHERE]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstCenterAndUnit.Distance(NzVector3f::UnitX()) == Approx(1.f));
|
||||
REQUIRE(firstCenterAndUnit.SquaredDistance(NzVector3f::UnitX()) == Approx(1.f));
|
||||
REQUIRE(firstCenterAndUnit.Distance(Nz::Vector3f::UnitX()) == Approx(1.f));
|
||||
REQUIRE(firstCenterAndUnit.SquaredDistance(Nz::Vector3f::UnitX()) == Approx(1.f));
|
||||
|
||||
NzSpheref tmp(NzVector3f::UnitX(), 1.f);
|
||||
REQUIRE(tmp.Distance(NzVector3f::UnitX() * 4.f) == Approx(3.f));
|
||||
REQUIRE(tmp.SquaredDistance(NzVector3f::UnitX() * 4.f) == Approx(9.f));
|
||||
Nz::Spheref tmp(Nz::Vector3f::UnitX(), 1.f);
|
||||
REQUIRE(tmp.Distance(Nz::Vector3f::UnitX() * 4.f) == Approx(3.f));
|
||||
REQUIRE(tmp.SquaredDistance(Nz::Vector3f::UnitX() * 4.f) == Approx(9.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We get sphere from box unit and center")
|
||||
{
|
||||
NzBoxf centerUnitBox(NzVector3f::Unit() * -0.5f, NzVector3f::Unit() * 0.5f);
|
||||
Nz::Boxf centerUnitBox(Nz::Vector3f::Unit() * -0.5f, Nz::Vector3f::Unit() * 0.5f);
|
||||
|
||||
THEN("This is equal to sphere center and radius 0.75")
|
||||
{
|
||||
REQUIRE(centerUnitBox.GetSquaredBoundingSphere() == NzSpheref(NzVector3f::Zero(), 0.75f));
|
||||
REQUIRE(centerUnitBox.GetSquaredBoundingSphere() == Nz::Spheref(Nz::Vector3f::Zero(), 0.75f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
|
||||
{
|
||||
GIVEN("Two same vectors (1, 1)")
|
||||
{
|
||||
NzVector2f firstUnit(1.f);
|
||||
NzVector2f secondUnit(NzVector2i(NzVector4i(1, 1, 3, 5)));
|
||||
Nz::Vector2f firstUnit(1.f);
|
||||
Nz::Vector2f secondUnit(Nz::Vector2i(Nz::Vector4i(1, 1, 3, 5)));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -20,7 +20,7 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
|
||||
|
||||
WHEN("We test the dot product")
|
||||
{
|
||||
NzVector2f tmp(-1.f, 1.f);
|
||||
Nz::Vector2f tmp(-1.f, 1.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
@@ -32,8 +32,8 @@ SCENARIO("Vector2", "[MATH][VECTOR2]")
|
||||
|
||||
WHEN("We ask for distance from (-2, -3)")
|
||||
{
|
||||
NzVector2f tmp(-2.f, -3.f);
|
||||
NzVector2f tmp2(-1.f, -1.f);
|
||||
Nz::Vector2f tmp(-2.f, -3.f);
|
||||
Nz::Vector2f tmp2(-1.f, -1.f);
|
||||
|
||||
THEN("These are expected")
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
|
||||
{
|
||||
GIVEN("Two same unit vector")
|
||||
{
|
||||
NzVector3f firstUnit(1.f, 1.f, 1.f);
|
||||
NzVector3f secondUnit(NzVector3i(NzVector4i(1, 1, 1, 5)));
|
||||
Nz::Vector3f firstUnit(1.f, 1.f, 1.f);
|
||||
Nz::Vector3f secondUnit(Nz::Vector3i(Nz::Vector4i(1, 1, 1, 5)));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -20,7 +20,7 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
|
||||
|
||||
WHEN("We test the dot product")
|
||||
{
|
||||
NzVector3f tmp(-1.f, 0.f, 1.f);
|
||||
Nz::Vector3f tmp(-1.f, 0.f, 1.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
@@ -34,14 +34,14 @@ SCENARIO("Vector3", "[MATH][VECTOR3]")
|
||||
{
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(NzVector3f::CrossProduct(NzVector3f::UnitX(), NzVector3f::UnitY()) == NzVector3f::UnitZ());
|
||||
REQUIRE(NzVector3f::CrossProduct(NzVector3f(1.f, 2.f, 3.f), NzVector3f(3.f, 2.f, 1.f)) == NzVector3f(-4.f, 8.f, -4.f));
|
||||
REQUIRE(Nz::Vector3f::CrossProduct(Nz::Vector3f::UnitX(), Nz::Vector3f::UnitY()) == Nz::Vector3f::UnitZ());
|
||||
REQUIRE(Nz::Vector3f::CrossProduct(Nz::Vector3f(1.f, 2.f, 3.f), Nz::Vector3f(3.f, 2.f, 1.f)) == Nz::Vector3f(-4.f, 8.f, -4.f));
|
||||
}
|
||||
}
|
||||
|
||||
WHEN("We ask for distance")
|
||||
{
|
||||
NzVector3f tmp(-1.f, -5.f, -8.f);
|
||||
Nz::Vector3f tmp(-1.f, -5.f, -8.f);
|
||||
|
||||
THEN("These are expected")
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@ SCENARIO("Vector4", "[MATH][VECTOR4]")
|
||||
{
|
||||
GIVEN("Two same unit vector")
|
||||
{
|
||||
NzVector4f firstUnit(1.f, 1.f, 1.f);
|
||||
NzVector4f secondUnit(NzVector4i(1, 1, 1, 1));
|
||||
Nz::Vector4f firstUnit(1.f, 1.f, 1.f);
|
||||
Nz::Vector4f secondUnit(Nz::Vector4i(1, 1, 1, 1));
|
||||
|
||||
WHEN("We compare them")
|
||||
{
|
||||
@@ -20,7 +20,7 @@ SCENARIO("Vector4", "[MATH][VECTOR4]")
|
||||
|
||||
WHEN("We test the dot product")
|
||||
{
|
||||
NzVector4f tmp(-1.f, 0.f, 1.f, 0.f);
|
||||
Nz::Vector4f tmp(-1.f, 0.f, 1.f, 0.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
@@ -31,12 +31,12 @@ SCENARIO("Vector4", "[MATH][VECTOR4]")
|
||||
|
||||
WHEN("We normalize")
|
||||
{
|
||||
NzVector4f tmp(1.f, 1.f, 1.f, 3.f);
|
||||
Nz::Vector4f tmp(1.f, 1.f, 1.f, 3.f);
|
||||
|
||||
THEN("These results are expected")
|
||||
{
|
||||
REQUIRE(firstUnit.Normalize() == NzVector4f(1.f, NzVector3f::Unit()));
|
||||
REQUIRE(tmp.Normalize() == NzVector4f(NzVector3f::Unit() * (1.f / 3.f), 1.f));
|
||||
REQUIRE(firstUnit.Normalize() == Nz::Vector4f(1.f, Nz::Vector3f::Unit()));
|
||||
REQUIRE(tmp.Normalize() == Nz::Vector4f(Nz::Vector3f::Unit() * (1.f / 3.f), 1.f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user