From 477697c6843b3a3ff95003d1f85bf8d440a7eea5 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sun, 13 Aug 2017 20:28:42 +0100 Subject: Improving style and continuing work on version headers --- .clang-format | 8 ++--- include/YAGE/spritebatch.hpp | 5 +-- scripts/add_version_headers | 39 +++++++++++--------- test/matrixtest.cpp | 84 ++++++++++++++++++++------------------------ 4 files changed, 66 insertions(+), 70 deletions(-) diff --git a/.clang-format b/.clang-format index 3bf5128c..47342b07 100644 --- a/.clang-format +++ b/.clang-format @@ -45,7 +45,7 @@ ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true DerivePointerAlignment: false -DisableFormat: false +DisableFormat: false ExperimentalAutoDetectBinPacking: false ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] IncludeCategories: @@ -57,7 +57,7 @@ IncludeCategories: Priority: 3 IncludeIsMainRegex: '([-_](test|unittest))?$' IndentCaseLabels: true -IndentWidth: 4 +IndentWidth: 4 IndentWrappedFunctionNames: false KeepEmptyLinesAtTheStartOfBlocks: false MacroBlockBegin: '' @@ -79,10 +79,10 @@ SortIncludes: true SpaceAfterCStyleCast: false SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements +SpaceBeforeParens: false SpaceInEmptyParentheses: false SpacesBeforeTrailingComments: 2 -SpacesInAngles: false +SpacesInAngles: false SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false diff --git a/include/YAGE/spritebatch.hpp b/include/YAGE/spritebatch.hpp index 1b1c8bb8..d47672ef 100644 --- a/include/YAGE/spritebatch.hpp +++ b/include/YAGE/spritebatch.hpp @@ -23,7 +23,6 @@ class SpriteBatch; /** Glyph with information of the texture. */ class Glyph { - // member variables private: GLuint texture_; float depth_; @@ -32,7 +31,6 @@ private: Vertex bottom_right_; Vertex bottom_left_; - // member functions public: Glyph(GLuint texture, float depth, const Vertex& top_left, const Vertex& top_right, const Vertex& bottom_right, @@ -72,7 +70,6 @@ private: std::vector glyph_ptrs_; std::vector render_batches_; - // member functions public: SpriteBatch(); SpriteBatch(const SpriteBatch&) = delete; @@ -98,6 +95,6 @@ private: void sortGlyphs(); }; -} // yage +} // namespace yage #endif diff --git a/scripts/add_version_headers b/scripts/add_version_headers index d41f5a08..def7d55a 100755 --- a/scripts/add_version_headers +++ b/scripts/add_version_headers @@ -48,26 +48,21 @@ class HeaderUpdate(object): self.exclude_build = True self.exclude_dir = ".*build.*" self.match_dir = "" + self.comment_match = "^\/[*] -+" + self.starting_dir = os.getcwd() for key, value in kwargs.items(): setattr(self, key, value) def writeHeader(self): - for subdir, dirs, files in os.walk(os.getcwd()): - if (not re.match(self.exclude_dir, subdir)) and \ - (re.match(self.match_dir, subdir)): - for file_ in files: - if (re.match(self.match_re, file_)) and \ - (not re.match(self.exclude_re, file_)): - with open(os.path.join(subdir, file_), 'r') \ - as src_file: - src = src_file.read() - if not re.match("^\/[*] -+", src): - print(os.path.join(subdir, file_), end=" ") - with open(os.path.join(subdir, file_), - 'w') as src_file_lic: - src_file_lic.write(header.format(file_)) - src_file_lic.write(src) - print("-- done") + def writeFileOperation(filePath, src): + if not re.match(self.comment_match, src): + print(filePath, end=" ") + with open(filePath, 'w') as src_file_lic: + src_file_lic.write(header.format(filePath)) + src_file_lic.write(src) + print("-- done") + + self._traverseDir(self.starting_dir, writeFileOperation) def updateHeader(self): ... @@ -75,6 +70,18 @@ class HeaderUpdate(object): def removeHeader(self): ... + def _traverseDir(self, path, fileOperation): + for subdir, dirs, files in os.walk(os.getcwd()): + if (not re.match(self.exclude_dir, subdir)) and \ + (re.match(self.match_dir, subdir)): + for fileName in files: + if (re.match(self.match_re, fileName)) and \ + (not re.match(self.exclude_re, fileName)): + with open(os.path.join(subdir, fileName), 'r') \ + as src_file: + src = src_file.read() + fileOperation(os.path.join(subdir, fileName), src) + def main(argv): update = HeaderUpdate(exclude_re="^picopng[.]cpp", diff --git a/test/matrixtest.cpp b/test/matrixtest.cpp index ee568067..1b27b544 100644 --- a/test/matrixtest.cpp +++ b/test/matrixtest.cpp @@ -15,70 +15,62 @@ #include "gtest/gtest.h" -template int matrixAssign(int number, int i, int j) -{ - yage::Matrix m; - m[j][i]=number; +template +int matrixAssign(int number, int i, int j) { + yage::Matrix m; + m[j][i] = number; - return m[j][i]; + return m[j][i]; } -template int matrixAddition(int num1, int num2) -{ - yage::Matrix m1, m2; - m1[1][1]=num1; - m2[1][1]=num2; +template +int matrixAddition(int num1, int num2) { + yage::Matrix m1, m2; + m1[1][1] = num1; + m2[1][1] = num2; - yage::Matrix m3 = m1+m2; + yage::Matrix m3 = m1 + m2; - return m3[1][1]; + return m3[1][1]; } -int vectorDotProduct(const std::vector &vec_contents_f, const std::vector &vec_contents_s) -{ - yage::Vector<3, int> v1(vec_contents_f); - yage::Vector<3, int> v2(vec_contents_s); +int vectorDotProduct(const std::vector& vec_contents_f, + const std::vector& vec_contents_s) { + yage::Vector<3, int> v1(vec_contents_f); + yage::Vector<3, int> v2(vec_contents_s); - int x = yage::matrix::dot(v1, v2); + int x = yage::matrix::dot(v1, v2); - return x; + return x; } -bool matrixMultiplication() -{ - return false; -} +bool matrixMultiplication() { return false; } // TESTS -TEST(Matrix, Assign) -{ - int rand_num = rand(); - ASSERT_EQ(rand_num, matrixAssign<10>(rand_num, 4, 2)); +TEST(Matrix, Assign) { + int rand_num = rand(); + ASSERT_EQ(rand_num, matrixAssign<10>(rand_num, 4, 2)); } -TEST(Matrix, Addition) -{ - int rand_x = rand(); - int rand_y = rand(); - ASSERT_EQ(rand_x+rand_y, matrixAddition<10>(rand_x, rand_y)); +TEST(Matrix, Addition) { + int rand_x = rand(); + int rand_y = rand(); + ASSERT_EQ(rand_x + rand_y, matrixAddition<10>(rand_x, rand_y)); } -TEST(Vector, DotProduct) -{ - std::vector contents_i = { rand()%100, rand()%100, rand()%100 }; - std::vector contents_j = { rand()%100, rand()%100, rand()%100 }; - int sum = 0; - for(std::size_t i = 0; i < contents_i.size(); ++i) - { - sum += contents_i[i]*contents_j[i]; - } - ASSERT_EQ(sum, vectorDotProduct(contents_i, contents_j)); +TEST(Vector, DotProduct) { + std::vector contents_i = {rand() % 100, rand() % 100, rand() % 100}; + std::vector contents_j = {rand() % 100, rand() % 100, rand() % 100}; + int sum = 0; + for(std::size_t i = 0; i < contents_i.size(); ++i) { + sum += contents_i[i] * contents_j[i]; + } + ASSERT_EQ(sum, vectorDotProduct(contents_i, contents_j)); } -int main(int argc, char **argv) -{ - srand(static_cast(time(nullptr))); - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char** argv) { + srand(static_cast(time(nullptr))); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } -- cgit