#include <swiss_gd_knife/math/geom/compass.hpp>
// std::ostream and std::cout #include <iostream> // sgdk::ZeroDirection, sgdk::PositiveRotation, and sgdk::Compass #include <swiss_gd_knife/math/geom/compass.hpp> typedef sgdk::Compass<> SampleCompass; /* * Outputs the compass.getDirection() call's parameters and its result. */ void coutDirection( const SampleCompass& compass , const double dx , const double dy ) { std::cout << "<" << dx << ", " << dy << "> = "; std::cout << compass.getDirection(dx, dy) << std::endl; } /* * Runs the specified example's invocations of the getDirection() * function of the specified Compass with its current zero-direction, * positive-rotation, and direction-count settings. */ void sample(const SampleCompass& compass, const unsigned int trial) { std::cout << "Number of directions = "; std::cout << compass.getDirectionCount() << std::endl; switch (trial) { case 1: coutDirection(compass, 0, 1); coutDirection(compass, 1, 0); coutDirection(compass, 0, -1); coutDirection(compass, -1, 0); coutDirection(compass, 1, 2); coutDirection(compass, 2, 1); coutDirection(compass, 2, -1); coutDirection(compass, 1, -2); coutDirection(compass, -1, -2); coutDirection(compass, -2, -1); coutDirection(compass, -2, 1); coutDirection(compass, -1, 2); break; case 2: coutDirection(compass, 1, 5); coutDirection(compass, 3, 4); coutDirection(compass, 5, 1); coutDirection(compass, 5, -1); coutDirection(compass, 3, -4); coutDirection(compass, 1, -5); coutDirection(compass, -1, -5); coutDirection(compass, -3, -4); coutDirection(compass, -5, -1); coutDirection(compass, -5, 1); coutDirection(compass, -3, 4); coutDirection(compass, -1, 5); break; case 3: coutDirection(compass, 0, 1); coutDirection(compass, 1, 1); coutDirection(compass, 1, 0); coutDirection(compass, 1, -1); coutDirection(compass, 0, -1); coutDirection(compass, -1, -1); coutDirection(compass, -1, 0); coutDirection(compass, -1, 1); break; default: coutDirection(compass, 0, 2); coutDirection(compass, 1, 2); coutDirection(compass, 2, 2); coutDirection(compass, 2, 1); coutDirection(compass, 2, 0); coutDirection(compass, 2, -1); coutDirection(compass, 2, -2); coutDirection(compass, 1, -2); coutDirection(compass, 0, -2); coutDirection(compass, -1, -2); coutDirection(compass, -2, -2); coutDirection(compass, -2, -1); coutDirection(compass, -2, 0); coutDirection(compass, -2, 1); coutDirection(compass, -2, 2); coutDirection(compass, -1, 2); break; } std::cout << std::endl; } /* * Runs the examples on the specified Compass with its current zero-direction * and positive-rotation settings. Groups the output directions by direction * count. */ void sample(SampleCompass& compass) { // Basic cases. compass.setDirectionCount(4); sample(compass, 1); compass.setDirectionCount(5); sample(compass, 2); compass.setDirectionCount(8); sample(compass, 3); compass.setDirectionCount(10); sample(compass, 2); compass.setDirectionCount(16); sample(compass, 0); // Degenerate cases. compass.setDirectionCount(1); sample(compass, 1); compass.setDirectionCount(2); sample(compass, 1); compass.setDirectionCount(3); sample(compass, 0); // See how a "real-world" compass works. compass.setDirectionCount(360); sample(compass, 0); // Unreal Tournament angles. compass.setDirectionCount(65536); sample(compass, 0); } /* * Runs the examples. */ int main() { std::cout << "ZeroDirection = Y, PositiveRotation = CW" << std::endl; SampleCompass compass( 4 , sgdk::ZeroDirection::POSITIVE_Y_AXIS , sgdk::PositiveRotation::CLOCKWISE ); sample(compass); std::cout << "ZeroDirection = Y, PositiveRotation = CCW" << std::endl; compass.setPositiveRotation(sgdk::PositiveRotation::COUNTERCLOCKWISE); sample(compass); std::cout << "ZeroDirection = -Y, PositiveRotation = CW" << std::endl; compass.setZeroDirection(sgdk::ZeroDirection::NEGATIVE_Y_AXIS); compass.setPositiveRotation(sgdk::PositiveRotation::CLOCKWISE); sample(compass); std::cout << "ZeroDirection = -Y, PositiveRotation = CCW" << std::endl; compass.setPositiveRotation(sgdk::PositiveRotation::COUNTERCLOCKWISE); sample(compass); std::cout << "ZeroDirection = X, PositiveRotation = CW" << std::endl; compass.setZeroDirection(sgdk::ZeroDirection::POSITIVE_X_AXIS); compass.setPositiveRotation(sgdk::PositiveRotation::CLOCKWISE); sample(compass); std::cout << "ZeroDirection = X, PositiveRotation = CCW" << std::endl; compass.setPositiveRotation(sgdk::PositiveRotation::COUNTERCLOCKWISE); sample(compass); std::cout << "ZeroDirection = -X, PositiveRotation = CW" << std::endl; compass.setZeroDirection(sgdk::ZeroDirection::NEGATIVE_X_AXIS); compass.setPositiveRotation(sgdk::PositiveRotation::CLOCKWISE); sample(compass); std::cout << "ZeroDirection = -X, PositiveRotation = CCW" << std::endl; compass.setPositiveRotation(sgdk::PositiveRotation::COUNTERCLOCKWISE); sample(compass); return 0; }
Parameter | Description | Default |
---|---|---|
Direction | The return type of getDirection() . | unsigned int |
DirectionChange | The return type of getDirectionChange() . | int |
PiConstant | The type of the function object returning the constant value PI. | Pi |
TangentFunction | The type of the function object returning the tangent of an angle. | Tangent |
Direction
must be an unsigned integral type. DirectionChange
must be a signed integral type. PiConstant
must be a nullary function object. TangentFunction
must model the Adaptable Unary Function and Default Constructible concepts. PiConstant::value_type
must be convertible to TangentFunction::argument_type
.
Public Types | |
typedef implementation_defined | RealNumber |
Public Member Functions | |
Compass (const Direction direction_count=4, const ZeroDirection &zero_direction=ZeroDirection::POSITIVE_Y_AXIS, const PositiveRotation &positive_rotation=PositiveRotation::CLOCKWISE, const RealNumber zero_tolerance=0.00001f) | |
The default constructor. | |
Compass (const Compass ©) | |
The copy constructor. | |
Compass & | operator= (const Compass ©) |
The assignment operator. | |
Direction | getDirectionCount () const |
Direction | getDirection (const RealNumber dx, const RealNumber dy) const |
DirectionChange | getDirectionChange (const RealNumber dx1, const RealNumber dy1, const RealNumber dx2, const RealNumber dy2) const |
void | setDirectionCount (const Direction direction_count) |
void | setZeroDirection (const ZeroDirection &zero_direction) |
void | setPositiveRotation (const PositiveRotation &positive_rotation) |
|
The type of the arguments for |
|
Constructs a new
|
|
Constructs a new
|
|
Sets this
|
|
Returns the number of possible rotation outputs for this
|
|
The direction-finding function. Returns zero if exactly one of the following conditions holds:
Returns
Returns a value between zero and
Returns a value between
|
|
Returns the change in direction between
|
|
Sets the number of possible rotation outputs.
|
|
Sets the zero-degree direction for this
|
|
Sets the positive rotational direction for this
|
Swiss GD Knife is hosted by .