style: remove all "using namespace std"

This commit is contained in:
Eric Wasylishen 2023-08-07 15:28:50 -06:00
parent db42b2116a
commit f8886b6e60
7 changed files with 54 additions and 65 deletions

View File

@ -170,8 +170,6 @@ float Lanczos2D(float x, float y, float a)
return lanczos;
}
using namespace std;
qvec3f FaceNormal(std::vector<qvec3f> points)
{
const int N = static_cast<int>(points.size());
@ -211,22 +209,22 @@ std::pair<bool, qvec4f> 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<qvec4f> MakeInwardFacingEdgePlanes(const std::vector<qvec3f> &points)
std::vector<qvec4f> MakeInwardFacingEdgePlanes(const std::vector<qvec3f> &points)
{
const size_t N = points.size();
if (N < 3)
return {};
vector<qvec4f> result;
std::vector<qvec4f> result;
result.reserve(points.size());
const qvec3f faceNormal = FaceNormal(points);
@ -261,7 +259,7 @@ float EdgePlanes_PointInsideDist(const std::vector<qvec4f> &edgeplanes, const qv
return min; // "outermost" point
}
bool EdgePlanes_PointInside(const vector<qvec4f> &edgeplanes, const qvec3f &point)
bool EdgePlanes_PointInside(const std::vector<qvec4f> &edgeplanes, const qvec3f &point)
{
if (edgeplanes.empty())
return false;
@ -354,7 +352,7 @@ std::pair<int, qvec3f> ClosestPointOnPolyBoundary(const std::vector<qvec3f> &pol
Q_assert(bestI != -1);
return make_pair(bestI, bestPointOnPoly);
return std::make_pair(bestI, bestPointOnPoly);
}
std::pair<bool, qvec3f> InterpolateNormal(
@ -374,7 +372,7 @@ std::pair<bool, qvec3f> 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<bool, qvec3f> 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<qvec3f>, std::vector<qvec3f>> ClipPoly(const std::vector<qvec3f> &poly, const qvec4f &plane)
{
if (poly.empty())
return make_pair(vector<qvec3f>(), vector<qvec3f>());
return make_pair(std::vector<qvec3f>(), std::vector<qvec3f>());
winding_t w = winding_t::from_winding_points(poly);
@ -430,9 +428,9 @@ std::pair<std::vector<qvec3f>, std::vector<qvec3f>> ClipPoly(const std::vector<q
std::vector<qvec3f> ShrinkPoly(const std::vector<qvec3f> &poly, const float amount)
{
const vector<qvec4f> edgeplanes = MakeInwardFacingEdgePlanes(poly);
const std::vector<qvec4f> edgeplanes = MakeInwardFacingEdgePlanes(poly);
vector<qvec3f> clipped = poly;
std::vector<qvec3f> clipped = poly;
for (const qvec4f &edge : edgeplanes) {
const qvec4f shrunkEdgePlane(edge[0], edge[1], edge[2], edge[3] + amount);

View File

@ -39,7 +39,6 @@
#include <common/qvec.hh>
#include <common/parallel.hh>
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<qvec3f> points;
std::vector<qvec3f> points;
if (light_options.emissivequality.value() == emissivequality_t::LOW ||
light_options.emissivequality.value() == emissivequality_t::MEDIUM) {

View File

@ -40,8 +40,6 @@
#include <algorithm>
#include <fstream>
using namespace std;
std::atomic<uint32_t> total_light_rays, total_light_ray_hits, total_samplepoints;
std::atomic<uint32_t> total_bounce_rays, total_bounce_ray_hits;
std::atomic<uint32_t> 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<int, qvec3f> closest = ClosestPointOnPolyBoundary(points, point);
const std::pair<int, qvec3f> closest = ClosestPointOnPolyBoundary(points, point);
float luxelSpaceDist;
{
auto desired_point_in_lmspace = faceextents.worldToLMCoord(point);

View File

@ -38,8 +38,6 @@
#include <common/qvec.hh>
#include <tbb/parallel_for_each.h>
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<face_normal_t> &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<neighbour_t> *result)
const qvec3f &p0, const qvec3f &p1, const mbsp_t *bsp, int nodenum, std::vector<neighbour_t> *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<neighbour_t> FacesOverlappingEdge(
inline std::vector<neighbour_t> FacesOverlappingEdge(
const qvec3f &p0, const qvec3f &p1, const mbsp_t *bsp, const dmodelh2_t *model)
{
vector<neighbour_t> result;
std::vector<neighbour_t> 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<const mface_t *, std::vector<face_normal_t>> vertex_normals;
static map<const mface_t *, set<const mface_t *>> smoothFaces;
static map<int, vector<const mface_t *>> vertsToFaces;
static map<int, vector<const mface_t *>> planesToFaces;
static std::map<const mface_t *, std::set<const mface_t *>> smoothFaces;
static std::map<int, std::vector<const mface_t *>> vertsToFaces;
static std::map<int, std::vector<const mface_t *>> planesToFaces;
static edgeToFaceMap_t EdgeToFaceMap;
static vector<face_cache_t> FaceCache;
static std::vector<face_cache_t> FaceCache;
void ResetPhong()
{
@ -198,7 +196,7 @@ void ResetPhong()
FaceCache = {};
}
vector<const mface_t *> FacesUsingVert(int vertnum)
std::vector<const mface_t *> 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<const mface_t *> &faceSet = facesIt->second;
const std::set<const mface_t *> &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_normal_t> Face_VertexNormals(const mbsp_t *bsp, const mface_t *face)
static std::vector<face_normal_t> Face_VertexNormals(const mbsp_t *bsp, const mface_t *face)
{
vector<face_normal_t> normals(face->numedges);
std::vector<face_normal_t> normals(face->numedges);
tbb::parallel_for(0, face->numedges, [&](size_t i) { normals[i] = GetSurfaceVertexNormal(bsp, face, i); });
return normals;
}
#include <common/parallel.hh>
static vector<face_cache_t> MakeFaceCache(const mbsp_t *bsp)
static std::vector<face_cache_t> MakeFaceCache(const mbsp_t *bsp)
{
logging::funcheader();
vector<face_cache_t> result(bsp->dfaces.size());
std::vector<face_cache_t> result(bsp->dfaces.size());
logging::parallel_for(static_cast<size_t>(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));

View File

@ -37,7 +37,6 @@ See file, 'COPYING', for details.
#include <common/qvec.hh>
using namespace std;
using namespace polylib;
static std::atomic_size_t total_surflight_points;

View File

@ -27,7 +27,6 @@
#include <vector>
#include <climits>
using namespace std;
using namespace polylib;
sceneinfo skygeom; // sky. always occludes.

View File

@ -11,8 +11,6 @@
#include <common/aabb.hh>
using namespace std;
TEST_SUITE("mathlib")
{
@ -37,7 +35,7 @@ TEST_SUITE("mathlib")
REQUIRE(2 == SampleCDF(cdf, 1));
}
static void checkBox(const vector<qvec4f> &edges, const vector<qvec3f> &poly)
static void checkBox(const std::vector<qvec4f> &edges, const std::vector<qvec3f> &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<qvec3f> poly{{0, 0, 0}, {64, 64, 0}, {0, 64, 0}, {64, 0, 0}};
const std::vector<qvec3f> poly{{0, 0, 0}, {64, 64, 0}, {0, 64, 0}, {64, 0, 0}};
const auto edges = MakeInwardFacingEdgePlanes(poly);
// CHECK(vector<qvec4f>() == edges);
@ -61,7 +59,7 @@ TEST_SUITE("mathlib")
TEST_CASE("SlightlyConcavePoly")
{
const vector<qvec3f> poly{qvec3f(225.846161, -1744, 1774), qvec3f(248, -1744, 1798),
const std::vector<qvec3f> 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<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}};
const std::vector<qvec3f> 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<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {0, 64, 0}, // repeat of last point
const std::vector<qvec3f> 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<qvec3f> poly{};
const std::vector<qvec3f> 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<qvec3f> poly{
const std::vector<qvec3f> poly{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
@ -115,7 +113,7 @@ TEST_SUITE("mathlib")
TEST_CASE("PointInPolygon_DegenerateFaceHandling3")
{
const vector<qvec3f> poly{
const std::vector<qvec3f> poly{
{0, 0, 0},
{10, 10, 10},
{20, 20, 20},
@ -130,7 +128,7 @@ TEST_SUITE("mathlib")
TEST_CASE("PointInPolygon_ColinearPointHandling")
{
// clockwise
const vector<qvec3f> poly{{0, 0, 0}, {0, 32, 0}, // colinear
const std::vector<qvec3f> 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<qvec3f> poly{
const std::vector<qvec3f> 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<qvec3f, 3> tri{qvec3f{0, 0, 0}, {0, 64, 0}, {64, 0, 0}};
const auto triAsVec = vector<qvec3f>{tri.begin(), tri.end()};
const auto triAsVec = std::vector<qvec3f>{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<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, // colinear
const std::vector<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, // colinear
{64, 64, 0}, {64, 0, 0}};
const vector<qvec3f> normals{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, // colinear
const std::vector<qvec3f> 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<qvec3f> &p1, const vector<qvec3f> &p2)
static bool polysEqual(const std::vector<qvec3f> &p1, const std::vector<qvec3f> &p2)
{
if (p1.size() != p2.size())
return false;
@ -345,11 +343,11 @@ TEST_SUITE("mathlib")
TEST_CASE("ClipPoly1")
{
const vector<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}};
const std::vector<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}};
const vector<qvec3f> frontRes{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, {32, 0, 0}};
const std::vector<qvec3f> frontRes{{0, 0, 0}, {0, 64, 0}, {32, 64, 0}, {32, 0, 0}};
const vector<qvec3f> backRes{{32, 64, 0}, {64, 64, 0}, {64, 0, 0}, {32, 0, 0}};
const std::vector<qvec3f> 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<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}};
const std::vector<qvec3f> poly{{0, 0, 0}, {0, 64, 0}, {64, 64, 0}, {64, 0, 0}};
const vector<qvec3f> shrunkPoly{{1, 1, 0}, {1, 63, 0}, {63, 63, 0}, {63, 1, 0}};
const std::vector<qvec3f> 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<qvec3f> poly{{0, 0, 0}, {64, 64, 0}, {64, 0, 0}};
const std::vector<qvec3f> poly{{0, 0, 0}, {64, 64, 0}, {64, 0, 0}};
const vector<qvec3f> shrunkPoly{
const std::vector<qvec3f> shrunkPoly{
{1.0f + sqrtf(2.0f), 1.0f, 0.0f},
{63.0f, 63.0f - sqrtf(2.0f), 0.0f},
{63, 1, 0},