Show rotation.cpp syntax highlighted
/***************************************************************************
rotation.cpp - description
-------------------
begin : Fri Sep 6 2002
copyright : (C) 2002 by Brendon Higgins
email : freepop-devel@lists.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <rotation.h>
const Rotation Rotation::CLOCKWISE(1);
const Rotation Rotation::ANTICLOCKWISE(3);
Rotation::Rotation() {
n = 0;
}
Rotation::Rotation(int r) {
n = r;
}
Rotation::Rotation(const Rotation& r) {
n = r.n;
}
void Rotation::setClock(int r) {
// Works for both positive and negative numbers!
n = r & 3;
}
int Rotation::getClock() const {
return n;
}
void Rotation::setAnti(int r) {
setClock(-r);
}
int Rotation::getAnti() const {
// We & 3 so that if n == 0, return != 4
return (4 - n) & 3;
}
Rotation& Rotation::incClock() {
setClock(n + 1);
return *this;
}
Rotation& Rotation::decClock() {
setClock(n - 1);
return *this;
}
Rotation& Rotation::incAnti() {
setClock(n - 1);
return *this;
}
Rotation& Rotation::decAnti() {
setClock(n + 1);
return *this;
}
Rotation& Rotation::operator+=(const Rotation& r) {
setClock(n + r.n);
return *this;
}
Rotation Rotation::operator-() const {
return Rotation((4 - n) & 3);
}
See more files for this project here