summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-10-17 05:10:25 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-10-17 05:10:25 +0000
commit47428274a07bce9be5e62f82aeeb7e57aa21037f (patch)
tree1e7ab1f7cfa82a1aca56d0ec6bd0d705bce427b1
parent3b83cc89885788de19b09f5e9e55c5d3ad7c60c9 (diff)
downloadsigen-47428274a07bce9be5e62f82aeeb7e57aa21037f.tar.gz
sigen-47428274a07bce9be5e62f82aeeb7e57aa21037f.tar.xz
sigen-47428274a07bce9be5e62f82aeeb7e57aa21037f.zip
[FIX] Added more comparison operators to Fraction
[FIX] mid and setMid in Matrix replaced with addMask git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@280 6ecfd1a5-f3ed-3746-8530-beee90d26b22
-rw-r--r--Changelog8
-rw-r--r--sigmod/Fraction.cpp22
-rw-r--r--sigmod/Fraction.h4
-rw-r--r--sigmod/Matrix.h72
4 files changed, 55 insertions, 51 deletions
diff --git a/Changelog b/Changelog
index bd440dc2..0bad146d 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,12 @@
-----------------
+Rev: 280
+Date: 17 October 2008
+User: MathStuf
+-----------------
+[FIX] Added more comparison operators to Fraction
+[FIX] mid and setMid in Matrix replaced with addMask
+
+-----------------
Rev: 279
Date: 16 October 2008
User: MathStuf
diff --git a/sigmod/Fraction.cpp b/sigmod/Fraction.cpp
index 8bafe022..c27c2e6e 100644
--- a/sigmod/Fraction.cpp
+++ b/sigmod/Fraction.cpp
@@ -139,7 +139,7 @@ Sigmod::Fraction& Sigmod::Fraction::operator/=(const Fraction& rhs)
bool Sigmod::Fraction::operator==(const Fraction& rhs) const
{
- return ((m_numerator == rhs.m_numerator) && (m_denominator == rhs.m_denominator));
+ return ((m_numerator * rhs.m_denominator) == (m_denominator * rhs.m_numerator));
}
bool Sigmod::Fraction::operator!=(const Fraction& rhs) const
@@ -147,6 +147,26 @@ bool Sigmod::Fraction::operator!=(const Fraction& rhs) const
return !(*this == rhs);
}
+bool Sigmod::Fraction::operator<(const Fraction& rhs) const
+{
+ return ((m_numerator * rhs.m_denominator) < (m_denominator * rhs.m_numerator));
+}
+
+bool Sigmod::Fraction::operator<=(const Fraction& rhs) const
+{
+ return ((m_numerator * rhs.m_denominator) <= (m_denominator * rhs.m_numerator));
+}
+
+bool Sigmod::Fraction::operator>(const Fraction& rhs) const
+{
+ return !(*this <= rhs);
+}
+
+bool Sigmod::Fraction::operator>=(const Fraction& rhs) const
+{
+ return !(*this < rhs);
+}
+
void Sigmod::Fraction::normalize()
{
if (m_denominator < 0)
diff --git a/sigmod/Fraction.h b/sigmod/Fraction.h
index 65f59523..7dd861ea 100644
--- a/sigmod/Fraction.h
+++ b/sigmod/Fraction.h
@@ -115,6 +115,10 @@ class SIGMOD_EXPORT Fraction
Fraction& operator%=(const Fraction& rhs);
bool operator==(const Fraction& rhs) const;
bool operator!=(const Fraction& rhs) const;
+ bool operator<(const Fraction& rhs) const;
+ bool operator<=(const Fraction& rhs) const;
+ bool operator>(const Fraction& rhs) const;
+ bool operator>=(const Fraction& rhs) const;
protected:
void normalize();
private:
diff --git a/sigmod/Matrix.h b/sigmod/Matrix.h
index 1726804c..1338001d 100644
--- a/sigmod/Matrix.h
+++ b/sigmod/Matrix.h
@@ -55,7 +55,7 @@ template<class T> class SIGMOD_EXPORT Matrix
*
* \param rhs The matrix to copy.
*/
- Matrix(const Matrix<T>& rhs);
+ Matrix(const Matrix& rhs);
/**
* Add a row to the matrix.
@@ -127,25 +127,13 @@ template<class T> class SIGMOD_EXPORT Matrix
QVector<T> column(const int column) const;
/**
- * Get a matrix from within the matrix.
+ * Add a masked matrix to the matrix.
*
* \param top The top-most part of the matrix.
* \param left The left-most part of the matrix.
- * \param height The height of the new matrix.
- * \param width The width of the new matrix.
- * \return The matrix.
+ * \param mask The mask to add.
*/
- Matrix<T> mid(const int top, const int left, const int height, const int width) const;
- /**
- * Set a matrix from within the matrix.
- *
- * \param top The top-most part of the matrix.
- * \param left The left-most part of the matrix.
- * \param height The height of the new matrix.
- * \param width The width of the new matrix.
- * \param value The value to set the mid to.
- */
- void setMid(const int top, const int left, const int height, const int width, const T& value);
+ void addMask(const int top, const int left, const Matrix& mask);
/**
* \return The height of the matrix.
@@ -172,9 +160,9 @@ template<class T> class SIGMOD_EXPORT Matrix
* \return The value of the cell in the matrix.
*/
T operator()(const int row, const int column) const;
- Matrix<T>& operator=(const Matrix<T>& rhs);
- bool operator==(const Matrix<T>& rhs) const;
- bool operator!=(const Matrix<T>& rhs) const;
+ Matrix<T>& operator=(const Matrix& rhs);
+ bool operator==(const Matrix& rhs) const;
+ bool operator!=(const Matrix& rhs) const;
private:
QVector< QVector<T> > m_matrix;
};
@@ -188,7 +176,7 @@ template<class T> Matrix<T>::Matrix(const int height, const int width, const T&
resize(height, width, value);
}
-template<class T> Matrix<T>::Matrix(const Matrix<T>& rhs)
+template<class T> Matrix<T>::Matrix(const Matrix& rhs)
{
*this = rhs;
}
@@ -283,39 +271,23 @@ template<class T> QVector<T> Matrix<T>::column(const int column) const
return col;
}
-template<class T> Matrix<T> Matrix<T>::mid(const int top, const int left, const int height, const int width) const
-{
- Q_ASSERT(0 <= top);
- Q_ASSERT(top < height());
- Q_ASSERT(0 <= left);
- Q_ASSERT(left < width());
- Q_ASSERT(0 <= height);
- Q_ASSERT(top + height <= height());
- Q_ASSERT(0 <= width);
- Q_ASSERT(left + width <= width());
- Matrix<T> matrix(height, width);
- for (int i = 0; i < height; ++i)
- {
- for (int j = 0; j < width; ++j)
- matrix(i, j) = operator()(top + i, left + j);
- }
- return matrix;
-}
-
-template<class T> void Matrix<T>::setMid(const int top, const int left, const int height, const int width, const T& value)
+template<class T> void Matrix<T>::addMask(const int top, const int left, const Matrix& mask)
{
Q_ASSERT(0 <= top);
Q_ASSERT(top < height());
Q_ASSERT(0 <= left);
Q_ASSERT(left < width());
- Q_ASSERT(0 <= height);
- Q_ASSERT(top + height <= height());
- Q_ASSERT(0 <= width);
- Q_ASSERT(left + width <= width());
- for (int i = 0; i < height; ++i)
+ Q_ASSERT(0 <= mask.height());
+ Q_ASSERT(top + mask.height() <= height());
+ Q_ASSERT(0 <= mask.width());
+ Q_ASSERT(left + mask.width() <= width());
+ for (int i = 0; i < mask.height(); ++i)
{
- for (int j = 0; j < width; ++j)
- operator()(top + i, left + j) = value;
+ for (int j = 0; j < mask.width(); ++j)
+ {
+ if (operator()(top + i, left + j) || mask(i, j))
+ operator()(top + i, left + j) = 1;
+ }
}
}
@@ -345,7 +317,7 @@ template<class T> T Matrix<T>::operator()(const int row, const int column) const
return m_matrix.at(row).at(column);
}
-template<class T> Matrix<T>& Matrix<T>::operator=(const Matrix<T>& rhs)
+template<class T> Matrix<T>& Matrix<T>::operator=(const Matrix& rhs)
{
if (this == &rhs)
return *this;
@@ -358,7 +330,7 @@ template<class T> Matrix<T>& Matrix<T>::operator=(const Matrix<T>& rhs)
return *this;
}
-template<class T> bool Matrix<T>::operator==(const Matrix<T>& rhs) const
+template<class T> bool Matrix<T>::operator==(const Matrix& rhs) const
{
if (this == &rhs)
return true;
@@ -366,7 +338,7 @@ template<class T> bool Matrix<T>::operator==(const Matrix<T>& rhs) const
return true;
}
-template<class T> bool Matrix<T>::operator!=(const Matrix<T>& rhs) const
+template<class T> bool Matrix<T>::operator!=(const Matrix& rhs) const
{
return !(*this == rhs);
}