surface code audit

This commit is contained in:
James Turk 2005-03-03 09:25:19 +00:00
parent 299e873c76
commit 9cf19f475c
18 changed files with 161 additions and 75 deletions

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Circle.hpp,v 1.1 2005/02/27 09:00:13 cozman Exp $ // $Id: Circle.hpp,v 1.2 2005/03/03 09:25:19 cozman Exp $
#ifndef PHOTON_MATH_CIRCLE_HPP #ifndef PHOTON_MATH_CIRCLE_HPP
#define PHOTON_MATH_CIRCLE_HPP #define PHOTON_MATH_CIRCLE_HPP
@ -22,7 +22,8 @@ class Rect;
// Class: Circle // Class: Circle
// Defines geometric entity known as a circle. // Defines geometric entity known as a circle.
// //
// A plane curve everywhere equidistant from a given fixed point, the center. <http://dictionary.com> // A plane curve everywhere equidistant from a given fixed point, the center.
// <http://dictionary.com>
// //
// Operators: // Operators:
// - Circle == Circle // - Circle == Circle
@ -115,12 +116,26 @@ public:
// Group: Accessors // Group: Accessors
public: public:
// Function: getCenter // Function: getCenter
// Get center coordinate. // Get center <Point2>.
// //
// Returns: // Returns:
// Center coordinate. // Center point.
Point2 getCenter() const; Point2 getCenter() const;
// Function: getCenterX
// Get center x coordinate.
//
// Returns:
// Center x coordinate.
scalar getCenterX() const;
// Function: getCenterY
// Get center y coordinate.
//
// Returns:
// Center y coordinate.
scalar getCenterY() const;
// Function: getRadius // Function: getRadius
// Get radius of Circle. // Get radius of Circle.
// //

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Rect.hpp,v 1.1 2005/02/27 09:00:13 cozman Exp $ // $Id: Rect.hpp,v 1.2 2005/03/03 09:25:19 cozman Exp $
#ifndef PHOTON_MATH_RECT_HPP #ifndef PHOTON_MATH_RECT_HPP
#define PHOTON_MATH_RECT_HPP #define PHOTON_MATH_RECT_HPP
@ -17,10 +17,12 @@ namespace photon
namespace math namespace math
{ {
class Circle;
// Class: Rect // Class: Rect
// Defines geometric entity known as a rectangle. // Defines geometric entity known as a rectangle.
// //
// A four-sided plane figure with four right angles. <http://dictionary.com> // A four-sided plane figure with four right angles. <http://dictionary.com>
// //
// Operators: // Operators:
// - Rect == Rect // - Rect == Rect
@ -105,6 +107,16 @@ public:
// True if Rect intersects rect, false otherwise. // True if Rect intersects rect, false otherwise.
bool intersects(const Rect &rect) const; bool intersects(const Rect &rect) const;
// Function: intersects
// Check for intersection between the <Rect> and <Circle>.
//
// Parameters:
// circle - <Circle> with which to check for intersection.
//
// Returns:
// True if Rect intersects circle, false otherwise.
bool intersects(const Circle &circle) const;
// Function: contains // Function: contains
// Check if a point is contained within the Rect. // Check if a point is contained within the Rect.
// //

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Vector2.hpp,v 1.2 2005/03/01 07:51:23 cozman Exp $ // $Id: Vector2.hpp,v 1.3 2005/03/03 09:25:19 cozman Exp $
#ifndef PHOTON_MATH_VECTOR2_HPP #ifndef PHOTON_MATH_VECTOR2_HPP
#define PHOTON_MATH_VECTOR2_HPP #define PHOTON_MATH_VECTOR2_HPP
@ -158,7 +158,6 @@ public:
// Angle of vector (in degrees). // Angle of vector (in degrees).
scalar getAngleDeg() const; scalar getAngleDeg() const;
// Function: getAngleRad // Function: getAngleRad
// Angle of vector in radians, angle is calculated with respect to positive // Angle of vector in radians, angle is calculated with respect to positive
// X axis. // X axis.

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: math.hpp,v 1.3 2005/03/02 10:55:54 cozman Exp $ // $Id: math.hpp,v 1.4 2005/03/03 09:25:19 cozman Exp $
#ifndef PHOTON_MATH_MATH_HPP #ifndef PHOTON_MATH_MATH_HPP
#define PHOTON_MATH_MATH_HPP #define PHOTON_MATH_MATH_HPP
@ -24,7 +24,10 @@ class Vector2;
// Title: Math Utilities // Title: Math Utilities
// Group: Constants // Group: Constants
const scalar Pi=3.1415926535897932384626433832795;
// Constant: PI
// Defined constant for pi: 3.1415926535897932384626433832795
const scalar PI=3.1415926535897932384626433832795;
// Group: Generic // Group: Generic
@ -62,7 +65,7 @@ bool scalarCompare(scalar val1, scalar val2, scalar epsilon=0.000001);
// //
// Returns: // Returns:
// Scalar distance between the two points. // Scalar distance between the two points.
scalar distance(Vector2 v1, Vector2 v2); scalar distance(const Vector2& v1, const Vector2& v2);
// Group: Degrees/Radians // Group: Degrees/Radians
@ -74,6 +77,9 @@ scalar distance(Vector2 v1, Vector2 v2);
// //
// Returns: // Returns:
// Radian equivalent of 'degrees'. // Radian equivalent of 'degrees'.
//
// See Also:
// <radToDeg>
scalar degToRad(scalar degrees); scalar degToRad(scalar degrees);
// Function: radToDeg // Function: radToDeg
@ -84,9 +90,12 @@ scalar degToRad(scalar degrees);
// //
// Returns: // Returns:
// Degree equivalent of 'radians' // Degree equivalent of 'radians'
//
// See Also:
// <degToRad>
scalar radToDeg(scalar radians); scalar radToDeg(scalar radians);
//template implementation // clamp template implementation
template<typename T, typename C> template<typename T, typename C>
T clamp(T val, C low, C high) T clamp(T val, C low, C high)

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: ConfigFile.hpp,v 1.2 2005/02/16 06:58:05 cozman Exp $ // $Id: ConfigFile.hpp,v 1.3 2005/03/03 09:25:19 cozman Exp $
#ifndef PHOTON_UTIL_CONFIGFILE_HPP #ifndef PHOTON_UTIL_CONFIGFILE_HPP
#define PHOTON_UTIL_CONFIGFILE_HPP #define PHOTON_UTIL_CONFIGFILE_HPP
@ -122,6 +122,7 @@ public:
const std::string& var, const std::string& var,
varType defVal) const; varType defVal) const;
// behind the scenes utils
private: private:
static std::string cleanString(const std::string& str); static std::string cleanString(const std::string& str);
static std::string bracketString(const std::string& str); static std::string bracketString(const std::string& str);
@ -164,14 +165,14 @@ ConfigFile::setVariable(const std::string& sec,
{ {
layout_.push_back( NamedSection( secBrac, Section() ) ); layout_.push_back( NamedSection( secBrac, Section() ) );
//search again, assert that it now exists // search again
secIter = std::find_if( layout_.begin(), secIter = std::find_if( layout_.begin(),
layout_.end(), layout_.end(),
std::bind2nd(StrPairEq<NamedSection>(), secBrac) ); std::bind2nd(StrPairEq<NamedSection>(),
assert(secIter != layout_.end()); secBrac) );
} }
//search for variable // search for variable
varIter = std::find_if( secIter->second.begin(), varIter = std::find_if( secIter->second.begin(),
secIter->second.end(), secIter->second.end(),
std::bind2nd(StrPairEq<Variable>(), var) ); std::bind2nd(StrPairEq<Variable>(), var) );

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: FileBuffer.hpp,v 1.2 2005/02/16 06:58:06 cozman Exp $ // $Id: FileBuffer.hpp,v 1.3 2005/03/03 09:25:20 cozman Exp $
#ifndef PHOTON_UTIL_FILEBUFFER_HPP #ifndef PHOTON_UTIL_FILEBUFFER_HPP
#define PHOTON_UTIL_FILEBUFFER_HPP #define PHOTON_UTIL_FILEBUFFER_HPP
@ -45,7 +45,6 @@ public:
// Destructor, calls <close>. // Destructor, calls <close>.
~FileBuffer(); ~FileBuffer();
// Group: General // Group: General
public: public:
// Function: open // Function: open

View File

@ -5,23 +5,23 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: RandGen.hpp,v 1.2 2005/02/16 06:58:06 cozman Exp $ // $Id: RandGen.hpp,v 1.3 2005/03/03 09:25:20 cozman Exp $
#ifndef PHOTON_UTIL_RANDGEN_HPP #ifndef PHOTON_UTIL_RANDGEN_HPP
#define PHOTON_UTIL_RANDGEN_HPP #define PHOTON_UTIL_RANDGEN_HPP
namespace photon { namespace photon
namespace util { {
namespace util
{
// Class: RandGen // Class: RandGen
// Psuedorandom number generator class which uses Mersenne Twister. // Psuedorandom number generator class which uses Mersenne Twister.
// MT19937 is described at <http://www.math.keio.ac.jp/matumoto/emt.html>. // MT19937 is described at <http://www.math.keio.ac.jp/matumoto/emt.html>.
class RandGen class RandGen
{ {
// Group: (Con/De)structors
public: public:
// Group: (Con/De)structors
// Function: RandGen // Function: RandGen
// Constructor for random generator, using time as seed. // Constructor for random generator, using time as seed.
RandGen(); RandGen();
@ -37,7 +37,8 @@ public:
// <seed> // <seed>
RandGen(unsigned long seedVal); RandGen(unsigned long seedVal);
// Group: General // Group: General
public:
// Function: seed // Function: seed
// Reseed random generator, a given seed will always turn out same string // Reseed random generator, a given seed will always turn out same string

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Singleton.hpp,v 1.4 2005/03/01 07:51:23 cozman Exp $ // $Id: Singleton.hpp,v 1.5 2005/03/03 09:25:20 cozman Exp $
#ifndef PHOTON_UTIL_SINGLETON_HPP #ifndef PHOTON_UTIL_SINGLETON_HPP
#define PHOTON_UTIL_SINGLETON_HPP #define PHOTON_UTIL_SINGLETON_HPP
@ -13,6 +13,8 @@
#include <memory> #include <memory>
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include "exceptions.hpp"
namespace photon namespace photon
{ {
namespace util namespace util
@ -67,7 +69,7 @@ public:
static T& getInstance(); static T& getInstance();
protected: protected:
virtual ~Singleton()=0; virtual ~Singleton()=0; // allow inheritance
private: private:
static std::auto_ptr<T> instance_; static std::auto_ptr<T> instance_;
@ -84,7 +86,10 @@ Singleton<T>::~Singleton()
template<class T> template<class T>
void Singleton<T>::initialize() void Singleton<T>::initialize()
{ {
assert(instance_.get() == 0); if(instance_.get() != 0)
{
throw PreconditionException("Attempt to double-initialize singleton.");
}
instance_ = std::auto_ptr<T>(new T); instance_ = std::auto_ptr<T>(new T);
} }
@ -92,7 +97,10 @@ void Singleton<T>::initialize()
template<class T> template<class T>
void Singleton<T>::destroy() void Singleton<T>::destroy()
{ {
assert(instance_.get() != 0); if(instance_.get() == 0)
{
throw PreconditionException("Attempt to destroy null singleton.");
}
instance_.reset(); instance_.reset();
} }
@ -100,9 +108,13 @@ void Singleton<T>::destroy()
template<class T> template<class T>
T& Singleton<T>::getInstance() T& Singleton<T>::getInstance()
{ {
assert(instance_.get() != 0); if(instance_.get() == 0)
{
throw PreconditionException("Attempt to get instance of uninitialized "
"singleton.");
}
return *instance_; return *instance_; //return dereferenced version
} }
template<class T> template<class T>

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: VersionInfo.hpp,v 1.4 2005/03/01 07:51:24 cozman Exp $ // $Id: VersionInfo.hpp,v 1.5 2005/03/03 09:25:20 cozman Exp $
#ifndef PHOTON_UTIL_VERSIONINFO_HPP #ifndef PHOTON_UTIL_VERSIONINFO_HPP
#define PHOTON_UTIL_VERSIONINFO_HPP #define PHOTON_UTIL_VERSIONINFO_HPP
@ -13,8 +13,10 @@
#include <string> #include <string>
#include <ostream> #include <ostream>
namespace photon { namespace photon
namespace util { {
namespace util
{
// Class: VersionInfo // Class: VersionInfo
// Class which stores version information, such as release numbers. // Class which stores version information, such as release numbers.

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Pen.hpp,v 1.1 2005/03/02 10:55:29 cozman Exp $ // $Id: Pen.hpp,v 1.2 2005/03/03 09:25:47 cozman Exp $
#ifndef PHOTON_VIDEO_PEN_HPP #ifndef PHOTON_VIDEO_PEN_HPP
#define PHOTON_VIDEO_PEN_HPP #define PHOTON_VIDEO_PEN_HPP
@ -56,7 +56,7 @@ public:
// //
// See Also: // See Also:
// <setColor> // <setColor>
Pen(Color color); Pen(const Color& color);
// Group: Color // Group: Color
public: public:
@ -75,7 +75,7 @@ public:
// //
// Parameters: // Parameters:
// color - <Color> to use for drawing. // color - <Color> to use for drawing.
void setColor(Color color); void setColor(const Color& color);
// Group: Drawing // Group: Drawing
public: public:
@ -84,7 +84,7 @@ public:
// //
// Parameters: // Parameters:
// point - Point to draw. // point - Point to draw.
void drawPoint(math::Point2 point) const; void drawPoint(const math::Point2& point) const;
// Function: drawLine // Function: drawLine
// Draw a line from one point to another. // Draw a line from one point to another.
@ -92,7 +92,7 @@ public:
// Parameters: // Parameters:
// p1 - First endpoint of line. // p1 - First endpoint of line.
// p2 - Second endpoint of line. // p2 - Second endpoint of line.
void drawLine(math::Point2 p1, math::Point2 p2) const; void drawLine(const math::Point2& p1, const math::Point2& p2) const;
// Function: drawVector // Function: drawVector
// Draw a vector, including small arrow, with base at a given point. // Draw a vector, including small arrow, with base at a given point.
@ -100,7 +100,8 @@ public:
// Parameters: // Parameters:
// point - Base point for vector. // point - Base point for vector.
// vector - Vector to draw. // vector - Vector to draw.
void drawVector(math::Point2 point, math::Vector2 vector) const; void drawVector(const math::Point2& point,
const math::Vector2& vector) const;
// Function: drawRectangle // Function: drawRectangle
// Draw an empty rectangle. // Draw an empty rectangle.

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: AudioCore.cpp,v 1.1 2005/02/27 05:55:18 cozman Exp $ // $Id: AudioCore.cpp,v 1.2 2005/03/03 09:25:47 cozman Exp $
#include "audio/AudioCore.hpp" #include "audio/AudioCore.hpp"
@ -27,8 +27,8 @@ std::string AudioCore::getAudioDeviceName() const
util::VersionInfo AudioCore::initOpenAL() util::VersionInfo AudioCore::initOpenAL()
{ {
ALCdevice* device; ALCdevice* device(0);
ALCcontext* context; ALCcontext* context(0);
std::stringstream ss; std::stringstream ss;
std::string junks; std::string junks;
char junkc; char junkc;
@ -53,8 +53,9 @@ util::VersionInfo AudioCore::initOpenAL()
checkOpenALError()); checkOpenALError());
} }
alcMakeContextCurrent(context); alcMakeContextCurrent(context); // context must be current to get version
// Version is in format "OpenAL 1.0"
ss << alGetString(AL_VERSION); ss << alGetString(AL_VERSION);
ss >> junks >> major >> junkc >> minor; ss >> junks >> major >> junkc >> minor;
return util::VersionInfo(major,minor,0); return util::VersionInfo(major,minor,0);
@ -86,7 +87,7 @@ std::string AudioCore::checkOpenALError()
err = "OpenAL out of memory"; err = "OpenAL out of memory";
break; break;
default: default:
err = "Unknown OpenAL error."; err = "Unknown OpenAL error";
break; break;
} }
@ -95,6 +96,7 @@ std::string AudioCore::checkOpenALError()
void AudioCore::setDesiredDevice(const std::string& name) void AudioCore::setDesiredDevice(const std::string& name)
{ {
// deviceName_ is used inside initOpenAL, must be set prior to construction
deviceName_ = name; deviceName_ = name;
} }
@ -102,13 +104,14 @@ std::string AudioCore::deviceName_;
AudioCore::AudioCore() AudioCore::AudioCore()
{ {
util::VersionInfo oalReq(1,0,0); // requires OpenAL 1.0 util::VersionInfo oalReq(1,0,0); // requires OpenAL 1.0 (TODO: check?)
util::ensureVersion("OpenAL", initOpenAL(), oalReq); util::ensureVersion("OpenAL", initOpenAL(), oalReq);
} }
AudioCore::~AudioCore() AudioCore::~AudioCore()
{ {
// retrieve both the context and device
ALCcontext* context( alcGetCurrentContext() ); ALCcontext* context( alcGetCurrentContext() );
ALCdevice* device( alcGetContextsDevice(context) ); ALCdevice* device( alcGetContextsDevice(context) );

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Circle.cpp,v 1.1 2005/02/27 09:00:13 cozman Exp $ // $Id: Circle.cpp,v 1.2 2005/03/03 09:25:47 cozman Exp $
#include "math/Circle.hpp" #include "math/Circle.hpp"
@ -68,7 +68,7 @@ bool Circle::intersects(const Rect &rect) const
{ {
scalar newX; scalar newX;
scalar newY; scalar newY;
Rect circBound(center_-Vector2(radius_,radius_),2*radius_,2*radius_); Rect circBound(center_-Point2(radius_,radius_),2*radius_,2*radius_);
//reference of rects, 'rect' is shown as rect 5 //reference of rects, 'rect' is shown as rect 5
// _____________ // _____________
@ -124,6 +124,18 @@ Point2 Circle::getCenter() const
return center_; return center_;
} }
scalar Circle::getCenterX() const
{
return center_.x;
}
scalar Circle::getCenterY() const
{
return center_.y;
}
scalar Circle::getRadius() const scalar Circle::getRadius() const
{ {
return radius_; return radius_;

View File

@ -5,12 +5,14 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Rect.cpp,v 1.1 2005/02/27 09:00:13 cozman Exp $ // $Id: Rect.cpp,v 1.2 2005/03/03 09:25:47 cozman Exp $
#include "math/Rect.hpp" #include "math/Rect.hpp"
#include <algorithm> #include <algorithm>
#include "math/Circle.hpp"
namespace photon namespace photon
{ {
namespace math namespace math
@ -75,6 +77,11 @@ bool Rect::intersects(const Rect &rect) const
rect.topLeft_.y > bottomRight_.y); rect.topLeft_.y > bottomRight_.y);
} }
bool Rect::intersects(const Circle &circle) const
{
return circle.intersects(*this);
}
bool Rect::contains(const Point2 &point) const bool Rect::contains(const Point2 &point) const
{ {
return point.x > topLeft_.x && point.x < bottomRight_.x && return point.x > topLeft_.x && point.x < bottomRight_.x &&

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: math.cpp,v 1.1 2005/02/27 09:00:13 cozman Exp $ // $Id: math.cpp,v 1.2 2005/03/03 09:25:47 cozman Exp $
#include "math/math.hpp" #include "math/math.hpp"
@ -21,7 +21,7 @@ bool scalarCompare(scalar val1, scalar val2, scalar epsilon)
return std::fabs(val1-val2) < epsilon; return std::fabs(val1-val2) < epsilon;
} }
scalar distance(Vector2 v1, Vector2 v2) scalar distance(const Vector2& v1, const Vector2& v2)
{ {
return magnitude(v1-v2); return magnitude(v1-v2);
} }

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: ConfigFile.cpp,v 1.4 2005/02/16 06:58:26 cozman Exp $ // $Id: ConfigFile.cpp,v 1.5 2005/03/03 09:25:47 cozman Exp $
#include "util/ConfigFile.hpp" #include "util/ConfigFile.hpp"
#include "exceptions.hpp" #include "exceptions.hpp"
@ -17,8 +17,6 @@ namespace photon
namespace util namespace util
{ {
//(Con/De)structors //(Con/De)structors
ConfigFile::ConfigFile() ConfigFile::ConfigFile()
@ -42,7 +40,7 @@ void ConfigFile::open(const std::string& filename)
filename_ = filename; filename_ = filename;
if(filename_.empty()) if(filename_.empty())
{ {
throw PreconditionException("No filename in ConfigFile::open"); throw PreconditionException("Empty filename in ConfigFile::open");
} }
std::string section, var, val, str, clean; std::string section, var, val, str, clean;

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: RandGen.cpp,v 1.4 2005/02/16 06:58:26 cozman Exp $ // $Id: RandGen.cpp,v 1.5 2005/03/03 09:25:47 cozman Exp $
// The source in this file is based on MT19937, with much of the source // The source in this file is based on MT19937, with much of the source
// replicated from mt19937ar.c, because of this the original license // replicated from mt19937ar.c, because of this the original license
@ -57,8 +57,10 @@
#include "util/RandGen.hpp" #include "util/RandGen.hpp"
#include <ctime> #include <ctime>
namespace photon { namespace photon
namespace util { {
namespace util
{
//static consts //static consts
const unsigned long RandGen::N; const unsigned long RandGen::N;

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: VersionInfo.cpp,v 1.5 2005/02/27 05:53:36 cozman Exp $ // $Id: VersionInfo.cpp,v 1.6 2005/03/03 09:25:47 cozman Exp $
#include "util/VersionInfo.hpp" #include "util/VersionInfo.hpp"
@ -13,8 +13,10 @@
#include "exceptions.hpp" #include "exceptions.hpp"
namespace photon { namespace photon
namespace util { {
namespace util
{
VersionInfo::VersionInfo(unsigned int maj, unsigned int min, unsigned int pat, VersionInfo::VersionInfo(unsigned int maj, unsigned int min, unsigned int pat,
std::string ext) : std::string ext) :
@ -27,20 +29,29 @@ VersionInfo::VersionInfo() :
bool VersionInfo::operator<(const VersionInfo &rhs) const bool VersionInfo::operator<(const VersionInfo &rhs) const
{ {
bool less(false);
//chained compares, compare numbers in order of importance //chained compares, compare numbers in order of importance
if(this->major < rhs.major) if(this->major < rhs.major)
return true; {
less = true;
}
else if(this->major == rhs.major) else if(this->major == rhs.major)
{ {
if(this->minor < rhs.minor) if(this->minor < rhs.minor)
return true; {
less = true;
}
else if(this->minor == rhs.minor) else if(this->minor == rhs.minor)
{ {
if(this->patch < rhs.patch) if(this->patch < rhs.patch)
return true; {
less = true;
}
} }
} }
return false; //if it reaches this point rhs is >=
return less; //false unless set to true within if-chain
} }
bool VersionInfo::operator<=(const VersionInfo &rhs) const bool VersionInfo::operator<=(const VersionInfo &rhs) const
@ -66,6 +77,7 @@ bool VersionInfo::operator>(const VersionInfo &rhs) const
std::ostream& operator<<(std::ostream &o, const VersionInfo &rhs) std::ostream& operator<<(std::ostream &o, const VersionInfo &rhs)
{ {
// output major.minor.path [extra] (extra is only printed if not empty)
return o << rhs.major << '.' << rhs.minor << '.' << rhs.patch << return o << rhs.major << '.' << rhs.minor << '.' << rhs.patch <<
(rhs.extra.empty() ? "" : " [" + rhs.extra + "]"); (rhs.extra.empty() ? "" : " [" + rhs.extra + "]");
} }
@ -80,7 +92,7 @@ void ensureVersion(const std::string& library,
{ {
ss << library << " version " << required << " required; " << ss << library << " version " << required << " required; " <<
version << " used, please update."; version << " used, please update.";
throw APIError(ss.str()); throw APIError(ss.str()); // throw APIError if requirement isn't met
} }
} }

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Pen.cpp,v 1.1 2005/03/02 10:55:29 cozman Exp $ // $Id: Pen.cpp,v 1.2 2005/03/03 09:25:47 cozman Exp $
#include "video/Pen.hpp" #include "video/Pen.hpp"
@ -28,7 +28,7 @@ Pen::Pen(ubyte r, ubyte g, ubyte b, ubyte a) :
{ {
} }
Pen::Pen(Color color) : Pen::Pen(const Color& color) :
color_(color) color_(color)
{ {
} }
@ -38,12 +38,12 @@ void Pen::setColor(ubyte r, ubyte g, ubyte b, ubyte a)
color_.setColor(r,g,b,a); color_.setColor(r,g,b,a);
} }
void Pen::setColor(Color color) void Pen::setColor(const Color& color)
{ {
color_ = color; color_ = color;
} }
void Pen::drawPoint(math::Point2 point) const void Pen::drawPoint(const math::Point2& point) const
{ {
glBindTexture(GL_TEXTURE_2D,0); glBindTexture(GL_TEXTURE_2D,0);
color_.makeGLColor(); color_.makeGLColor();
@ -53,7 +53,7 @@ void Pen::drawPoint(math::Point2 point) const
glColor4ub(255,255,255,255); glColor4ub(255,255,255,255);
} }
void Pen::drawLine(math::Point2 p1, math::Point2 p2) const void Pen::drawLine(const math::Point2& p1, const math::Point2& p2) const
{ {
glBindTexture(GL_TEXTURE_2D,0); glBindTexture(GL_TEXTURE_2D,0);
color_.makeGLColor(); color_.makeGLColor();
@ -64,17 +64,18 @@ void Pen::drawLine(math::Point2 p1, math::Point2 p2) const
glColor4ub(255,255,255,255); glColor4ub(255,255,255,255);
} }
void Pen::drawVector(math::Point2 point, math::Vector2 vector) const void Pen::drawVector(const math::Point2& point,
const math::Vector2& vector) const
{ {
double x2,y2,x3,y3,x4,y4; double x2,y2,x3,y3,x4,y4;
math::Vector2 v; math::Vector2 v;
x2 = point.x+vector.x; x2 = point.x+vector.x;
y2 = point.y+vector.y; y2 = point.y+vector.y;
//calculate an arrow (5pi/6) //calculate an arrow (5pi/6)
v.resolveRad(vector.getMagnitude()/5,vector.getAngleRad()+(5./6)*math::Pi); v.resolveRad(vector.getMagnitude()/5,vector.getAngleRad()+(5./6)*math::PI);
x3 = x2+v.x; x3 = x2+v.x;
y3 = y2-v.y; y3 = y2-v.y;
v.resolveRad(vector.getMagnitude()/5,vector.getAngleRad()-(5./6)*math::Pi); v.resolveRad(vector.getMagnitude()/5,vector.getAngleRad()-(5./6)*math::PI);
x4 = x2+v.x; x4 = x2+v.x;
y4 = y2-v.y; y4 = y2-v.y;