git.s-ol.nu ~forks/DiligentCore / 30d6e99
MathLib: added stream insreters for vector types assiduous 7 months ago
3 changed file(s) with 94 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
4949
5050 #include <cmath>
5151 #include <algorithm>
52 #include <iostream>
5253
5354 #include "HashUtils.hpp"
5455
22082209 return static_cast<T>(ExtractLSB(reinterpret_cast<typename std::underlying_type<T>::type&>(bits)));
22092210 }
22102211
2212
2213 inline std::ostream& operator<<(std::ostream& os, const float4& vec)
2214 {
2215 return os << "float4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
2216 }
2217 inline std::ostream& operator<<(std::ostream& os, const float3& vec)
2218 {
2219 return os << "float3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
2220 }
2221 inline std::ostream& operator<<(std::ostream& os, const float2& vec)
2222 {
2223 return os << "float2(" << vec.x << ", " << vec.y << ')';
2224 }
2225
2226 inline std::ostream& operator<<(std::ostream& os, const int4& vec)
2227 {
2228 return os << "int4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
2229 }
2230 inline std::ostream& operator<<(std::ostream& os, const int3& vec)
2231 {
2232 return os << "int3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
2233 }
2234 inline std::ostream& operator<<(std::ostream& os, const int2& vec)
2235 {
2236 return os << "int2(" << vec.x << ", " << vec.y << ')';
2237 }
2238
2239
2240 inline std::ostream& operator<<(std::ostream& os, const uint4& vec)
2241 {
2242 return os << "uint4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
2243 }
2244 inline std::ostream& operator<<(std::ostream& os, const uint3& vec)
2245 {
2246 return os << "uint3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
2247 }
2248 inline std::ostream& operator<<(std::ostream& os, const uint2& vec)
2249 {
2250 return os << "uint2(" << vec.x << ", " << vec.y << ')';
2251 }
2252
22112253 } // namespace Diligent
22122254
22132255
7575 LOG_INFO_MESSAGE(ss.str());
7676 }
7777
78 } // namespace Test
78 } // namespace Testing
7979
8080 } // namespace Diligent
8181 namespace
2525 */
2626
2727 #include <climits>
28 #include <sstream>
2829
2930 #include "BasicMath.hpp"
3031 #include "AdvancedMath.hpp"
16841685 }
16851686 }
16861687
1688 TEST(Common_BasicMath, VectorInserters)
1689 {
1690 {
1691 std::stringstream ss;
1692 ss << float4{1, 20, 300, 4000};
1693 EXPECT_STREQ(ss.str().c_str(), "float4(1, 20, 300, 4000)");
1694 }
1695 {
1696 std::stringstream ss;
1697 ss << float3{1, 201, 302};
1698 EXPECT_STREQ(ss.str().c_str(), "float3(1, 201, 302)");
1699 }
1700 {
1701 std::stringstream ss;
1702 ss << float2{1, 23};
1703 EXPECT_STREQ(ss.str().c_str(), "float2(1, 23)");
1704 }
1705
1706 {
1707 std::stringstream ss;
1708 ss << int4{1, 20, 300, 4000};
1709 EXPECT_STREQ(ss.str().c_str(), "int4(1, 20, 300, 4000)");
1710 }
1711 {
1712 std::stringstream ss;
1713 ss << int3{1, 201, 302};
1714 EXPECT_STREQ(ss.str().c_str(), "int3(1, 201, 302)");
1715 }
1716 {
1717 std::stringstream ss;
1718 ss << int2{1, 23};
1719 EXPECT_STREQ(ss.str().c_str(), "int2(1, 23)");
1720 }
1721
1722 {
1723 std::stringstream ss;
1724 ss << uint4{1, 20, 300, 4000};
1725 EXPECT_STREQ(ss.str().c_str(), "uint4(1, 20, 300, 4000)");
1726 }
1727 {
1728 std::stringstream ss;
1729 ss << uint3{1, 201, 302};
1730 EXPECT_STREQ(ss.str().c_str(), "uint3(1, 201, 302)");
1731 }
1732 {
1733 std::stringstream ss;
1734 ss << uint2{1, 23};
1735 EXPECT_STREQ(ss.str().c_str(), "uint2(1, 23)");
1736 }
1737 }
16871738
16881739 TEST(Common_AdvancedMath, IsPointInsideTriangleF)
16891740 {