diff --git a/common/mathlib.cc b/common/mathlib.cc index 2a9579ee..1c682cae 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -170,8 +170,6 @@ float Lanczos2D(float x, float y, float a) return lanczos; } -using namespace std; - qvec3f FaceNormal(std::vector points) { const int N = static_cast(points.size()); @@ -211,22 +209,22 @@ std::pair MakeInwardFacingEdgePlane(const qvec3f &v0, const qvec3f { const float v0v1len = qv::length(v1 - v0); if (v0v1len < POINT_EQUAL_EPSILON) - return make_pair(false, qvec4f(0)); + return std::make_pair(false, qvec4f(0)); const qvec3f edgedir = (v1 - v0) / v0v1len; const qvec3f edgeplane_normal = qv::cross(edgedir, faceNormal); const float edgeplane_dist = qv::dot(edgeplane_normal, v0); - return make_pair(true, qvec4f(edgeplane_normal[0], edgeplane_normal[1], edgeplane_normal[2], edgeplane_dist)); + return std::make_pair(true, qvec4f(edgeplane_normal[0], edgeplane_normal[1], edgeplane_normal[2], edgeplane_dist)); } -vector MakeInwardFacingEdgePlanes(const std::vector &points) +std::vector MakeInwardFacingEdgePlanes(const std::vector &points) { const size_t N = points.size(); if (N < 3) return {}; - vector result; + std::vector result; result.reserve(points.size()); const qvec3f faceNormal = FaceNormal(points); @@ -261,7 +259,7 @@ float EdgePlanes_PointInsideDist(const std::vector &edgeplanes, const qv return min; // "outermost" point } -bool EdgePlanes_PointInside(const vector &edgeplanes, const qvec3f &point) +bool EdgePlanes_PointInside(const std::vector &edgeplanes, const qvec3f &point) { if (edgeplanes.empty()) return false; @@ -354,7 +352,7 @@ std::pair ClosestPointOnPolyBoundary(const std::vector &pol Q_assert(bestI != -1); - return make_pair(bestI, bestPointOnPoly); + return std::make_pair(bestI, bestPointOnPoly); } std::pair InterpolateNormal( @@ -374,7 +372,7 @@ std::pair InterpolateNormal( Q_assert(points.size() == normals.size()); if (points.size() < 3) - return make_pair(false, qvec3f{}); + return std::make_pair(false, qvec3f{}); // Step through the triangles, being careful to handle zero-size ones @@ -401,18 +399,18 @@ std::pair InterpolateNormal( continue; const qvec3f interpolatedNormal = qv::Barycentric_ToPoint(bary, n0, n1, n2); - return make_pair(true, interpolatedNormal); + return std::make_pair(true, interpolatedNormal); } } - return make_pair(false, qvec3f{}); + return std::make_pair(false, qvec3f{}); } /// Returns (front part, back part) std::pair, std::vector> ClipPoly(const std::vector &poly, const qvec4f &plane) { if (poly.empty()) - return make_pair(vector(), vector()); + return make_pair(std::vector(), std::vector()); winding_t w = winding_t::from_winding_points(poly); @@ -430,9 +428,9 @@ std::pair, std::vector> ClipPoly(const std::vector ShrinkPoly(const std::vector &poly, const float amount) { - const vector edgeplanes = MakeInwardFacingEdgePlanes(poly); + const std::vector edgeplanes = MakeInwardFacingEdgePlanes(poly); - vector clipped = poly; + std::vector clipped = poly; for (const qvec4f &edge : edgeplanes) { const qvec4f shrunkEdgePlane(edge[0], edge[1], edge[2], edge[3] + amount); diff --git a/light/bounce.cc b/light/bounce.cc index 6aecbc26..1a752853 100644 --- a/light/bounce.cc +++ b/light/bounce.cc @@ -39,7 +39,6 @@ #include #include -using namespace std; using namespace polylib; static std::atomic_size_t bouncelightpoints; @@ -225,7 +224,7 @@ static void MakeBounceLightsThread(const settings::worldspawn_keys &cfg, const m qvec3d facenormal = faceplane.normal; qvec3d facemidpoint = winding.center() + facenormal; // Lift 1 unit - vector points; + std::vector points; if (light_options.emissivequality.value() == emissivequality_t::LOW || light_options.emissivequality.value() == emissivequality_t::MEDIUM) { diff --git a/light/ltface.cc b/light/ltface.cc index 510cf3ab..1bc9ddf2 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -40,8 +40,6 @@ #include #include -using namespace std; - std::atomic total_light_rays, total_light_ray_hits, total_samplepoints; std::atomic total_bounce_rays, total_bounce_ray_hits; std::atomic total_surflight_rays, total_surflight_ray_hits; // mxd @@ -240,7 +238,7 @@ position_t CalcPointNormal(const mbsp_t *bsp, const mface_t *face, const qvec3f // 2. Try snapping to poly - const pair closest = ClosestPointOnPolyBoundary(points, point); + const std::pair closest = ClosestPointOnPolyBoundary(points, point); float luxelSpaceDist; { auto desired_point_in_lmspace = faceextents.worldToLMCoord(point); diff --git a/light/phong.cc b/light/phong.cc index ba028bcc..3a0efec1 100644 --- a/light/phong.cc +++ b/light/phong.cc @@ -38,8 +38,6 @@ #include #include -using namespace std; - face_cache_t::face_cache_t(){}; face_cache_t::face_cache_t(const mbsp_t *bsp, const mface_t *face, const std::vector &normals) @@ -68,7 +66,7 @@ static neighbour_t FaceOverlapsEdge(const qvec3f &p0, const qvec3f &p1, const mb } static void FacesOverlappingEdge_r( - const qvec3f &p0, const qvec3f &p1, const mbsp_t *bsp, int nodenum, vector *result) + const qvec3f &p0, const qvec3f &p1, const mbsp_t *bsp, int nodenum, std::vector *result) { if (nodenum < 0) { // we don't do anything for leafs. @@ -110,10 +108,10 @@ static void FacesOverlappingEdge_r( * Returns faces which have an edge that overlaps the given p0-p1 edge. * Uses hull 0. */ -inline vector FacesOverlappingEdge( +inline std::vector FacesOverlappingEdge( const qvec3f &p0, const qvec3f &p1, const mbsp_t *bsp, const dmodelh2_t *model) { - vector result; + std::vector result; FacesOverlappingEdge_r(p0, p1, bsp, model->headnode[0], &result); return result; } @@ -181,11 +179,11 @@ static float AngleBetweenPoints(const qvec3f &p1, const qvec3f &p2, const qvec3f static bool s_builtPhongCaches; static std::unordered_map> vertex_normals; -static map> smoothFaces; -static map> vertsToFaces; -static map> planesToFaces; +static std::map> smoothFaces; +static std::map> vertsToFaces; +static std::map> planesToFaces; static edgeToFaceMap_t EdgeToFaceMap; -static vector FaceCache; +static std::vector FaceCache; void ResetPhong() { @@ -198,7 +196,7 @@ void ResetPhong() FaceCache = {}; } -vector FacesUsingVert(int vertnum) +std::vector FacesUsingVert(int vertnum) { const auto &vertsToFaces_const = vertsToFaces; @@ -223,7 +221,7 @@ bool FacesSmoothed(const mface_t *f1, const mface_t *f2) if (facesIt == smoothFaces.end()) return false; - const set &faceSet = facesIt->second; + const std::set &faceSet = facesIt->second; if (faceSet.find(f2) == faceSet.end()) return false; @@ -295,7 +293,7 @@ const mface_t *Face_EdgeIndexSmoothed(const mbsp_t *bsp, const mface_t *f, const const int v0 = Face_VertexAtIndex(bsp, f, edgeindex); const int v1 = Face_VertexAtIndex(bsp, f, (edgeindex + 1) % f->numedges); - auto it = EdgeToFaceMap.find(make_pair(v1, v0)); + auto it = EdgeToFaceMap.find(std::make_pair(v1, v0)); if (it != EdgeToFaceMap.end()) { for (const mface_t *neighbour : it->second) { if (neighbour == f) { @@ -355,7 +353,7 @@ static edgeToFaceMap_t MakeEdgeToFaceMap(const mbsp_t *bsp) continue; } - const auto edge = make_pair(v0, v1); + const auto edge = std::make_pair(v0, v1); auto &edgeFacesRef = result[edge]; if (find(begin(edgeFacesRef), end(edgeFacesRef), &f) != end(edgeFacesRef)) { @@ -369,19 +367,19 @@ static edgeToFaceMap_t MakeEdgeToFaceMap(const mbsp_t *bsp) return result; } -static vector Face_VertexNormals(const mbsp_t *bsp, const mface_t *face) +static std::vector Face_VertexNormals(const mbsp_t *bsp, const mface_t *face) { - vector normals(face->numedges); + std::vector normals(face->numedges); tbb::parallel_for(0, face->numedges, [&](size_t i) { normals[i] = GetSurfaceVertexNormal(bsp, face, i); }); return normals; } #include -static vector MakeFaceCache(const mbsp_t *bsp) +static std::vector MakeFaceCache(const mbsp_t *bsp) { logging::funcheader(); - vector result(bsp->dfaces.size()); + std::vector result(bsp->dfaces.size()); logging::parallel_for(static_cast(0), bsp->dfaces.size(), [&](size_t i) { auto &face = bsp->dfaces[i]; result[i] = face_cache_t(bsp, &bsp->dfaces[i], Face_VertexNormals(bsp, &face)); diff --git a/light/surflight.cc b/light/surflight.cc index 65a19b64..575cc136 100644 --- a/light/surflight.cc +++ b/light/surflight.cc @@ -37,7 +37,6 @@ See file, 'COPYING', for details. #include -using namespace std; using namespace polylib; static std::atomic_size_t total_surflight_points; diff --git a/light/trace_embree.cc b/light/trace_embree.cc index d0b10b5c..284ab6b7 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -27,7 +27,6 @@ #include #include -using namespace std; using namespace polylib; sceneinfo skygeom; // sky. always occludes. diff --git a/tests/test_light.cc b/tests/test_light.cc index b0d4a8db..0f00c30b 100644 --- a/tests/test_light.cc +++ b/tests/test_light.cc @@ -11,8 +11,6 @@ #include -using namespace std; - TEST_SUITE("mathlib") { @@ -37,7 +35,7 @@ TEST_SUITE("mathlib") REQUIRE(2 == SampleCDF(cdf, 1)); } - static void checkBox(const vector &edges, const vector &poly) + static void checkBox(const std::vector &edges, const std::vector &poly) { CHECK(EdgePlanes_PointInside(edges, qvec3f(0, 0, 0))); CHECK(EdgePlanes_PointInside(edges, qvec3f(64, 0, 0))); @@ -53,7 +51,7 @@ TEST_SUITE("mathlib") TEST_CASE("EdgePlanesOfNonConvexPoly") { // hourglass, non-convex - const vector poly{{0, 0, 0}, {64, 64, 0}, {0, 64, 0}, {64, 0, 0}}; + const std::vector poly{{0, 0, 0}, {64, 64, 0}, {0, 64, 0}, {64, 0, 0}}; const auto edges = MakeInwardFacingEdgePlanes(poly); // CHECK(vector() == edges); @@ -61,7 +59,7 @@ TEST_SUITE("mathlib") TEST_CASE("SlightlyConcavePoly") { - const vector poly{qvec3f(225.846161, -1744, 1774), qvec3f(248, -1744, 1798), + const std::vector poly{qvec3f(225.846161, -1744, 1774), qvec3f(248, -1744, 1798), qvec3f(248, -1763.82605, 1799.65222), qvec3f(248, -1764, 1799.66663), qvec3f(248, -1892, 1810.33337), qvec3f(248, -1893.21741, 1810.43481), qvec3f(248, -1921.59998, 1812.80005), qvec3f(248, -1924, 1813), qvec3f(80, -1924, 1631), qvec3f(80, -1744, 1616)}; @@ -74,7 +72,7 @@ TEST_SUITE("mathlib") TEST_CASE("PointInPolygon") { // clockwise - const vector poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}}; + const std::vector poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}}; const auto edges = MakeInwardFacingEdgePlanes(poly); checkBox(edges, poly); @@ -83,7 +81,7 @@ TEST_SUITE("mathlib") TEST_CASE("PointInPolygon_DegenerateEdgeHandling") { // clockwise - const vector poly{{0, 0, 0}, {0, 64, 0}, {0, 64, 0}, // repeat of last point + const std::vector poly{{0, 0, 0}, {0, 64, 0}, {0, 64, 0}, // repeat of last point {64, 64, 0}, {64, 0, 0}}; const auto edges = MakeInwardFacingEdgePlanes(poly); @@ -92,7 +90,7 @@ TEST_SUITE("mathlib") TEST_CASE("PointInPolygon_DegenerateFaceHandling1") { - const vector poly{}; + const std::vector poly{}; const auto edges = MakeInwardFacingEdgePlanes(poly); CHECK_FALSE(EdgePlanes_PointInside(edges, qvec3f(0, 0, 0))); @@ -101,7 +99,7 @@ TEST_SUITE("mathlib") TEST_CASE("PointInPolygon_DegenerateFaceHandling2") { - const vector poly{ + const std::vector poly{ {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, @@ -115,7 +113,7 @@ TEST_SUITE("mathlib") TEST_CASE("PointInPolygon_DegenerateFaceHandling3") { - const vector poly{ + const std::vector poly{ {0, 0, 0}, {10, 10, 10}, {20, 20, 20}, @@ -130,7 +128,7 @@ TEST_SUITE("mathlib") TEST_CASE("PointInPolygon_ColinearPointHandling") { // clockwise - const vector poly{{0, 0, 0}, {0, 32, 0}, // colinear + const std::vector poly{{0, 0, 0}, {0, 32, 0}, // colinear {0, 64, 0}, {64, 64, 0}, {64, 0, 0}}; const auto edges = MakeInwardFacingEdgePlanes(poly); @@ -146,20 +144,20 @@ TEST_SUITE("mathlib") TEST_CASE("ClosestPointOnPolyBoundary") { // clockwise - const vector poly{ + const std::vector poly{ {0, 0, 0}, // edge 0 start, edge 3 end {0, 64, 0}, // edge 1 start, edge 0 end {64, 64, 0}, // edge 2 start, edge 1 end {64, 0, 0} // edge 3 start, edge 2 end }; - CHECK(make_pair(0, qvec3f(0, 0, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(0, 0, 0))); + CHECK(std::make_pair(0, qvec3f(0, 0, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(0, 0, 0))); // Either edge 1 or 2 contain the point qvec3f(64,64,0), but we expect the first edge to be returned - CHECK(make_pair(1, qvec3f(64, 64, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(100, 100, 100))); - CHECK(make_pair(2, qvec3f(64, 32, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(100, 32, 0))); + CHECK(std::make_pair(1, qvec3f(64, 64, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(100, 100, 100))); + CHECK(std::make_pair(2, qvec3f(64, 32, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(100, 32, 0))); - CHECK(make_pair(0, qvec3f(0, 0, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(-1, -1, 0))); + CHECK(std::make_pair(0, qvec3f(0, 0, 0)) == ClosestPointOnPolyBoundary(poly, qvec3f(-1, -1, 0))); } TEST_CASE("PolygonCentroid_empty") @@ -240,7 +238,7 @@ TEST_SUITE("mathlib") // clockwise const std::array tri{qvec3f{0, 0, 0}, {0, 64, 0}, {64, 0, 0}}; - const auto triAsVec = vector{tri.begin(), tri.end()}; + const auto triAsVec = std::vector{tri.begin(), tri.end()}; const auto edges = MakeInwardFacingEdgePlanes(triAsVec); const auto plane = PolyPlane(triAsVec); @@ -308,10 +306,10 @@ TEST_SUITE("mathlib") // |// | // o-----o - const vector poly{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, // colinear + const std::vector poly{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, // colinear {64, 64, 0}, {64, 0, 0}}; - const vector normals{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, // colinear + const std::vector normals{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, // colinear {0, 0, 0}, {-1, 0, 0}}; // First try all the known points @@ -332,7 +330,7 @@ TEST_SUITE("mathlib") CHECK_FALSE(InterpolateNormal(poly, normals, qvec3f(-0.1, 0, 0)).first); } - static bool polysEqual(const vector &p1, const vector &p2) + static bool polysEqual(const std::vector &p1, const std::vector &p2) { if (p1.size() != p2.size()) return false; @@ -345,11 +343,11 @@ TEST_SUITE("mathlib") TEST_CASE("ClipPoly1") { - const vector poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}}; + const std::vector poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}}; - const vector frontRes{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, {32, 0, 0}}; + const std::vector frontRes{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, {32, 0, 0}}; - const vector backRes{{32, 64, 0}, {64, 64, 0}, {64, 0, 0}, {32, 0, 0}}; + const std::vector backRes{{32, 64, 0}, {64, 64, 0}, {64, 0, 0}, {32, 0, 0}}; auto clipRes = ClipPoly(poly, qvec4f(-1, 0, 0, -32)); @@ -359,9 +357,9 @@ TEST_SUITE("mathlib") TEST_CASE("ShrinkPoly1") { - const vector poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}}; + const std::vector poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}}; - const vector shrunkPoly{{1, 1, 0}, {1, 63, 0}, {63, 63, 0}, {63, 1, 0}}; + const std::vector shrunkPoly{{1, 1, 0}, {1, 63, 0}, {63, 63, 0}, {63, 1, 0}}; const auto actualShrunk = ShrinkPoly(poly, 1.0f); @@ -370,9 +368,9 @@ TEST_SUITE("mathlib") TEST_CASE("ShrinkPoly2") { - const vector poly{{0, 0, 0}, {64, 64, 0}, {64, 0, 0}}; + const std::vector poly{{0, 0, 0}, {64, 64, 0}, {64, 0, 0}}; - const vector shrunkPoly{ + const std::vector shrunkPoly{ {1.0f + sqrtf(2.0f), 1.0f, 0.0f}, {63.0f, 63.0f - sqrtf(2.0f), 0.0f}, {63, 1, 0},