upload
This commit is contained in:
parent
4fdd776448
commit
347ad8d712
6 changed files with 155 additions and 41 deletions
43
.clang-format
Normal file
43
.clang-format
Normal file
|
@ -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: '<c(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)>'
|
||||||
|
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
|
43
.class-clang-format
Normal file
43
.class-clang-format
Normal file
|
@ -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: '<c(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)>'
|
||||||
|
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
|
21
Makefile
21
Makefile
|
@ -1,13 +1,13 @@
|
||||||
TARGET = L2C
|
TARGET = L2C
|
||||||
SRC_FILES = main.cpp coordinate_conversion.cpp
|
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"
|
.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
|
## 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)
|
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)
|
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
|
## 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
|
run: all
|
||||||
./$(TARGET)
|
./$(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
|
# NO EDITS NEEDED BELOW THIS LINE
|
||||||
|
|
||||||
CXX = g++
|
CXX = g++
|
||||||
|
|
|
@ -2,16 +2,16 @@
|
||||||
#define COORDINATE_CONVERSION_H
|
#define COORDINATE_CONVERSION_H
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
void polar_to_cartesian(const double RADIUS, const double ANGLE, double *pXCoordinate,
|
void polar_to_cartesian(const double RADIUS, const double ANGLE,
|
||||||
double *pYCoordinate) {
|
double* pXCoordinate, double* pYCoordinate) {
|
||||||
*pXCoordinate = RADIUS * std::cos(ANGLE);
|
*pXCoordinate = RADIUS * std::cos(ANGLE);
|
||||||
*pYCoordinate = RADIUS * std::sin(ANGLE);
|
*pYCoordinate = RADIUS * std::sin(ANGLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cartesian_to_polar(const double X_COORDINATE, const double Y_COORDINATE, double *pRadius,
|
void cartesian_to_polar(const double X_COORDINATE, const double Y_COORDINATE,
|
||||||
double *pAngle) {
|
double* pRadius, double* pAngle) {
|
||||||
*pRadius = std::sqrt(std::pow(X_COORDINATE, 2) + std::pow(Y_COORDINATE, 2));
|
*pRadius = std::sqrt(std::pow(X_COORDINATE, 2) + std::pow(Y_COORDINATE, 2));
|
||||||
*pAngle = std::atan(X_COORDINATE / Y_COORDINATE);
|
*pAngle = std::atan(X_COORDINATE / Y_COORDINATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // COORDINATE_CONVERSION_H
|
#endif // COORDINATE_CONVERSION_H
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
*
|
*
|
||||||
* @param RADIUS The radius of the polar coordinates
|
* @param RADIUS The radius of the polar coordinates
|
||||||
* @param ANGLE The angle 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 pXCoordinate A pointer referencing the variable to place the x
|
||||||
* @param pYCoordinate A pointer referencing the variable to place the y component of the cartesian coordinates into
|
* 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
|
* @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 X_COORDINATE The x component of the cartesian coordinates
|
||||||
* @param Y_COORDINATE The y 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 pRadius A pointer referencing the variable to put the radius of the
|
||||||
* @param pAngle A pointer referencing the variable to put the angle of the polar coordinates into
|
* 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
|
#endif // COORDINATE_CONVERSION_H
|
||||||
|
|
55
main.cpp
55
main.cpp
|
@ -9,35 +9,42 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(void) {
|
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::cout
|
||||||
std::cin >> direction;
|
<< "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 radius = 0;
|
||||||
double angle = 0;
|
double angle = 0;
|
||||||
double xCoordinate = 0;
|
double xCoordinate = 0;
|
||||||
double yCoordinate = 0;
|
double yCoordinate = 0;
|
||||||
|
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case 'P':
|
case 'P':
|
||||||
std::cout << "Please enter the (x, y) coordinates, separated by a space: ";
|
std::cout << "Please enter the (x, y) coordinates, separated by a "
|
||||||
std::cin >> xCoordinate >> yCoordinate;
|
"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 << ")";
|
std::cout << "The result (r, θ) is: (" << radius << ", " << angle << ")"
|
||||||
break;
|
<< std::endl;
|
||||||
case 'C':
|
break;
|
||||||
std::cout << "Please enter the (r, θ) coordinates, separated by a space: ";
|
case 'C':
|
||||||
std::cin >> radius >> angle;
|
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 << ")";
|
std::cout << "The result (x, y) is: (" << xCoordinate << ", "
|
||||||
break;
|
<< yCoordinate << ")" << std::endl;
|
||||||
default:
|
break;
|
||||||
std::cout << "\"" << direction << "\" is not a valid option, exiting";
|
default:
|
||||||
return 1;
|
std::cout << "\"" << direction << "\" is not a valid option, exiting"
|
||||||
}
|
<< std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue