Wed, 05 Mar 2014 18:30:04 +0200
- doxygenified Types.h
src/ConfigurationDialog.cc | file | annotate | diff | comparison | revisions | |
src/Document.cc | file | annotate | diff | comparison | revisions | |
src/Types.cc | file | annotate | diff | comparison | revisions | |
src/Types.h | file | annotate | diff | comparison | revisions | |
src/Widgets.cc | file | annotate | diff | comparison | revisions | |
src/Widgets.h | file | annotate | diff | comparison | revisions | |
src/misc/RingFinder.cc | file | annotate | diff | comparison | revisions |
--- a/src/ConfigurationDialog.cc Wed Mar 05 17:29:27 2014 +0200 +++ b/src/ConfigurationDialog.cc Wed Mar 05 18:30:04 2014 +0200 @@ -208,7 +208,7 @@ *anglabel = new QLabel ("Angle"); int i = 1; - for (QLabel* label : initlist<QLabel*> ({xlabel, ylabel, zlabel, anglabel})) + for (QLabel* label : QList<QLabel*> ({xlabel, ylabel, zlabel, anglabel})) { label->setAlignment (Qt::AlignCenter); gridlayout->addWidget (label, 0, i++);
--- a/src/Document.cc Wed Mar 05 17:29:27 2014 +0200 +++ b/src/Document.cc Wed Mar 05 18:30:04 2014 +0200 @@ -281,9 +281,9 @@ { // Look in sub-directories: parts and p. Also look in net_downloadpath, since that's // where we download parts from the PT to. - for (const QString& topdir : initlist<QString> ({ io_ldpath, net_downloadpath })) + for (const QString& topdir : QList<QString> ({ io_ldpath, net_downloadpath })) { - for (const QString& subdir : initlist<QString> ({ "parts", "p" })) + for (const QString& subdir : QList<QString> ({ "parts", "p" })) { fullPath = format ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath);
--- a/src/Types.cc Wed Mar 05 17:29:27 2014 +0200 +++ b/src/Types.cc Wed Mar 05 18:30:04 2014 +0200 @@ -189,7 +189,7 @@ // ============================================================================= // -Matrix::Matrix (initlist<double> vals) +Matrix::Matrix (QList<double> vals) { assert (vals.size() == 9); memcpy (&m_vals[0], & (*vals.begin()), sizeof m_vals); @@ -259,12 +259,12 @@ // double Matrix::getDeterminant() const { - return (val (0) * val (4) * val (8)) + - (val (1) * val (5) * val (6)) + - (val (2) * val (3) * val (7)) - - (val (2) * val (4) * val (6)) - - (val (1) * val (3) * val (8)) - - (val (0) * val (5) * val (7)); + return (value (0) * value (4) * value (8)) + + (value (1) * value (5) * value (6)) + + (value (2) * value (3) * value (7)) - + (value (2) * value (4) * value (6)) - + (value (1) * value (3) * value (8)) - + (value (0) * value (5) * value (7)); } // ============================================================================= @@ -272,7 +272,7 @@ bool Matrix::operator== (const Matrix& other) const { for (int i = 0; i < 9; ++i) - if (val (i) != other[i]) + if (value (i) != other[i]) return false; return true; @@ -287,7 +287,7 @@ // ============================================================================= // -void LDBoundingBox::calculate() +void LDBoundingBox::calculateFromCurrentDocument() { reset(); @@ -349,12 +349,12 @@ // ============================================================================= // -void LDBoundingBox::calcVertex (const Vertex& v) +void LDBoundingBox::calcVertex (const Vertex& vertex) { for_axes (ax) { - m_vertex0[ax] = min (v[ax], m_vertex0[ax]); - m_vertex1[ax] = max (v[ax], m_vertex1[ax]); + m_vertex0[ax] = min (vertex[ax], m_vertex0[ax]); + m_vertex1[ax] = max (vertex[ax], m_vertex1[ax]); } setEmpty (false); @@ -371,7 +371,7 @@ // ============================================================================= // -double LDBoundingBox::size() const +double LDBoundingBox::longestMeasurement() const { double xscale = (m_vertex0[X] - m_vertex1[X]); double yscale = (m_vertex0[Y] - m_vertex1[Y]);
--- a/src/Types.h Wed Mar 05 17:29:27 2014 +0200 +++ b/src/Types.h Wed Mar 05 18:30:04 2014 +0200 @@ -36,11 +36,8 @@ using uint32 = quint32; using uint64 = quint64; -template<class T> -using initlist = std::initializer_list<T>; - -template<class T, class R> -using pair = std::pair<T, R>; +template<typename T, typename R> +using Pair = std::pair<T, R>; enum Axis { @@ -54,143 +51,230 @@ class LDObject; using LDObjectList = QList<LDObject*>; -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -// matrix -// -// A mathematical 3 x 3 matrix -// ============================================================================= +//! +//! \brief A mathematical 3 x 3 matrix +//! class Matrix { public: + //! Constructs a matrix with undetermined values. Matrix() {} - Matrix (initlist<double> vals); + + //! Constructs a matrix with the given values. + //! \note \c vals is expected to have exactly 9 elements. + Matrix (const QList<double>& vals); + + //! Constructs a matrix all 9 elements initialized to the same value. + //! \param fillval the value to initialize the matrix coordinates as Matrix (double fillval); + + //! Constructs a matrix with a C-array. + //! \note \c vals is expected to have exactly 9 elements. Matrix (double vals[]); + //! Calculates the matrix's determinant. + //! \returns the calculated determinant. double getDeterminant() const; + + //! Multiplies this matrix with \c other + //! \param other the matrix to multiply with. + //! \returns the resulting matrix + //! \note a.mult(b) is not equivalent to b.mult(a)! Matrix mult (const Matrix& other) const; + + //! Prints the matrix to stdout. void dump() const; + + //! \returns a string representation of the matrix. QString toString() const; + + //! Zeroes the matrix out. void zero(); + + //! Assigns the matrix values to the values of \c other. + //! \param other the matrix to assign this to. + //! \returns a reference to self Matrix& operator= (const Matrix& other); - inline double& val (int idx) + //! \returns a mutable reference to a value by \c idx + inline double& value (int idx) { return m_vals[idx]; } - inline const double& val (int idx) const + //! An overload of \c value() for const matrices. + //! \returns a const reference to a value by \c idx + inline const double& value (int idx) const { return m_vals[idx]; } + //! An operator overload for \c mult(). + //! \returns the multiplied matrix. inline Matrix operator* (const Matrix& other) const { return mult (other); } + //! An operator overload for \c value(). + //! \returns a mutable reference to a value by \c idx inline double& operator[] (int idx) { - return val (idx); + return value (idx); } + //! An operator overload for \c value() const. + //! \returns a const reference to a value by \c idx inline const double& operator[] (int idx) const { - return val (idx); + return value (idx); } + //! \param other the matrix to check against + //! \returns whether the two matrices have the same values. bool operator== (const Matrix& other) const; private: double m_vals[9]; }; -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -// Vertex -// -// Vertex class, contains a single point in 3D space. Not to be confused with -// LDVertex, which is a vertex used in an LDraw part file. -// ============================================================================= +//! +//! \brief A vertex in 3D space +//! +//! Contains a single point in 3D space. Not to be confused with +//! LDVertex, which is a vertex used in an LDraw part file. +//! +//! This also sees use as a position vector. +//! class Vertex { public: - Vertex() {} + //! Constructs a zero vertex + Vertex() : m_coords({0, 0, 0}) {} + + //! Constructs a vertex with the given \c x, \c y and \c z. Vertex (double x, double y, double z); + //! \returns the distance from this vertex to \c other double distanceTo (const Vertex& other) const; + + //! \returns the vertex at the midpoint between this and \c other Vertex midpoint (const Vertex& other); + + //! Moves this vertex using \param other as a position vector. void move (const Vertex& other); + + //! Yields a string representation of the vertex. The string returned + //! can possibly be mangled. + //! - As mangled: {1.5, 2.8, 3.14} + //! - Without mangling: 1.5 2.8 3.14 + //! + //! The mangled version is suitable for printing to the user, the + //! non-mangled one is used when writing the vertex to LDraw files. + //! + //! \returns a string representation of this vertex + //! \param mangled whether to return a mangled representation or not QString toString (bool mangled) const; + + //! Transforms this vertex with \c matr as transformation matrix + //! and \c pos as the position column of the 4x4 matrix. void transform (const Matrix& matr, const Vertex& pos); + //! An operator overload for \c move(). Vertex& operator+= (const Vertex& other); + + //! An operator overload for \c move(), using a temporary vertex. Vertex operator+ (const Vertex& other) const; + + //! Divides all values by \c d. Vertex operator/ (const double d) const; + + //! Divides all values by \c d. Vertex& operator/= (const double d); + + //! Checks whether this vertex has the same values as \c other. bool operator== (const Vertex& other) const; + + //! Checks whether this vertex has different values than \c other. bool operator!= (const Vertex& other) const; + + //! \returns a negated version the vertex Vertex operator-() const; + + //! \returns whether the vertex has lesser values than \c other. int operator< (const Vertex& other) const; + //! An operator overload for \c getCoordinate(). inline double& operator[] (const Axis ax) { return getCoordinate ((int) ax); } + //! An operator overload for \c getCoordinate() const. inline const double& operator[] (const Axis ax) const { return getCoordinate ((int) ax); } + //! An operator overload for \c getCoordinate(). inline double& operator[] (const int ax) { return getCoordinate (ax); } + //! An operator overload for \c getCoordinate() const. inline const double& operator[] (const int ax) const { return getCoordinate (ax); } + //! \returns a mutable reference for the coordinate designated by \param n. inline double& getCoordinate (int n) { return m_coords[n]; } + //! An overload of \c getCoordinate for const vertices. + //! \returns a const reference for the coordinate designated by \param n. inline const double& getCoordinate (int n) const { return m_coords[n]; } + //! \returns a mutable reference to X. inline double& x() { return m_coords[X]; } + //! An overload of \c x() for const vertices. + //! \returns a const reference to X. inline const double& x() const { return m_coords[X]; } + //! \returns a mutable reference to Y. inline double& y() { return m_coords[Y]; } + //! An overload of \c y() for const vertices. + //! \returns a const reference to Y. inline const double& y() const { return m_coords[Y]; } + //! \returns a mutable reference to Z. inline double& z() { return m_coords[Z]; } + //! An overload of \c z() for const vertices. + //! \returns a const reference to Z. inline const double& z() const { return m_coords[Z]; @@ -202,12 +286,10 @@ Q_DECLARE_METATYPE (Vertex) -// ============================================================================= -// LDBoundingBox +//! +//! Defines a bounding box that encompasses a given set of objects. +//! vertex0 is the minimum vertex, vertex1 is the maximum vertex. // -// The bounding box is the box that encompasses a given set of objects. -// v0 is the minimum vertex, v1 is the maximum vertex. -// ============================================================================= class LDBoundingBox { PROPERTY (private, bool, isEmpty, setEmpty, STOCK_WRITE) @@ -215,15 +297,34 @@ PROPERTY (private, Vertex, vertex1, setVertex1, STOCK_WRITE) public: + //! Constructs an empty bounding box. LDBoundingBox(); + + //! Clears the bounding box void reset(); - void calculate(); - double size() const; + + //! Calculates the bounding box's values from the objects in the current + //! document. + void calculateFromCurrentDocument(); + + //! \returns the length of the bounding box on the longest measure. + double longestMeasurement() const; + + //! Calculates the given \param obj to the bounding box, adjusting + //! extremas if necessary. void calcObject (LDObject* obj); - void calcVertex (const Vertex& v); + + //! Calculates the given \param vertex to the bounding box, adjusting + //! extremas if necessary. + void calcVertex (const Vertex& vertex); + + //! \returns the center of the bounding box. Vertex center() const; + //! An operator overload for \c calcObject() LDBoundingBox& operator<< (LDObject* obj); + + //! An operator overload for \c calcVertex() LDBoundingBox& operator<< (const Vertex& v); };
--- a/src/Widgets.cc Wed Mar 05 17:29:27 2014 +0200 +++ b/src/Widgets.cc Wed Mar 05 18:30:04 2014 +0200 @@ -71,7 +71,7 @@ // ============================================================================= // -RadioGroup::RadioGroup (const QString& title, initlist<char const*> entries, int const defaultId, const Qt::Orientation orient, QWidget* parent) : +RadioGroup::RadioGroup (const QString& title, QList<char const*> entries, int const defaultId, const Qt::Orientation orient, QWidget* parent) : QGroupBox (title, parent), m_defId (defaultId) {
--- a/src/Widgets.h Wed Mar 05 17:29:27 2014 +0200 +++ b/src/Widgets.h Wed Mar 05 18:30:04 2014 +0200 @@ -52,7 +52,7 @@ } explicit RadioGroup (const QString& title, QWidget* parent = null); - explicit RadioGroup (const QString& title, initlist<char const*> entries, int const defaultId, + explicit RadioGroup (const QString& title, QList<char const*> entries, int const defaultId, const Qt::Orientation orient = Qt::Vertical, QWidget* parent = null); void addButton (const char* entry);
--- a/src/misc/RingFinder.cc Wed Mar 05 17:29:27 2014 +0200 +++ b/src/misc/RingFinder.cc Wed Mar 05 18:30:04 2014 +0200 @@ -124,7 +124,7 @@ { const Solution& sol = *solp; - if (m_bestSolution == null || sol.isBetterThan (m_bestSolution)) + if (m_bestSolution == null || sol.isSuperiorTo (m_bestSolution)) m_bestSolution = / } @@ -133,7 +133,7 @@ // ============================================================================= // -bool RingFinder::Solution::isBetterThan (const Solution* other) const +bool RingFinder::Solution::isSuperiorTo (const Solution* other) const { // If this solution has less components than the other one, this one // is definitely better.