From d8dbd49a2f23b7637f05fc058f39bdf6ab706624 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 31 May 2019 22:51:19 +1000 Subject: Cleanup: style, use braces in source/ Automated using clang-tidy. --- source/blender/freestyle/intern/geometry/BBox.h | 18 ++-- .../blender/freestyle/intern/geometry/Bezier.cpp | 15 ++- .../blender/freestyle/intern/geometry/FastGrid.cpp | 6 +- .../blender/freestyle/intern/geometry/FitCurve.cpp | 6 +- .../freestyle/intern/geometry/GeomCleaner.cpp | 9 +- .../freestyle/intern/geometry/GeomUtils.cpp | 114 +++++++++++++------- .../blender/freestyle/intern/geometry/GeomUtils.h | 6 +- source/blender/freestyle/intern/geometry/Grid.cpp | 36 ++++--- source/blender/freestyle/intern/geometry/Grid.h | 15 ++- .../blender/freestyle/intern/geometry/HashGrid.h | 3 +- source/blender/freestyle/intern/geometry/Noise.cpp | 12 ++- source/blender/freestyle/intern/geometry/Polygon.h | 12 ++- source/blender/freestyle/intern/geometry/VecMat.h | 120 ++++++++++++++------- 13 files changed, 248 insertions(+), 124 deletions(-) (limited to 'source/blender/freestyle/intern/geometry') diff --git a/source/blender/freestyle/intern/geometry/BBox.h b/source/blender/freestyle/intern/geometry/BBox.h index 7350fabbc13..71384d33bc6 100644 --- a/source/blender/freestyle/intern/geometry/BBox.h +++ b/source/blender/freestyle/intern/geometry/BBox.h @@ -59,10 +59,12 @@ template class BBox { return; } for (unsigned int i = 0; i < Point::dim(); i++) { - if (p[i] < _min[i]) + if (p[i] < _min[i]) { _min[i] = p[i]; - else if (p[i] > _max[i]) + } + else if (p[i] > _max[i]) { _max[i] = p[i]; + } } _empty = false; } @@ -106,10 +108,12 @@ template class BBox { } else { for (unsigned int i = 0; i < Point::dim(); i++) { - if (b.getMin()[i] < _min[i]) + if (b.getMin()[i] < _min[i]) { _min[i] = b.getMin()[i]; - if (b.getMax()[i] > _max[i]) + } + if (b.getMax()[i] > _max[i]) { _max[i] = b.getMax()[i]; + } } } return *this; @@ -117,11 +121,13 @@ template class BBox { inline bool inside(const Point &p) { - if (empty()) + if (empty()) { return false; + } for (unsigned int i = 0; i < Point::dim(); i++) { - if ((_min[i] > p[i]) || (_max[i] < p[i])) + if ((_min[i] > p[i]) || (_max[i] < p[i])) { return false; + } } return true; } diff --git a/source/blender/freestyle/intern/geometry/Bezier.cpp b/source/blender/freestyle/intern/geometry/Bezier.cpp index 3f6b6b25f76..9a832c04699 100644 --- a/source/blender/freestyle/intern/geometry/Bezier.cpp +++ b/source/blender/freestyle/intern/geometry/Bezier.cpp @@ -37,14 +37,16 @@ BezierCurveSegment::~BezierCurveSegment() void BezierCurveSegment::AddControlPoint(const Vec2d &iPoint) { _ControlPolygon.push_back(iPoint); - if (_ControlPolygon.size() == 4) + if (_ControlPolygon.size() == 4) { Build(); + } } void BezierCurveSegment::Build() { - if (_ControlPolygon.size() != 4) + if (_ControlPolygon.size() != 4) { return; + } // Compute the rightmost part of the matrix: vector::const_iterator p0, p1, p2, p3; @@ -92,8 +94,9 @@ BezierCurve::BezierCurve(vector &iPoints, double error) int i = 0; vector::iterator v, vend; for (v = curve.begin(), vend = curve.end(); v != vend; ++v) { - if ((i == 0) || (i % 4 != 0)) + if ((i == 0) || (i % 4 != 0)) { AddControlPoint(*v); + } ++i; } } @@ -102,11 +105,13 @@ BezierCurve::~BezierCurve() { if (!_Segments.empty()) { vector::iterator v, vend; - for (v = _Segments.begin(), vend = _Segments.end(); v != vend; ++v) + for (v = _Segments.begin(), vend = _Segments.end(); v != vend; ++v) { delete *v; + } } - if (_currentSegment) + if (_currentSegment) { delete _currentSegment; + } } void BezierCurve::AddControlPoint(const Vec2d &iPoint) diff --git a/source/blender/freestyle/intern/geometry/FastGrid.cpp b/source/blender/freestyle/intern/geometry/FastGrid.cpp index e0d36bece6e..1e5707690a0 100644 --- a/source/blender/freestyle/intern/geometry/FastGrid.cpp +++ b/source/blender/freestyle/intern/geometry/FastGrid.cpp @@ -30,12 +30,14 @@ namespace Freestyle { void FastGrid::clear() { - if (!_cells) + if (!_cells) { return; + } for (unsigned int i = 0; i < _cells_size; i++) { - if (_cells[i]) + if (_cells[i]) { delete _cells[i]; + } } delete[] _cells; _cells = NULL; diff --git a/source/blender/freestyle/intern/geometry/FitCurve.cpp b/source/blender/freestyle/intern/geometry/FitCurve.cpp index 368c3d2f46c..e7d67756535 100644 --- a/source/blender/freestyle/intern/geometry/FitCurve.cpp +++ b/source/blender/freestyle/intern/geometry/FitCurve.cpp @@ -266,8 +266,9 @@ static double NewtonRaphsonRootFind(BezierCurve Q, Vector2 P, double u) (Q_u[1] - P[1]) * (Q2_u[1]); /* u = u - f(u)/f'(u) */ - if (denominator == 0) // FIXME + if (denominator == 0) { // FIXME return u; + } uPrime = u - (numerator / denominator); return uPrime; } @@ -472,8 +473,9 @@ FitCurveWrapper::~FitCurveWrapper() void FitCurveWrapper::DrawBezierCurve(int n, Vector2 *curve) { - for (int i = 0; i <= n; ++i) + for (int i = 0; i <= n; ++i) { _vertices.push_back(curve[i]); + } } void FitCurveWrapper::FitCurve(vector &data, vector &oCurve, double error) diff --git a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp index 32d6fc62085..9fb830c056c 100644 --- a/source/blender/freestyle/intern/geometry/GeomCleaner.cpp +++ b/source/blender/freestyle/intern/geometry/GeomCleaner.cpp @@ -115,8 +115,9 @@ void GeomCleaner::CompressIndexedVertexArray(const float *iVertices, i = 1; for (; v != vertices.end(); v++) { current = *v; - if (current == previous) + if (current == previous) { mapVertex[i] = compressedVertices.size() - 1; + } else { compressedVertices.push_back(current); mapVertex[i] = compressedVertices.size() - 1; @@ -205,8 +206,9 @@ void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, typedef map cleanHashTable; vector vertices; unsigned i; - for (i = 0; i < iVSize; i += 3) + for (i = 0; i < iVSize; i += 3) { vertices.push_back(Vec3f(iVertices[i], iVertices[i + 1], iVertices[i + 2])); + } cleanHashTable ht; vector newIndices; @@ -244,8 +246,9 @@ void GeomCleaner::CleanIndexedVertexArray(const float *iVertices, // map new indices: *oIndices = new unsigned[iISize]; - for (i = 0; i < iISize; i++) + for (i = 0; i < iISize; i++) { (*oIndices)[i] = 3 * newIndices[iIndices[i] / 3]; + } } } /* namespace Freestyle */ diff --git a/source/blender/freestyle/intern/geometry/GeomUtils.cpp b/source/blender/freestyle/intern/geometry/GeomUtils.cpp index bec6ed27cc4..e6b1c947476 100644 --- a/source/blender/freestyle/intern/geometry/GeomUtils.cpp +++ b/source/blender/freestyle/intern/geometry/GeomUtils.cpp @@ -76,8 +76,9 @@ intersection_test intersect2dSeg2dSeg( // Check signs of r3 and r4. If both point 3 and point 4 lie on same side of line 1, // the line segments do not intersect. - if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) + if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) { return (DONT_INTERSECT); + } // Compute a2, b2, c2 a2 = p4[1] - p3[1]; @@ -90,13 +91,15 @@ intersection_test intersect2dSeg2dSeg( // Check signs of r1 and r2. If both point 1 and point 2 lie on same side of second line // segment, the line segments do not intersect. - if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) + if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) { return (DONT_INTERSECT); + } // Line segments intersect: compute intersection point. denom = a1 * b2 - a2 * b1; - if (fabs(denom) < M_EPSILON) + if (fabs(denom) < M_EPSILON) { return (COLINEAR); + } num = b1 * c2 - b2 * c1; res[0] = num / denom; @@ -125,8 +128,9 @@ intersection_test intersect2dLine2dLine( // Line segments intersect: compute intersection point. denom = a1 * b2 - a2 * b1; - if (fabs(denom) < M_EPSILON) + if (fabs(denom) < M_EPSILON) { return (COLINEAR); + } num = b1 * c2 - b2 * c1; res[0] = num / denom; @@ -160,8 +164,9 @@ intersection_test intersect2dSeg2dSegParametric(const Vec2r &p1, // Check signs of r3 and r4. If both point 3 and point 4 lie on same side of line 1, // the line segments do not intersect. - if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) + if (r3 != 0 && r4 != 0 && r3 * r4 > 0.0) { return (DONT_INTERSECT); + } // Compute a2, b2, c2 a2 = p4[1] - p3[1]; @@ -174,13 +179,15 @@ intersection_test intersect2dSeg2dSegParametric(const Vec2r &p1, // Check signs of r1 and r2. If both point 1 and point 2 lie on same side of second line // segment, the line segments do not intersect. - if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) + if (r1 != 0 && r2 != 0 && r1 * r2 > 0.0) { return (DONT_INTERSECT); + } // Line segments intersect: compute intersection point. denom = a1 * b2 - a2 * b1; - if (fabs(denom) < epsilon) + if (fabs(denom) < epsilon) { return (COLINEAR); + } real d1, e1; @@ -387,26 +394,30 @@ bool overlapTriangleBox(Vec3r &boxcenter, Vec3r &boxhalfsize, Vec3r triverts[3]) // test in X-direction FINDMINMAX(v0[X], v1[X], v2[X], min, max); - if (min > boxhalfsize[X] || max < -boxhalfsize[X]) + if (min > boxhalfsize[X] || max < -boxhalfsize[X]) { return false; + } // test in Y-direction FINDMINMAX(v0[Y], v1[Y], v2[Y], min, max); - if (min > boxhalfsize[Y] || max < -boxhalfsize[Y]) + if (min > boxhalfsize[Y] || max < -boxhalfsize[Y]) { return false; + } // test in Z-direction FINDMINMAX(v0[Z], v1[Z], v2[Z], min, max); - if (min > boxhalfsize[Z] || max < -boxhalfsize[Z]) + if (min > boxhalfsize[Z] || max < -boxhalfsize[Z]) { return false; + } // Bullet 2: // test if the box intersects the plane of the triangle // compute plane equation of triangle: normal * x + d = 0 normal = e0 ^ e1; d = -(normal * v0); // plane eq: normal.x + d = 0 - if (!overlapPlaneBox(normal, d, boxhalfsize)) + if (!overlapPlaneBox(normal, d, boxhalfsize)) { return false; + } return true; // box and triangle overlaps } @@ -453,24 +464,28 @@ bool intersectRayTriangle(const Vec3r &orig, if (det > epsilon) { u = tvec * pvec; - if (u < 0.0 || u > det) + if (u < 0.0 || u > det) { return false; + } // calculate V parameter and test bounds v = dir * qvec; - if (v < 0.0 || u + v > det) + if (v < 0.0 || u + v > det) { return false; + } } else if (det < -epsilon) { // calculate U parameter and test bounds u = tvec * pvec; - if (u > 0.0 || u < det) + if (u > 0.0 || u < det) { return false; + } // calculate V parameter and test bounds v = dir * qvec; - if (v > 0.0 || u + v < det) + if (v > 0.0 || u + v < det) { return false; + } } else { return false; // ray is parallell to the plane of the triangle @@ -496,16 +511,19 @@ intersection_test intersectRayPlane(const Vec3r &orig, real denom = norm * dir; if (fabs(denom) <= epsilon) { // plane and ray are parallel - if (fabs((norm * orig) + d) <= epsilon) + if (fabs((norm * orig) + d) <= epsilon) { return COINCIDENT; // plane and ray are coincident - else + } + else { return COLINEAR; + } } t = -(d + (norm * orig)) / denom; - if (t < 0.0f) + if (t < 0.0f) { return DONT_INTERSECT; + } return DO_INTERSECT; } @@ -535,20 +553,26 @@ bool intersectRayBBox(const Vec3r &orig, tmax = (bounds[1 - sign[0]].x() - orig.x()) * inv_direction.x(); tymin = (bounds[sign[1]].y() - orig.y()) * inv_direction.y(); tymax = (bounds[1 - sign[1]].y() - orig.y()) * inv_direction.y(); - if ((tmin > tymax) || (tymin > tmax)) + if ((tmin > tymax) || (tymin > tmax)) { return false; - if (tymin > tmin) + } + if (tymin > tmin) { tmin = tymin; - if (tymax < tmax) + } + if (tymax < tmax) { tmax = tymax; + } tzmin = (bounds[sign[2]].z() - orig.z()) * inv_direction.z(); tzmax = (bounds[1 - sign[2]].z() - orig.z()) * inv_direction.z(); - if ((tmin > tzmax) || (tzmin > tmax)) + if ((tmin > tzmax) || (tzmin > tmax)) { return false; - if (tzmin > tmin) + } + if (tzmin > tmin) { tmin = tzmin; - if (tzmax < tmax) + } + if (tzmax < tmax) { tmax = tzmax; + } return ((tmin < t1) && (tmax > t0)); } @@ -571,14 +595,17 @@ bool includePointTriangle(const Vec3r &P, const Vec3r &A, const Vec3r &B, const K.normalize(); L.normalize(); - if (J * N < 0) + if (J * N < 0) { return false; // on the right of AB + } - if (K * N < 0) + if (K * N < 0) { return false; // on the right of BC + } - if (L * N < 0) + if (L * N < 0) { return false; // on the right of CA + } return true; } @@ -589,8 +616,9 @@ void transformVertex(const Vec3r &vert, const Matrix44r &matrix, Vec3r &res) real scale; for (unsigned int j = 0; j < 4; j++) { scale = hvert[j]; - for (unsigned int i = 0; i < 4; i++) + for (unsigned int i = 0; i < 4; i++) { res_tmp[i] += matrix(i, j) * scale; + } } res[0] = res_tmp.x(); @@ -612,8 +640,9 @@ Vec3r rotateVector(const Matrix44r &mat, const Vec3r &v) Vec3r res; for (unsigned int i = 0; i < 3; i++) { res[i] = 0; - for (unsigned int j = 0; j < 3; j++) + for (unsigned int j = 0; j < 3; j++) { res[i] += mat(i, j) * v[j]; + } } res.normalize(); return res; @@ -698,8 +727,9 @@ void fromCameraToWorld(const Vec3r &p, Vec3r &q, const real model_view_matrix[4] }; for (unsigned short i = 0; i < 3; i++) { q[i] = 0.0; - for (unsigned short j = 0; j < 3; j++) + for (unsigned short j = 0; j < 3; j++) { q[i] += model_view_matrix[j][i] * (p[j] - translation[j]); + } } } @@ -718,8 +748,9 @@ void fromCameraToWorld(const Vec3r &p, Vec3r &q, const real model_view_matrix[4] inline bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, unsigned n) { - if (seg[0] == seg[1]) + if (seg[0] == seg[1]) { return false; + } real tE = 0; // the maximum entering segment parameter real tL = 1; // the minimum leaving segment parameter @@ -732,25 +763,29 @@ inline bool intersect2dSegPoly(Vec2r *seg, Vec2r *poly, unsigned n) N = PERP(e, seg[0] - poly[i]); D = -PERP(e, dseg); if (fabs(D) < M_EPSILON) { - if (N < 0) + if (N < 0) { return false; - else + } + else { continue; + } } t = N / D; if (D < 0) { // segment seg is entering across this edge if (t > tE) { // new max tE tE = t; - if (tE > tL) // seg enters after leaving polygon + if (tE > tL) { // seg enters after leaving polygon return false; + } } } else { // segment seg is leaving across this edge if (t < tL) { // new min tL tL = t; - if (tL < tE) // seg leaves before entering polygon + if (tL < tE) { // seg leaves before entering polygon return false; + } } } } @@ -773,10 +808,12 @@ inline bool overlapPlaneBox(Vec3r &normal, real d, Vec3r &maxbox) vmax[q] = -maxbox[q]; } } - if ((normal * vmin) + d > 0.0f) + if ((normal * vmin) + d > 0.0f) { return false; - if ((normal * vmax) + d >= 0.0f) + } + if ((normal * vmax) + d >= 0.0f) { return true; + } return false; } @@ -796,8 +833,9 @@ inline void fromCoordAToCoordB(const Vec3r &p, Vec3r &q, const real transform[4] return; } - for (unsigned int k = 0; k < 3; k++) + for (unsigned int k = 0; k < 3; k++) { q[k] = hq[k] / hq[3]; + } } } // end of namespace GeomUtils diff --git a/source/blender/freestyle/intern/geometry/GeomUtils.h b/source/blender/freestyle/intern/geometry/GeomUtils.h index c469f10cc49..635808aab4b 100644 --- a/source/blender/freestyle/intern/geometry/GeomUtils.h +++ b/source/blender/freestyle/intern/geometry/GeomUtils.h @@ -50,12 +50,14 @@ template real distPointSegment(const T &P, const T &A, const T &B) BP = P - B; real c1(AB * AP); - if (c1 <= 0) + if (c1 <= 0) { return AP.norm(); + } real c2(AB * AB); - if (c2 <= c1) + if (c2 <= c1) { return BP.norm(); + } real b = c1 / c2; T Pb, PPb; diff --git a/source/blender/freestyle/intern/geometry/Grid.cpp b/source/blender/freestyle/intern/geometry/Grid.cpp index aeb82d56009..4076bfe03df 100644 --- a/source/blender/freestyle/intern/geometry/Grid.cpp +++ b/source/blender/freestyle/intern/geometry/Grid.cpp @@ -83,8 +83,9 @@ void firstIntersectionGridVisitor::examineOccluder(Polygon3r *occ) bool firstIntersectionGridVisitor::stop() { - if (occluder_) + if (occluder_) { return true; + } return false; } @@ -139,20 +140,23 @@ void Grid::configure(const Vec3r &orig, const Vec3r &size, unsigned nb) // We compute the number of cells par edge such as we cover at least the whole box. unsigned i; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { _cells_nb[i] = (unsigned)floor(tmpSize[i] / edge) + 1; + } _size = tmpSize; - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { _cell_size[i] = _size[i] / _cells_nb[i]; + } } void Grid::insertOccluder(Polygon3r *occluder) { const vector vertices = occluder->getVertices(); - if (vertices.size() == 0) + if (vertices.size() == 0) { return; + } // add this occluder to the grid's occluders list addOccluder(occluder); @@ -244,12 +248,15 @@ bool Grid::nextRayCell(Vec3u ¤t_cell, Vec3u &next_cell) // coresponding to the intersections with the plans: // x = _cell_size[0], y = _cell_size[1], z = _cell_size[2] for (i = 0; i < 3; i++) { - if (_ray_dir[i] == 0) + if (_ray_dir[i] == 0) { continue; - if (_ray_dir[i] > 0) + } + if (_ray_dir[i] > 0) { t = (_cell_size[i] - _pt[i]) / _ray_dir[i]; - else + } + else { t = -_pt[i] / _ray_dir[i]; + } if (t < t_min) { t_min = t; coord = i; @@ -266,20 +273,23 @@ bool Grid::nextRayCell(Vec3u ¤t_cell, Vec3u &next_cell) next_cell[coord]++; _pt[coord] -= _cell_size[coord]; // if we are out of the grid, we must stop - if (next_cell[coord] >= _cells_nb[coord]) + if (next_cell[coord] >= _cells_nb[coord]) { return false; + } } else { int tmp = next_cell[coord] - 1; _pt[coord] = _cell_size[coord]; - if (tmp < 0) + if (tmp < 0) { return false; + } next_cell[coord]--; } _t += t_min; - if (_t >= _t_end) + if (_t >= _t_end) { return false; + } return true; } @@ -301,8 +311,9 @@ void Grid::castInfiniteRay(const Vec3r &orig, { Vec3r end = Vec3r(orig + FLT_MAX * dir / dir.norm()); bool inter = initInfiniteRay(orig, dir, timestamp); - if (!inter) + if (!inter) { return; + } allOccludersGridVisitor visitor(occluders); castRayInternal(visitor); } @@ -371,8 +382,9 @@ bool Grid::initInfiniteRay(const Vec3r &orig, const Vec3r &dir, unsigned timesta Vec3r newOrig = orig + tmin * _ray_dir; for (unsigned int i = 0; i < 3; i++) { _current_cell[i] = (unsigned)floor((newOrig[i] - _orig[i]) / _cell_size[i]); - if (_current_cell[i] == _cells_nb[i]) + if (_current_cell[i] == _cells_nb[i]) { _current_cell[i] = _cells_nb[i] - 1; + } // soc unused - unsigned u = _current_cell[i]; _pt[i] = newOrig[i] - _orig[i] - _current_cell[i] * _cell_size[i]; } diff --git a/source/blender/freestyle/intern/geometry/Grid.h b/source/blender/freestyle/intern/geometry/Grid.h index 67aae73a578..6090eeb122a 100644 --- a/source/blender/freestyle/intern/geometry/Grid.h +++ b/source/blender/freestyle/intern/geometry/Grid.h @@ -67,8 +67,9 @@ class Cell { inline void addOccluder(Polygon3r *o) { - if (o) + if (o) { _occluders.push_back(o); + } } inline const Vec3r &getOrigin() @@ -227,12 +228,15 @@ class Grid { int tmp; for (int i = 0; i < 3; i++) { tmp = (int)((p[i] - _orig[i]) / _cell_size[i]); - if (tmp < 0) + if (tmp < 0) { res[i] = 0; - else if ((unsigned int)tmp >= _cells_nb[i]) + } + else if ((unsigned int)tmp >= _cells_nb[i]) { res[i] = _cells_nb[i] - 1; - else + } + else { res[i] = tmp; + } } } @@ -263,8 +267,9 @@ class Grid { */ inline void getCellOrigin(const Vec3u &cell_coord, Vec3r &orig) { - for (unsigned int i = 0; i < 3; i++) + for (unsigned int i = 0; i < 3; i++) { orig[i] = _orig[i] + cell_coord[i] * _cell_size[i]; + } } /*! Retrieves the box corresponding to the cell whose coordinates are passed as argument: diff --git a/source/blender/freestyle/intern/geometry/HashGrid.h b/source/blender/freestyle/intern/geometry/HashGrid.h index b1fc4824b6f..73751d820ab 100644 --- a/source/blender/freestyle/intern/geometry/HashGrid.h +++ b/source/blender/freestyle/intern/geometry/HashGrid.h @@ -87,8 +87,9 @@ class HashGrid : public Grid { Cell *found_cell = NULL; GridHashTable::const_iterator found = _cells.find(p); - if (found != _cells.end()) + if (found != _cells.end()) { found_cell = (*found).second; + } return found_cell; } diff --git a/source/blender/freestyle/intern/geometry/Noise.cpp b/source/blender/freestyle/intern/geometry/Noise.cpp index 8b81660fd58..7c42c332370 100644 --- a/source/blender/freestyle/intern/geometry/Noise.cpp +++ b/source/blender/freestyle/intern/geometry/Noise.cpp @@ -245,12 +245,14 @@ Noise::Noise(long seed) p[i] = i; g1[i] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; - for (j = 0; j < 2; j++) + for (j = 0; j < 2; j++) { g2[i][j] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; + } normalize2(g2[i]); - for (j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { g3[i][j] = (float)((BLI_rng_get_int(rng) % (_NOISE_B + _NOISE_B)) - _NOISE_B) / _NOISE_B; + } normalize3(g3[i]); } @@ -264,11 +266,13 @@ Noise::Noise(long seed) p[_NOISE_B + i] = p[i]; g1[_NOISE_B + i] = g1[i]; - for (j = 0; j < 2; j++) + for (j = 0; j < 2; j++) { g2[_NOISE_B + i][j] = g2[i][j]; + } - for (j = 0; j < 3; j++) + for (j = 0; j < 3; j++) { g3[_NOISE_B + i][j] = g3[i][j]; + } } BLI_rng_free(rng); diff --git a/source/blender/freestyle/intern/geometry/Polygon.h b/source/blender/freestyle/intern/geometry/Polygon.h index 739f880443c..f0e1199d930 100644 --- a/source/blender/freestyle/intern/geometry/Polygon.h +++ b/source/blender/freestyle/intern/geometry/Polygon.h @@ -100,8 +100,9 @@ template class Polygon { inline Point getCenter() { Point result; - for (typename vector::iterator it = _vertices.begin(); it != _vertices.end(); it++) + for (typename vector::iterator it = _vertices.begin(); it != _vertices.end(); it++) { result += *it; + } result /= _vertices.size(); return result; } @@ -138,18 +139,21 @@ template class Polygon { ///////////////////////////////////////////////////////////////////////////// inline void computeBBox() { - if (_vertices.empty()) + if (_vertices.empty()) { return; + } _max = _vertices[0]; _min = _vertices[0]; for (typename vector::iterator it = _vertices.begin(); it != _vertices.end(); it++) { for (unsigned int i = 0; i < Point::dim(); i++) { - if ((*it)[i] > _max[i]) + if ((*it)[i] > _max[i]) { _max[i] = (*it)[i]; - if ((*it)[i] < _min[i]) + } + if ((*it)[i] < _min[i]) { _min[i] = (*it)[i]; + } } } } diff --git a/source/blender/freestyle/intern/geometry/VecMat.h b/source/blender/freestyle/intern/geometry/VecMat.h index b9cf604fed7..bb12e5b97f0 100644 --- a/source/blender/freestyle/intern/geometry/VecMat.h +++ b/source/blender/freestyle/intern/geometry/VecMat.h @@ -59,8 +59,9 @@ template class Vec { // constructors inline Vec() { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] = 0; + } } ~Vec() @@ -70,20 +71,23 @@ template class Vec { template explicit inline Vec(const U tab[N]) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] = (T)tab[i]; + } } template explicit inline Vec(const std::vector &tab) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] = (T)tab[i]; + } } template explicit inline Vec(const Vec &v) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] = (T)v[i]; + } } // accessors @@ -116,8 +120,9 @@ template class Vec { inline Vec &normalize() { value_type n = norm(); - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] /= n; + } return *this; } @@ -125,8 +130,9 @@ template class Vec { { value_type n = norm(); if (n) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] /= n; + } } return *this; } @@ -156,8 +162,9 @@ template class Vec { inline Vec operator/(const typename Vec::value_type r) const { Vec res(*this); - if (r) + if (r) { res /= r; + } return res; } @@ -165,46 +172,52 @@ template class Vec { inline value_type operator*(const Vec &v) const { value_type sum = 0; - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { sum += (*this)[i] * v[i]; + } return sum; } template inline Vec &operator=(const Vec &v) { if (this != &v) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] = (T)v[i]; + } } return *this; } template inline Vec &operator+=(const Vec &v) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] += (T)v[i]; + } return *this; } template inline Vec &operator-=(const Vec &v) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] -= (T)v[i]; + } return *this; } template inline Vec &operator*=(const U r) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] *= r; + } return *this; } template inline Vec &operator/=(const U r) { if (r) { - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { this->_coord[i] /= r; + } } return *this; } @@ -212,8 +225,9 @@ template class Vec { inline bool operator==(const Vec &v) const { for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] != v[i]) + if (this->_coord[i] != v[i]) { return false; + } } return true; } @@ -221,8 +235,9 @@ template class Vec { inline bool operator!=(const Vec &v) const { for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] != v[i]) + if (this->_coord[i] != v[i]) { return true; + } } return false; } @@ -230,12 +245,15 @@ template class Vec { inline bool operator<(const Vec &v) const { for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] < v[i]) + if (this->_coord[i] < v[i]) { return true; - if (this->_coord[i] > v[i]) + } + if (this->_coord[i] > v[i]) { return false; - if (this->_coord[i] == v[i]) + } + if (this->_coord[i] == v[i]) { continue; + } } return false; } @@ -243,12 +261,15 @@ template class Vec { inline bool operator>(const Vec &v) const { for (unsigned int i = 0; i < N; i++) { - if (this->_coord[i] > v[i]) + if (this->_coord[i] > v[i]) { return true; - if (this->_coord[i] < v[i]) + } + if (this->_coord[i] < v[i]) { return false; - if (this->_coord[i] == v[i]) + } + if (this->_coord[i] == v[i]) { continue; + } } return false; } @@ -351,8 +372,9 @@ template class Vec2 : public Vec { inline Vec2 operator/(const value_type r) const { Vec2 res(*this); - if (r) + if (r) { res /= r; + } return res; } @@ -360,8 +382,9 @@ template class Vec2 : public Vec { inline value_type operator*(const Vec2 &v) const { value_type sum = 0; - for (unsigned int i = 0; i < 2; i++) + for (unsigned int i = 0; i < 2; i++) { sum += (*this)[i] * v[i]; + } return sum; } }; @@ -578,8 +601,9 @@ template class Vec3 : public Vec { inline Vec3 operator/(const value_type r) const { Vec3 res(*this); - if (r) + if (r) { res /= r; + } return res; } @@ -587,8 +611,9 @@ template class Vec3 : public Vec { inline value_type operator*(const Vec3 &v) const { value_type sum = 0; - for (unsigned int i = 0; i < 3; i++) + for (unsigned int i = 0; i < 3; i++) { sum += (*this)[i] * v[i]; + } return sum; } @@ -629,8 +654,9 @@ template class Matrix { inline Matrix() { - for (unsigned int i = 0; i < _SIZE; i++) + for (unsigned int i = 0; i < _SIZE; i++) { this->_coord[i] = 0; + } } ~Matrix() @@ -641,21 +667,24 @@ template class Matrix { template explicit inline Matrix(const U tab[_SIZE]) { - for (unsigned int i = 0; i < _SIZE; i++) + for (unsigned int i = 0; i < _SIZE; i++) { this->_coord[i] = tab[i]; + } } template explicit inline Matrix(const std::vector &tab) { - for (unsigned int i = 0; i < _SIZE; i++) + for (unsigned int i = 0; i < _SIZE; i++) { this->_coord[i] = tab[i]; + } } template inline Matrix(const Matrix &m) { for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) + for (unsigned int j = 0; j < N; j++) { this->_coord[i * N + j] = (T)m(i, j); + } } } @@ -683,8 +712,9 @@ template class Matrix { { Matrix res; for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) + for (unsigned int j = 0; j < N; j++) { res(j, i) = this->_coord[i * N + j]; + } } *this = res; return *this; @@ -694,8 +724,9 @@ template class Matrix { { if (this != &m) { for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) + for (unsigned int j = 0; j < N; j++) { this->_coord[i * N + j] = (T)m(i, j); + } } } return *this; @@ -704,8 +735,9 @@ template class Matrix { template inline Matrix &operator+=(const Matrix &m) { for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) + for (unsigned int j = 0; j < N; j++) { this->_coord[i * N + j] += (T)m(i, j); + } } return *this; } @@ -713,8 +745,9 @@ template class Matrix { template inline Matrix &operator-=(const Matrix &m) { for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) + for (unsigned int j = 0; j < N; j++) { this->_coord[i * N + j] -= (T)m(i, j); + } } return *this; } @@ -722,8 +755,9 @@ template class Matrix { template inline Matrix &operator*=(const U lambda) { for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) + for (unsigned int j = 0; j < N; j++) { this->_coord[i * N + j] *= lambda; + } } return *this; } @@ -732,8 +766,9 @@ template class Matrix { { if (lambda) { for (unsigned int i = 0; i < M; i++) { - for (unsigned int j = 0; j < N; j++) + for (unsigned int j = 0; j < N; j++) { this->_coord[i * N + j] /= lambda; + } } } return *this; @@ -782,8 +817,9 @@ template class SquareMatrix : public Matrix { static inline SquareMatrix identity() { SquareMatrix res; - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { res(i, i) = 1; + } return res; } }; @@ -861,8 +897,9 @@ template inline std::ostream &operator<<(std::ostream &s, c { unsigned int i; s << "["; - for (i = 0; i < N - 1; i++) + for (i = 0; i < N - 1; i++) { s << v[i] << ", "; + } s << v[i] << "]"; return s; } @@ -925,8 +962,9 @@ inline Matrix operator*(const Matrix &m1, const Matrix operator*(const Matrix &m, const Vec &v) for (unsigned int j = 0; j < M; j++) { scale = v[j]; - for (unsigned int i = 0; i < N; i++) + for (unsigned int i = 0; i < N; i++) { res[i] += m(i, j) * scale; + } } return res; } @@ -953,8 +992,9 @@ inline std::ostream &operator<<(std::ostream &s, const Matrix &m) unsigned int i, j; for (i = 0; i < M; i++) { s << "["; - for (j = 0; j < N - 1; j++) + for (j = 0; j < N - 1; j++) { s << m(i, j) << ", "; + } s << m(i, j) << "]" << std::endl; } return s; -- cgit v1.2.3