diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-31 15:51:19 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-31 15:55:15 +0300 |
commit | d8dbd49a2f23b7637f05fc058f39bdf6ab706624 (patch) | |
tree | 0805b9372c82ae6505d87e879824efe1d3e32f8e /source/blender/freestyle/intern/stroke/Stroke.cpp | |
parent | 8987f7987d8160e1f6e79e8c85d6ce65b885ab25 (diff) |
Cleanup: style, use braces in source/
Automated using clang-tidy.
Diffstat (limited to 'source/blender/freestyle/intern/stroke/Stroke.cpp')
-rw-r--r-- | source/blender/freestyle/intern/stroke/Stroke.cpp | 117 |
1 files changed, 78 insertions, 39 deletions
diff --git a/source/blender/freestyle/intern/stroke/Stroke.cpp b/source/blender/freestyle/intern/stroke/Stroke.cpp index ff0cd64fdaa..13f8080552b 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.cpp +++ b/source/blender/freestyle/intern/stroke/Stroke.cpp @@ -43,8 +43,9 @@ StrokeAttribute::StrokeAttribute() _alpha = 1.0f; _thickness[0] = 1.0f; _thickness[1] = 1.0f; - for (i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) { _color[i] = 0.2f; + } _color[0] = 0.8f; _userAttributesReal = NULL; _userAttributesVec2f = NULL; @@ -57,21 +58,28 @@ StrokeAttribute::StrokeAttribute(const StrokeAttribute &iBrother) _alpha = iBrother._alpha; _thickness[0] = iBrother._thickness[0]; _thickness[1] = iBrother._thickness[1]; - for (int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { _color[i] = iBrother._color[i]; + } _visible = iBrother._visible; - if (iBrother._userAttributesReal) + if (iBrother._userAttributesReal) { _userAttributesReal = new realMap(*iBrother._userAttributesReal); - else + } + else { _userAttributesReal = NULL; - if (iBrother._userAttributesVec2f) + } + if (iBrother._userAttributesVec2f) { _userAttributesVec2f = new Vec2fMap(*iBrother._userAttributesVec2f); - else + } + else { _userAttributesVec2f = NULL; - if (iBrother._userAttributesVec3f) + } + if (iBrother._userAttributesVec3f) { _userAttributesVec3f = new Vec3fMap(*iBrother._userAttributesVec3f); - else + } + else { _userAttributesVec3f = NULL; + } } StrokeAttribute::StrokeAttribute(float iRColor, @@ -102,8 +110,9 @@ StrokeAttribute::StrokeAttribute(const StrokeAttribute &a1, const StrokeAttribut _alpha = (1 - t) * a1._alpha + t * a2._alpha; _thickness[0] = (1 - t) * a1._thickness[0] + t * a2._thickness[0]; _thickness[1] = (1 - t) * a1._thickness[1] + t * a2._thickness[1]; - for (int i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) { _color[i] = (1 - t) * a1._color[i] + t * a2._color[i]; + } _visible = a1.isVisible(); @@ -174,28 +183,32 @@ StrokeAttribute &StrokeAttribute::operator=(const StrokeAttribute &iBrother) _alpha = iBrother._alpha; _thickness[0] = iBrother._thickness[0]; _thickness[1] = iBrother._thickness[1]; - for (i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) { _color[i] = iBrother._color[i]; + } _visible = iBrother._visible; if (iBrother._userAttributesReal) { - if (!_userAttributesReal) + if (!_userAttributesReal) { _userAttributesReal = new realMap; + } _userAttributesReal = new realMap(*(iBrother._userAttributesReal)); } else { _userAttributesReal = NULL; } if (iBrother._userAttributesVec2f) { - if (!_userAttributesVec2f) + if (!_userAttributesVec2f) { _userAttributesVec2f = new Vec2fMap; + } _userAttributesVec2f = new Vec2fMap(*(iBrother._userAttributesVec2f)); } else { _userAttributesVec2f = NULL; } if (iBrother._userAttributesVec3f) { - if (!_userAttributesVec3f) + if (!_userAttributesVec3f) { _userAttributesVec3f = new Vec3fMap; + } _userAttributesVec3f = new Vec3fMap(*(iBrother._userAttributesVec3f)); } else { @@ -299,22 +312,25 @@ bool StrokeAttribute::isAttributeAvailableVec3f(const char *iName) const void StrokeAttribute::setAttributeReal(const char *iName, float att) { - if (!_userAttributesReal) + if (!_userAttributesReal) { _userAttributesReal = new realMap; + } (*_userAttributesReal)[iName] = att; } void StrokeAttribute::setAttributeVec2f(const char *iName, const Vec2f &att) { - if (!_userAttributesVec2f) + if (!_userAttributesVec2f) { _userAttributesVec2f = new Vec2fMap; + } (*_userAttributesVec2f)[iName] = att; } void StrokeAttribute::setAttributeVec3f(const char *iName, const Vec3f &att) { - if (!_userAttributesVec3f) + if (!_userAttributesVec3f) { _userAttributesVec3f = new Vec3fMap; + } (*_userAttributesVec3f)[iName] = att; } @@ -427,10 +443,12 @@ Stroke::Stroke(const Stroke &iBrother) } _nodeTree = iBrother._nodeTree; _tips = iBrother._tips; - if (iBrother._rep) + if (iBrother._rep) { _rep = new StrokeRep(*(iBrother._rep)); - else + } + else { _rep = NULL; + } } Stroke::~Stroke() @@ -452,8 +470,9 @@ Stroke::~Stroke() Stroke &Stroke::operator=(const Stroke &iBrother) { - if (!_Vertices.empty()) + if (!_Vertices.empty()) { _Vertices.clear(); + } for (vertex_container::const_iterator v = iBrother._Vertices.begin(), vend = iBrother._Vertices.end(); @@ -465,12 +484,15 @@ Stroke &Stroke::operator=(const Stroke &iBrother) _id = iBrother._id; _ViewEdges = iBrother._ViewEdges; _sampling = iBrother._sampling; - if (_rep) + if (_rep) { delete _rep; - if (iBrother._rep) + } + if (iBrother._rep) { _rep = new StrokeRep(*(iBrother._rep)); - else + } + else { _rep = NULL; + } return *this; } @@ -484,8 +506,9 @@ void Stroke::setLength(float iLength) float Stroke::ComputeSampling(int iNVertices) { - if (iNVertices <= (int)_Vertices.size()) // soc + if (iNVertices <= (int)_Vertices.size()) { // soc return _sampling; + } float sampling = _Length / (float)(iNVertices - _Vertices.size() + 1); return sampling; @@ -518,8 +541,9 @@ class StrokeSegment { int Stroke::Resample(int iNPoints) { int NPointsToAdd = iNPoints - strokeVerticesSize(); - if (NPointsToAdd <= 0) + if (NPointsToAdd <= 0) { return 0; + } StrokeInternal::StrokeVertexIterator it = strokeVerticesBegin(); StrokeInternal::StrokeVertexIterator next = it; @@ -557,23 +581,27 @@ int Stroke::Resample(int iNPoints) for (vector<StrokeSegment>::iterator s = strokeSegments.begin(), send = strokeSegments.end(); s != send; ++s) { - if (s->_sampling == 0.0f) + if (s->_sampling == 0.0f) { continue; + } if (s->_resampled == false) { - if ((!checkEveryone) && (s->_length < meanlength)) + if ((!checkEveryone) && (s->_length < meanlength)) { continue; + } // resample s->_n = s->_n + 1; s->_sampling = s->_length / (float)(s->_n + 1); s->_resampled = resampled = true; N++; - if (N == NPointsToAdd) + if (N == NPointsToAdd) { break; + } } } - if (checkEveryone && !resampled) + if (checkEveryone && !resampled) { break; + } checkEveryone = true; } if (N < NPointsToAdd) { @@ -586,8 +614,9 @@ int Stroke::Resample(int iNPoints) s != send; ++s) { newVertices.push_back(&(*(s->_begin))); - if (s->_sampling < _sampling) + if (s->_sampling < _sampling) { _sampling = s->_sampling; + } t = s->_sampling / s->_length; for (int i = 0; i < s->_n; ++i) { @@ -602,12 +631,14 @@ int Stroke::Resample(int iNPoints) // add last: ++it; ++next; - if ((it != itend) && (next == itend) /* && (t == 0.0f)*/) + if ((it != itend) && (next == itend) /* && (t == 0.0f)*/) { newVertices.push_back(&(*it)); + } int newsize = newVertices.size(); - if (newsize != iNPoints) + if (newsize != iNPoints) { cerr << "Warning: incorrect points number" << endl; + } _Vertices.clear(); _Vertices = newVertices; @@ -619,10 +650,12 @@ int Stroke::Resample(int iNPoints) int Stroke::Resample(float iSampling) { // cerr << "old size :" << strokeVerticesSize() << endl; - if (iSampling == 0) + if (iSampling == 0) { return 0; - if (iSampling >= _sampling) + } + if (iSampling >= _sampling) { return 0; + } _sampling = iSampling; // Resample... @@ -660,8 +693,9 @@ int Stroke::Resample(float iSampling) ++next; } // add last: - if ((it != itend) && (next == itend) /* && (t == 0.f)*/) + if ((it != itend) && (next == itend) /* && (t == 0.f)*/) { newVertices.push_back(&(*it)); + } _Vertices.clear(); _Vertices = newVertices; @@ -673,8 +707,9 @@ int Stroke::Resample(float iSampling) void Stroke::RemoveAllVertices() { vertex_container::iterator it = _Vertices.begin(), itend = _Vertices.end(); - for (; it != itend; ++it) + for (; it != itend; ++it) { delete (*it); + } _Vertices.clear(); UpdateLength(); } @@ -734,8 +769,9 @@ Stroke::vertex_iterator Stroke::vertices_end() StrokeInternal::StrokeVertexIterator Stroke::strokeVerticesBegin(float t) { - if ((t != 0) && (t < _sampling)) + if ((t != 0) && (t < _sampling)) { Resample(t); + } return StrokeInternal::StrokeVertexIterator( this->_Vertices.begin(), this->_Vertices.begin(), this->_Vertices.end()); } @@ -781,23 +817,26 @@ void Stroke::ScaleThickness(float iFactor) void Stroke::Render(const StrokeRenderer *iRenderer) { - if (!_rep) + if (!_rep) { _rep = new StrokeRep(this); + } iRenderer->RenderStrokeRep(_rep); } void Stroke::RenderBasic(const StrokeRenderer *iRenderer) { - if (!_rep) + if (!_rep) { _rep = new StrokeRep(this); + } iRenderer->RenderStrokeRep(_rep); } Stroke::vertex_iterator Stroke::vertices_begin(float sampling) { // Resample if necessary - if ((sampling != 0) && (sampling < _sampling)) + if ((sampling != 0) && (sampling < _sampling)) { Resample(sampling); + } return vertex_iterator(_Vertices.begin(), _Vertices.begin(), _Vertices.end()); // return _Vertices.begin(); } |