diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-26 03:04:44 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-26 03:09:15 +0300 |
commit | 8a68f4f80814a28d68055a0ae0b22a7efe1c2619 (patch) | |
tree | c89d4c3343836b0b8321be1beb55d7b547a6d6a3 /source/blender/freestyle/intern/geometry | |
parent | 15f3cf7f8f956a6372b6a99788b622946ba3d1e5 (diff) |
Cleanup: replace unsigned with uint, use function style casts for C++
Diffstat (limited to 'source/blender/freestyle/intern/geometry')
7 files changed, 57 insertions, 60 deletions
diff --git a/source/blender/freestyle/intern/geometry/FastGrid.cpp b/source/blender/freestyle/intern/geometry/FastGrid.cpp index f87b25ebc71..24ecacbad2a 100644 --- a/source/blender/freestyle/intern/geometry/FastGrid.cpp +++ b/source/blender/freestyle/intern/geometry/FastGrid.cpp @@ -32,7 +32,7 @@ void FastGrid::clear() Grid::clear(); } -void FastGrid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) +void FastGrid::configure(const Vec3r &orig, const Vec3r &size, uint nb) { Grid::configure(orig, size, nb); _cells_size = _cells_nb[0] * _cells_nb[1] * _cells_nb[2]; diff --git a/source/blender/freestyle/intern/geometry/FitCurve.cpp b/source/blender/freestyle/intern/geometry/FitCurve.cpp index eb53fd1257c..3ea83576e8f 100644 --- a/source/blender/freestyle/intern/geometry/FitCurve.cpp +++ b/source/blender/freestyle/intern/geometry/FitCurve.cpp @@ -273,7 +273,7 @@ static Vector2 BezierII(int degree, Vector2 *V, double t) Vector2 *Vtemp; /* Local copy of control points */ /* Copy array */ - Vtemp = (Vector2 *)malloc((unsigned)((degree + 1) * sizeof(Vector2))); + Vtemp = (Vector2 *)malloc(uint((degree + 1) * sizeof(Vector2))); for (i = 0; i <= degree; i++) { Vtemp[i] = V[i]; } @@ -376,7 +376,7 @@ static double *ChordLengthParameterize(Vector2 *d, int first, int last) int i; double *u; /* Parameterization */ - u = (double *)malloc((unsigned)(last - first + 1) * sizeof(double)); + u = (double *)malloc(uint(last - first + 1) * sizeof(double)); u[0] = 0.0; for (i = first + 1; i <= last; i++) { diff --git a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp index 1bbea79d793..c17fb92a58c 100644 --- a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp +++ b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp @@ -30,15 +30,15 @@ using namespace std; namespace Freestyle { void GeomCleaner::SortIndexedVertexArray(const float *iVertices, - unsigned iVSize, - const unsigned *iIndices, - unsigned iISize, + uint iVSize, + const uint *iIndices, + uint iISize, float **oVertices, - unsigned **oIndices) + uint **oIndices) { // First, we build a list of IndexVertex: list<IndexedVertex> indexedVertices; - unsigned i; + uint i; for (i = 0; i < iVSize; i += 3) { indexedVertices.emplace_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2]), i / 3); } @@ -47,11 +47,11 @@ void GeomCleaner::SortIndexedVertexArray(const float *iVertices, indexedVertices.sort(); // build the indices mapping array: - unsigned *mapIndices = new unsigned[iVSize / 3]; + uint *mapIndices = new uint[iVSize / 3]; *oVertices = new float[iVSize]; list<IndexedVertex>::iterator iv; - unsigned newIndex = 0; - unsigned vIndex = 0; + uint newIndex = 0; + uint vIndex = 0; for (iv = indexedVertices.begin(); iv != indexedVertices.end(); iv++) { // Build the final results: (*oVertices)[vIndex] = iv->x(); @@ -64,7 +64,7 @@ void GeomCleaner::SortIndexedVertexArray(const float *iVertices, } // Build the final index array: - *oIndices = new unsigned[iISize]; + *oIndices = new uint[iISize]; for (i = 0; i < iISize; i++) { (*oIndices)[i] = 3 * mapIndices[iIndices[i] / 3]; } @@ -73,21 +73,21 @@ void GeomCleaner::SortIndexedVertexArray(const float *iVertices, } void GeomCleaner::CompressIndexedVertexArray(const float *iVertices, - unsigned iVSize, - const unsigned *iIndices, - unsigned iISize, + uint iVSize, + const uint *iIndices, + uint iISize, float **oVertices, - unsigned *oVSize, - unsigned **oIndices) + uint *oVSize, + uint **oIndices) { // First, we build a list of IndexVertex: vector<Vec3f> vertices; - unsigned i; + uint i; for (i = 0; i < iVSize; i += 3) { vertices.emplace_back(iVertices[i], iVertices[i + 1], iVertices[i + 2]); } - unsigned *mapVertex = new unsigned[iVSize]; + uint *mapVertex = new uint[iVSize]; vector<Vec3f>::iterator v = vertices.begin(); vector<Vec3f> compressedVertices; @@ -123,7 +123,7 @@ void GeomCleaner::CompressIndexedVertexArray(const float *iVertices, } // Map the index array: - *oIndices = new unsigned[iISize]; + *oIndices = new uint[iISize]; for (i = 0; i < iISize; i++) { (*oIndices)[i] = 3 * mapVertex[iIndices[i] / 3]; } @@ -132,16 +132,16 @@ void GeomCleaner::CompressIndexedVertexArray(const float *iVertices, } void GeomCleaner::SortAndCompressIndexedVertexArray(const float *iVertices, - unsigned iVSize, - const unsigned *iIndices, - unsigned iISize, + uint iVSize, + const uint *iIndices, + uint iISize, float **oVertices, - unsigned *oVSize, - unsigned **oIndices) + uint *oVSize, + uint **oIndices) { // tmp arrays used to store the sorted data: float *tmpVertices; - unsigned *tmpIndices; + uint *tmpIndices; Chronometer chrono; // Sort data @@ -181,26 +181,26 @@ struct GeomCleanerHasher { }; void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, - unsigned iVSize, - const unsigned *iIndices, - unsigned iISize, + uint iVSize, + const uint *iIndices, + uint iISize, float **oVertices, - unsigned *oVSize, - unsigned **oIndices) + uint *oVSize, + uint **oIndices) { - using cleanHashTable = map<Vec3f, unsigned>; + using cleanHashTable = map<Vec3f, uint>; vector<Vec3f> vertices; - unsigned i; + uint i; for (i = 0; i < iVSize; i += 3) { vertices.emplace_back(iVertices[i], iVertices[i + 1], iVertices[i + 2]); } cleanHashTable ht; - vector<unsigned> newIndices; + vector<uint> newIndices; vector<Vec3f> newVertices; // elimination of needless points - unsigned currentIndex = 0; + uint currentIndex = 0; vector<Vec3f>::const_iterator v = vertices.begin(); vector<Vec3f>::const_iterator end = vertices.end(); cleanHashTable::const_iterator found; @@ -230,7 +230,7 @@ void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, } // map new indices: - *oIndices = new unsigned[iISize]; + *oIndices = new uint[iISize]; for (i = 0; i < iISize; i++) { (*oIndices)[i] = 3 * newIndices[iIndices[i] / 3]; } diff --git a/source/blender/freestyle/intern/geometry/GeomUtils.cpp b/source/blender/freestyle/intern/geometry/GeomUtils.cpp index 742d5f2fd02..f1e4297ab5e 100644 --- a/source/blender/freestyle/intern/geometry/GeomUtils.cpp +++ b/source/blender/freestyle/intern/geometry/GeomUtils.cpp @@ -10,7 +10,7 @@ namespace Freestyle::GeomUtils { // This internal procedure is defined below. -bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, unsigned n); +bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, uint n); bool intersect2dSeg2dArea(const Vec2r &min, const Vec2r &max, const Vec2r &A, const Vec2r &B) { @@ -739,7 +739,7 @@ void fromCameraToWorld(const Vec3r &p, Vec3r &q, const real model_view_matrix[4] #define PERP(u, v) ((u)[0] * (v)[1] - (u)[1] * (v)[0]) // 2D perp product -inline bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, unsigned n) +inline bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, uint n) { if (seg[0] == seg[1]) { return false; diff --git a/source/blender/freestyle/intern/geometry/Grid.cpp b/source/blender/freestyle/intern/geometry/Grid.cpp index ad45ab4eb42..e0e3af0fe47 100644 --- a/source/blender/freestyle/intern/geometry/Grid.cpp +++ b/source/blender/freestyle/intern/geometry/Grid.cpp @@ -93,7 +93,7 @@ void Grid::clear() //_ray_occluders.clear(); } -void Grid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) +void Grid::configure(const Vec3r &orig, const Vec3r &size, uint nb) { _orig = orig; Vec3r tmpSize = size; @@ -125,9 +125,9 @@ void Grid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) real edge = pow(cell_vol, 1.0 / 3.0); // We compute the number of cells par edge such as we cover at least the whole box. - unsigned i; + uint i; for (i = 0; i < 3; i++) { - _cells_nb[i] = (unsigned)floor(tmpSize[i] / edge) + 1; + _cells_nb[i] = uint(floor(tmpSize[i] / edge)) + 1; } _size = tmpSize; @@ -161,7 +161,7 @@ void Grid::insertOccluder(Polygon3r *occluder) // overlapping with the triangle in order to only fill in the ones really overlapping the // triangle. - unsigned i, x, y, z; + uint i, x, y, z; vector<Vec3r>::const_iterator it; Vec3u coord; @@ -225,10 +225,10 @@ bool Grid::nextRayCell(Vec3u ¤t_cell, Vec3u &next_cell) { next_cell = current_cell; real t_min, t; - unsigned i; + uint i; - t_min = FLT_MAX; // init tmin with handle of the case where one or 2 _u[i] = 0. - unsigned coord = 0; // predominant coord(0=x, 1=y, 2=z) + t_min = FLT_MAX; // init tmin with handle of the case where one or 2 _u[i] = 0. + uint coord = 0; // predominant coord(0=x, 1=y, 2=z) // using a parametric equation of a line : B = A + t u, we find the tx, ty and tz respectively // corresponding to the intersections with the plans: @@ -280,10 +280,7 @@ bool Grid::nextRayCell(Vec3u ¤t_cell, Vec3u &next_cell) return true; } -void Grid::castRay(const Vec3r &orig, - const Vec3r &end, - OccludersSet &occluders, - unsigned timestamp) +void Grid::castRay(const Vec3r &orig, const Vec3r &end, OccludersSet &occluders, uint timestamp) { initRay(orig, end, timestamp); allOccludersGridVisitor visitor(occluders); @@ -293,7 +290,7 @@ void Grid::castRay(const Vec3r &orig, void Grid::castInfiniteRay(const Vec3r &orig, const Vec3r &dir, OccludersSet &occluders, - unsigned timestamp) + uint timestamp) { Vec3r end = Vec3r(orig + FLT_MAX * dir / dir.norm()); bool inter = initInfiniteRay(orig, dir, timestamp); @@ -305,7 +302,7 @@ void Grid::castInfiniteRay(const Vec3r &orig, } Polygon3r *Grid::castRayToFindFirstIntersection( - const Vec3r &orig, const Vec3r &dir, double &t, double &u, double &v, unsigned timestamp) + const Vec3r &orig, const Vec3r &dir, double &t, double &u, double &v, uint timestamp) { Polygon3r *occluder = nullptr; Vec3r end = Vec3r(orig + FLT_MAX * dir / dir.norm()); @@ -325,7 +322,7 @@ Polygon3r *Grid::castRayToFindFirstIntersection( return occluder; } -void Grid::initRay(const Vec3r &orig, const Vec3r &end, unsigned timestamp) +void Grid::initRay(const Vec3r &orig, const Vec3r &end, uint timestamp) { _ray_dir = end - orig; _t_end = _ray_dir.norm(); @@ -333,15 +330,15 @@ void Grid::initRay(const Vec3r &orig, const Vec3r &end, unsigned timestamp) _ray_dir.normalize(); _timestamp = timestamp; - for (unsigned i = 0; i < 3; i++) { - _current_cell[i] = (unsigned)floor((orig[i] - _orig[i]) / _cell_size[i]); + for (uint i = 0; i < 3; i++) { + _current_cell[i] = uint(floor((orig[i] - _orig[i]) / _cell_size[i])); // soc unused - unsigned u = _current_cell[i]; _pt[i] = orig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; } //_ray_occluders.clear(); } -bool Grid::initInfiniteRay(const Vec3r &orig, const Vec3r &dir, unsigned timestamp) +bool Grid::initInfiniteRay(const Vec3r &orig, const Vec3r &dir, uint timestamp) { _ray_dir = dir; _t_end = FLT_MAX; @@ -367,7 +364,7 @@ bool Grid::initInfiniteRay(const Vec3r &orig, const Vec3r &dir, unsigned timesta BLI_assert(tmin != -1.0); Vec3r newOrig = orig + tmin * _ray_dir; for (uint i = 0; i < 3; i++) { - _current_cell[i] = (unsigned)floor((newOrig[i] - _orig[i]) / _cell_size[i]); + _current_cell[i] = uint(floor((newOrig[i] - _orig[i]) / _cell_size[i])); if (_current_cell[i] == _cells_nb[i]) { _current_cell[i] = _cells_nb[i] - 1; } diff --git a/source/blender/freestyle/intern/geometry/HashGrid.cpp b/source/blender/freestyle/intern/geometry/HashGrid.cpp index c86aa4fd22c..51c87757645 100644 --- a/source/blender/freestyle/intern/geometry/HashGrid.cpp +++ b/source/blender/freestyle/intern/geometry/HashGrid.cpp @@ -22,7 +22,7 @@ void HashGrid::clear() Grid::clear(); } -void HashGrid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) +void HashGrid::configure(const Vec3r &orig, const Vec3r &size, uint nb) { Grid::configure(orig, size, nb); } diff --git a/source/blender/freestyle/intern/geometry/Noise.cpp b/source/blender/freestyle/intern/geometry/Noise.cpp index 95a742e9d0d..306913e6297 100644 --- a/source/blender/freestyle/intern/geometry/Noise.cpp +++ b/source/blender/freestyle/intern/geometry/Noise.cpp @@ -69,7 +69,7 @@ static void normalize3(float v[3]) v[2] = v[2] / s; } -float Noise::turbulence1(float arg, float freq, float amp, unsigned oct) +float Noise::turbulence1(float arg, float freq, float amp, uint oct) { float t; float vec; @@ -81,7 +81,7 @@ float Noise::turbulence1(float arg, float freq, float amp, unsigned oct) return t; } -float Noise::turbulence2(Vec2f &v, float freq, float amp, unsigned oct) +float Noise::turbulence2(Vec2f &v, float freq, float amp, uint oct) { float t; Vec2f vec; @@ -94,7 +94,7 @@ float Noise::turbulence2(Vec2f &v, float freq, float amp, unsigned oct) return t; } -float Noise::turbulence3(Vec3f &v, float freq, float amp, unsigned oct) +float Noise::turbulence3(Vec3f &v, float freq, float amp, uint oct) { float t; Vec3f vec; |