diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f9412e2 --- /dev/null +++ b/.clang-format @@ -0,0 +1,43 @@ +# Tyler's personal code-style formatting file, make sure to use the class version before turning in +IndentWidth: 4 +UseTab: Always +TabWidth: 4 +InsertBraces: false +SortIncludes: true +IncludeBlocks: Regroup +IncludeCategories: + # System headers from C (hardcoded, it isn't really possible to automatically detect them with regex) + - Regex: '' + Priority: 3 + # System headers without extension. + - Regex: '<([A-Za-z0-9\Q/-_\E])+>' + Priority: 2 + # Local headers with extension. + - Regex: '"([A-Za-z0-9\Q/-_\E])+\.h(pp)?"' + Priority: 1 +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +IndentCaseLabels: true +IntegerLiteralSeparator: + Binary: 0 + Decimal: 3 + Hex: -1 +DerivePointerAlignment: false +PointerAlignment: Right +QualifierAlignment: Left \ No newline at end of file diff --git a/.class-clang-format b/.class-clang-format new file mode 100644 index 0000000..c1015e1 --- /dev/null +++ b/.class-clang-format @@ -0,0 +1,43 @@ +# A clang-format config to follow CSCI200's style guide, use before turning in +IndentWidth: 2 +UseTab: Never +TabWidth: 2 +InsertBraces: true +SortIncludes: true +IncludeBlocks: Regroup +IncludeCategories: + # System headers from C + - Regex: '' + Priority: 3 + # System headers without extension. + - Regex: '<([A-Za-z0-9\Q/-_\E])+>' + Priority: 2 + # Local headers with extension. + - Regex: '"([A-Za-z0-9\Q/-_\E])+\.h(pp)?"' + Priority: 1 +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +IndentCaseLabels: true +IntegerLiteralSeparator: + Binary: -1 + Decimal: -1 + Hex: -1 +DerivePointerAlignment: false +PointerAlignment: Left +QualifierAlignment: Left \ No newline at end of file diff --git a/Makefile b/Makefile index 33455c6..6be1f14 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ TARGET = L2C SRC_FILES = main.cpp coordinate_conversion.cpp -# Tyler's custom makefile extensions +# Tyler's custom makefile extensions for CSCI200 (anyone can use these if they want) .DEFAULT_GOAL := all # Necessary so `make` doesn't run the "pack" target, as it is declared before "all" -.PHONY: pack clean-run c run +.PHONY: pack clean-run c run fmt ## Adds only the necessary files for build into a .tar.gz file, named appropriately ARCHIVED_FILES = Makefile $(SRC_FILES) $(SRC_FILES:.cpp=.h) $(SRC_FILES:.cpp=.hpp) -pack: +pack: fmtc tar --ignore-failed-read -czvf $(TARGET).tar.gz $(shell echo $(ARCHIVED_FILES) | xargs ls -d 2>/dev/null) ## Runs the pack target and then attempts to build & run the program to make sure it functions correctly @@ -26,6 +26,21 @@ c: clean run: all ./$(TARGET) +## Formats all cpp, h, and hpp files with clang-format, using my personal clang-format config +fmt: + find . -iname '*.hpp' -o -iname '*.h' -o -iname '*.cpp' | xargs clang-format --style=file:.clang-format -i + +## Formats all cpp, h, and hpp files with clang-format, using the class clang-format config +fmtc: + find . -iname '*.hpp' -o -iname '*.h' -o -iname '*.cpp' | xargs clang-format --style=file:.class-clang-format -i + +## Modifies the SRC_FILES variable to have all .cpp files in the repo +setupsrc: + sed -i "0,/SRC_FILE.\{0\}S = .*/ s//SRC_FILES = $(shell find . -iname '*.cpp' -printf '%P\n')/" Makefile + +## Alias to setup SRC_FILES and then dependencies +setup: setupsrc depend + # NO EDITS NEEDED BELOW THIS LINE CXX = g++ diff --git a/coordinate_conversion.cpp b/coordinate_conversion.cpp index 38c4213..1995240 100644 --- a/coordinate_conversion.cpp +++ b/coordinate_conversion.cpp @@ -2,16 +2,16 @@ #define COORDINATE_CONVERSION_H #include -void polar_to_cartesian(const double RADIUS, const double ANGLE, double *pXCoordinate, - double *pYCoordinate) { - *pXCoordinate = RADIUS * std::cos(ANGLE); - *pYCoordinate = RADIUS * std::sin(ANGLE); +void polar_to_cartesian(const double RADIUS, const double ANGLE, + double* pXCoordinate, double* pYCoordinate) { + *pXCoordinate = RADIUS * std::cos(ANGLE); + *pYCoordinate = RADIUS * std::sin(ANGLE); } -void cartesian_to_polar(const double X_COORDINATE, const double Y_COORDINATE, double *pRadius, - double *pAngle) { - *pRadius = std::sqrt(std::pow(X_COORDINATE, 2) + std::pow(Y_COORDINATE, 2)); - *pAngle = std::atan(X_COORDINATE / Y_COORDINATE); +void cartesian_to_polar(const double X_COORDINATE, const double Y_COORDINATE, + double* pRadius, double* pAngle) { + *pRadius = std::sqrt(std::pow(X_COORDINATE, 2) + std::pow(Y_COORDINATE, 2)); + *pAngle = std::atan(X_COORDINATE / Y_COORDINATE); } #endif // COORDINATE_CONVERSION_H diff --git a/coordinate_conversion.h b/coordinate_conversion.h index c9c195b..d16dc80 100644 --- a/coordinate_conversion.h +++ b/coordinate_conversion.h @@ -7,10 +7,13 @@ * * @param RADIUS The radius of the polar coordinates * @param ANGLE The angle of the polar coordinates - * @param pXCoordinate A pointer referencing the variable to place the x component of the cartesian coordinates into - * @param pYCoordinate A pointer referencing the variable to place the y component of the cartesian coordinates into + * @param pXCoordinate A pointer referencing the variable to place the x + * component of the cartesian coordinates into + * @param pYCoordinate A pointer referencing the variable to place the y + * component of the cartesian coordinates into */ -void polar_to_cartesian(const double RADIUS, const double ANGLE, double* pXCoordinate, double* pYCoordinate); +void polar_to_cartesian(const double RADIUS, const double ANGLE, + double* pXCoordinate, double* pYCoordinate); /** * @brief Converts passed cartesian coordinates to their polar equivalent, using @@ -18,9 +21,12 @@ void polar_to_cartesian(const double RADIUS, const double ANGLE, double* pXCoord * * @param X_COORDINATE The x component of the cartesian coordinates * @param Y_COORDINATE The y component of the cartesian coordinates - * @param pRadius A pointer referencing the variable to put the radius of the polar coordinates into - * @param pAngle A pointer referencing the variable to put the angle of the polar coordinates into + * @param pRadius A pointer referencing the variable to put the radius of the + * polar coordinates into + * @param pAngle A pointer referencing the variable to put the angle of the + * polar coordinates into */ -void cartesian_to_polar(const double X_COORDINATE, const double Y_COORDINATE, double* pRadius, double* pAngle); +void cartesian_to_polar(const double X_COORDINATE, const double Y_COORDINATE, + double* pRadius, double* pAngle); #endif // COORDINATE_CONVERSION_H diff --git a/main.cpp b/main.cpp index 437b496..5ec43db 100644 --- a/main.cpp +++ b/main.cpp @@ -9,35 +9,42 @@ #include int main(void) { - char direction = 'P'; + char direction = 'P'; - std::cout << "Which coordinate system would you like to convert to? [P]olar - (x, y) -> (r, θ), or [C]artesian - (r, θ) -> (x, y)? "; - std::cin >> direction; + std::cout + << "Which coordinate system would you like to convert to? [P]olar - " + "(x, y) -> (r, θ), or [C]artesian - (r, θ) -> (x, y)? "; + std::cin >> direction; - double radius = 0; - double angle = 0; - double xCoordinate = 0; - double yCoordinate = 0; + double radius = 0; + double angle = 0; + double xCoordinate = 0; + double yCoordinate = 0; - switch (direction) { - case 'P': - std::cout << "Please enter the (x, y) coordinates, separated by a space: "; - std::cin >> xCoordinate >> yCoordinate; + switch (direction) { + case 'P': + std::cout << "Please enter the (x, y) coordinates, separated by a " + "space: "; + std::cin >> xCoordinate >> yCoordinate; - cartesian_to_polar(xCoordinate, yCoordinate, &radius, &angle); + cartesian_to_polar(xCoordinate, yCoordinate, &radius, &angle); - std::cout << "The result (r, θ) is: (" << radius << ", " << angle << ")"; - break; - case 'C': - std::cout << "Please enter the (r, θ) coordinates, separated by a space: "; - std::cin >> radius >> angle; + std::cout << "The result (r, θ) is: (" << radius << ", " << angle << ")" + << std::endl; + break; + case 'C': + std::cout << "Please enter the (r, θ) coordinates, separated by a " + "space: "; + std::cin >> radius >> angle; - polar_to_cartesian(radius, angle, &xCoordinate, &yCoordinate); + polar_to_cartesian(radius, angle, &xCoordinate, &yCoordinate); - std::cout << "The result (x, y) is: (" << xCoordinate << ", " << yCoordinate << ")"; - break; - default: - std::cout << "\"" << direction << "\" is not a valid option, exiting"; - return 1; - } + std::cout << "The result (x, y) is: (" << xCoordinate << ", " + << yCoordinate << ")" << std::endl; + break; + default: + std::cout << "\"" << direction << "\" is not a valid option, exiting" + << std::endl; + return 1; + } } \ No newline at end of file