|     28 #include "ldDocument.h" | 
    28 #include "ldDocument.h" | 
|     29  | 
    29  | 
|     30 Vertex::Vertex() : | 
    30 Vertex::Vertex() : | 
|     31 	QVector3D() {} | 
    31 	QVector3D() {} | 
|     32  | 
    32  | 
|     33 Vertex::Vertex (const QVector3D& a) : | 
    33 Vertex::Vertex(const QVector3D& a) : | 
|     34 	QVector3D (a) {} | 
    34 	QVector3D(a) {} | 
|     35  | 
    35  | 
|     36 Vertex::Vertex (qreal xpos, qreal ypos, qreal zpos) : | 
    36 Vertex::Vertex(qreal xpos, qreal ypos, qreal zpos) : | 
|     37 	QVector3D(xpos, ypos, zpos) {} | 
    37 	QVector3D(xpos, ypos, zpos) {} | 
|     38  | 
    38  | 
|     39  | 
    39  | 
|     40 void Vertex::transform (const Matrix& matr, const Vertex& pos) | 
    40 void Vertex::transform(const Matrix& matr, const Vertex& pos) | 
|     41 { | 
    41 { | 
|     42 	double x2 = (matr[0] * x()) + (matr[1] * y()) + (matr[2] * z()) + pos.x(); | 
    42 	double x2 = (matr[0] * x()) +(matr[1] * y()) +(matr[2] * z()) + pos.x(); | 
|     43 	double y2 = (matr[3] * x()) + (matr[4] * y()) + (matr[5] * z()) + pos.y(); | 
    43 	double y2 = (matr[3] * x()) +(matr[4] * y()) +(matr[5] * z()) + pos.y(); | 
|     44 	double z2 = (matr[6] * x()) + (matr[7] * y()) + (matr[8] * z()) + pos.z(); | 
    44 	double z2 = (matr[6] * x()) +(matr[7] * y()) +(matr[8] * z()) + pos.z(); | 
|     45 	setX (x2); | 
    45 	setX(x2); | 
|     46 	setY (y2); | 
    46 	setY(y2); | 
|     47 	setZ (z2); | 
    47 	setZ(z2); | 
|     48 } | 
    48 } | 
|     49  | 
    49  | 
|     50 void Vertex::apply (ApplyFunction func) | 
    50 void Vertex::apply(ApplyFunction func) | 
|     51 { | 
    51 { | 
|     52 	double newX = x(), newY = y(), newZ = z(); | 
    52 	double newX = x(), newY = y(), newZ = z(); | 
|     53 	func (X, newX); | 
    53 	func(X, newX); | 
|     54 	func (Y, newY); | 
    54 	func(Y, newY); | 
|     55 	func (Z, newZ); | 
    55 	func(Z, newZ); | 
|     56 	*this = Vertex (newX, newY, newZ); | 
    56 	*this = Vertex(newX, newY, newZ); | 
|     57 } | 
    57 } | 
|     58  | 
    58  | 
|     59 void Vertex::apply (ApplyConstFunction func) const | 
    59 void Vertex::apply(ApplyConstFunction func) const | 
|     60 { | 
    60 { | 
|     61 	func (X, x()); | 
    61 	func(X, x()); | 
|     62 	func (Y, y()); | 
    62 	func(Y, y()); | 
|     63 	func (Z, z()); | 
    63 	func(Z, z()); | 
|     64 } | 
    64 } | 
|     65  | 
    65  | 
|     66 double Vertex::operator[] (Axis ax) const | 
    66 double Vertex::operator[](Axis ax) const | 
|     67 { | 
    67 { | 
|     68 	switch (ax) | 
    68 	switch(ax) | 
|     69 	{ | 
    69 	{ | 
|     70 		case X: return x(); | 
    70 		case X: return x(); | 
|     71 		case Y: return y(); | 
    71 		case Y: return y(); | 
|     72 		case Z: return z(); | 
    72 		case Z: return z(); | 
|     73 	} | 
    73 	} | 
|     74  | 
    74  | 
|     75 	return 0.0; | 
    75 	return 0.0; | 
|     76 } | 
    76 } | 
|     77  | 
    77  | 
|     78 void Vertex::setCoordinate (Axis ax, qreal value) | 
    78 void Vertex::setCoordinate(Axis ax, qreal value) | 
|     79 { | 
    79 { | 
|     80 	switch (ax) | 
    80 	switch(ax) | 
|     81 	{ | 
    81 	{ | 
|     82 		case X: setX (value); break; | 
    82 		case X: setX(value); break; | 
|     83 		case Y: setY (value); break; | 
    83 		case Y: setY(value); break; | 
|     84 		case Z: setZ (value); break; | 
    84 		case Z: setZ(value); break; | 
|     85 	} | 
    85 	} | 
|     86 } | 
    86 } | 
|     87  | 
    87  | 
|     88 QString Vertex::toString (bool mangled) const | 
    88 QString Vertex::toString(bool mangled) const | 
|     89 { | 
    89 { | 
|     90 	if (mangled) | 
    90 	if (mangled) | 
|     91 		return format ("(%1, %2, %3)", x(), y(), z()); | 
    91 		return format("(%1, %2, %3)", x(), y(), z()); | 
|     92  | 
    92  | 
|     93 	return format ("%1 %2 %3", x(), y(), z()); | 
    93 	return format("%1 %2 %3", x(), y(), z()); | 
|     94 } | 
    94 } | 
|     95  | 
    95  | 
|     96 Vertex Vertex::operator* (qreal scalar) const | 
    96 Vertex Vertex::operator*(qreal scalar) const | 
|     97 { | 
    97 { | 
|     98 	return Vertex (x() * scalar, y() * scalar, z() * scalar); | 
    98 	return Vertex(x() * scalar, y() * scalar, z() * scalar); | 
|     99 } | 
    99 } | 
|    100  | 
   100  | 
|    101 Vertex& Vertex::operator+= (const Vertex& other) | 
   101 Vertex& Vertex::operator+= (const Vertex& other) | 
|    102 { | 
   102 { | 
|    103 	setX (x() + other.x()); | 
   103 	setX(x() + other.x()); | 
|    104 	setY (y() + other.y()); | 
   104 	setY(y() + other.y()); | 
|    105 	setZ (z() + other.z()); | 
   105 	setZ(z() + other.z()); | 
|    106 	return *this; | 
   106 	return *this; | 
|    107 } | 
   107 } | 
|    108  | 
   108  | 
|    109 Vertex Vertex::operator+ (const Vertex& other) const | 
   109 Vertex Vertex::operator+(const Vertex& other) const | 
|    110 { | 
   110 { | 
|    111 	Vertex result (*this); | 
   111 	Vertex result(*this); | 
|    112 	result += other; | 
   112 	result += other; | 
|    113 	return result; | 
   113 	return result; | 
|    114 } | 
   114 } | 
|    115  | 
   115  | 
|    116 Vertex& Vertex::operator*= (qreal scalar) | 
   116 Vertex& Vertex::operator*= (qreal scalar) | 
|    117 { | 
   117 { | 
|    118 	setX (x() * scalar); | 
   118 	setX(x() * scalar); | 
|    119 	setY (y() * scalar); | 
   119 	setY(y() * scalar); | 
|    120 	setZ (z() * scalar); | 
   120 	setZ(z() * scalar); | 
|    121 	return *this; | 
   121 	return *this; | 
|    122 } | 
   122 } | 
|    123  | 
   123  | 
|    124 bool Vertex::operator< (const Vertex& other) const | 
   124 bool Vertex::operator<(const Vertex& other) const | 
|    125 { | 
   125 { | 
|    126 	if (x() != other.x()) return x() < other.x(); | 
   126 	if (x() != other.x()) return x() < other.x(); | 
|    127 	if (y() != other.y()) return y() < other.y(); | 
   127 	if (y() != other.y()) return y() < other.y(); | 
|    128 	if (z() != other.z()) return z() < other.z(); | 
   128 	if (z() != other.z()) return z() < other.z(); | 
|    129 	return false; | 
   129 	return false; | 
|    130 } | 
   130 } | 
|    131  | 
   131  | 
|    132 // ============================================================================= | 
   132 // ============================================================================= | 
|    133 // | 
   133 // | 
|    134 Matrix::Matrix (double vals[]) | 
   134 Matrix::Matrix(double vals[]) | 
|    135 { | 
   135 { | 
|    136 	for (int i = 0; i < 9; ++i) | 
   136 	for (int i = 0; i < 9; ++i) | 
|    137 		m_vals[i] = vals[i]; | 
   137 		m_vals[i] = vals[i]; | 
|    138 } | 
   138 } | 
|    139  | 
   139  | 
|    140 // ============================================================================= | 
   140 // ============================================================================= | 
|    141 // | 
   141 // | 
|    142 Matrix::Matrix (double fillval) | 
   142 Matrix::Matrix(double fillval) | 
|    143 { | 
   143 { | 
|    144 	for (int i = 0; i < 9; ++i) | 
   144 	for (int i = 0; i < 9; ++i) | 
|    145 		m_vals[i] = fillval; | 
   145 		m_vals[i] = fillval; | 
|    146 } | 
   146 } | 
|    147  | 
   147  | 
|    148 // ============================================================================= | 
   148 // ============================================================================= | 
|    149 // | 
   149 // | 
|    150 Matrix::Matrix (const std::initializer_list<double>& vals) | 
   150 Matrix::Matrix(const std::initializer_list<double>& vals) | 
|    151 { | 
   151 { | 
|    152 	if (vals.size() == 9) | 
   152 	if (vals.size() == 9) | 
|    153 		memcpy (&m_vals[0], vals.begin(), sizeof m_vals); | 
   153 		memcpy(&m_vals[0], vals.begin(), sizeof m_vals); | 
|    154 } | 
   154 } | 
|    155  | 
   155  | 
|    156 // ============================================================================= | 
   156 // ============================================================================= | 
|    157 // | 
   157 // | 
|    158 void Matrix::dump() const | 
   158 void Matrix::dump() const | 
|    159 { | 
   159 { | 
|    160 	for (int i = 0; i < 3; ++i) | 
   160 	for (int i = 0; i < 3; ++i) | 
|    161 	{ | 
   161 	{ | 
|    162 		for (int j = 0; j < 3; ++j) | 
   162 		for (int j = 0; j < 3; ++j) | 
|    163 			print ("%1\t", m_vals[i * 3 + j]); | 
   163 			print("%1\t", m_vals[i * 3 + j]); | 
|    164  | 
   164  | 
|    165 		print ("\n"); | 
   165 		print("\n"); | 
|    166 	} | 
   166 	} | 
|    167 } | 
   167 } | 
|    168  | 
   168  | 
|    169 // ============================================================================= | 
   169 // ============================================================================= | 
|    170 // | 
   170 // | 
|    207  | 
   207  | 
|    208 // ============================================================================= | 
   208 // ============================================================================= | 
|    209 // | 
   209 // | 
|    210 Matrix& Matrix::operator= (const Matrix& other) | 
   210 Matrix& Matrix::operator= (const Matrix& other) | 
|    211 { | 
   211 { | 
|    212 	memcpy (&m_vals[0], &other.m_vals[0], sizeof m_vals); | 
   212 	memcpy(&m_vals[0], &other.m_vals[0], sizeof m_vals); | 
|    213 	return *this; | 
   213 	return *this; | 
|    214 } | 
   214 } | 
|    215  | 
   215  | 
|    216 // ============================================================================= | 
   216 // ============================================================================= | 
|    217 // | 
   217 // | 
|    218 double Matrix::getDeterminant() const | 
   218 double Matrix::getDeterminant() const | 
|    219 { | 
   219 { | 
|    220 	return (value (0) * value (4) * value (8)) + | 
   220 	return (value(0) * value(4) * value(8)) + | 
|    221 		   (value (1) * value (5) * value (6)) + | 
   221 		  (value(1) * value(5) * value(6)) + | 
|    222 		   (value (2) * value (3) * value (7)) - | 
   222 		  (value(2) * value(3) * value(7)) - | 
|    223 		   (value (2) * value (4) * value (6)) - | 
   223 		  (value(2) * value(4) * value(6)) - | 
|    224 		   (value (1) * value (3) * value (8)) - | 
   224 		  (value(1) * value(3) * value(8)) - | 
|    225 		   (value (0) * value (5) * value (7)); | 
   225 		  (value(0) * value(5) * value(7)); | 
|    226 } | 
   226 } | 
|    227  | 
   227  | 
|    228 // ============================================================================= | 
   228 // ============================================================================= | 
|    229 // | 
   229 // | 
|    230 bool Matrix::operator== (const Matrix& other) const | 
   230 bool Matrix::operator== (const Matrix& other) const | 
|    231 { | 
   231 { | 
|    232 	for (int i = 0; i < 9; ++i) | 
   232 	for (int i = 0; i < 9; ++i) | 
|    233 	{ | 
   233 	{ | 
|    234 		if (value (i) != other[i]) | 
   234 		if (value(i) != other[i]) | 
|    235 			return false; | 
   235 			return false; | 
|    236 	} | 
   236 	} | 
|    237  | 
   237  | 
|    238 	return true; | 
   238 	return true; | 
|    239 } | 
   239 } | 
|    272 	} | 
   272 	} | 
|    273 } | 
   273 } | 
|    274  | 
   274  | 
|    275 // ============================================================================= | 
   275 // ============================================================================= | 
|    276 // | 
   276 // | 
|    277 LDBoundingBox& LDBoundingBox::operator<< (const Vertex& v) | 
   277 LDBoundingBox& LDBoundingBox::operator<<(const Vertex& v) | 
|    278 { | 
   278 { | 
|    279 	calcVertex (v); | 
   279 	calcVertex(v); | 
|    280 	return *this; | 
   280 	return *this; | 
|    281 } | 
   281 } | 
|    282  | 
   282  | 
|    283 // ============================================================================= | 
   283 // ============================================================================= | 
|    284 // | 
   284 // | 
|    285 LDBoundingBox& LDBoundingBox::operator<< (LDObject* obj) | 
   285 LDBoundingBox& LDBoundingBox::operator<<(LDObject* obj) | 
|    286 { | 
   286 { | 
|    287 	calcObject (obj); | 
   287 	calcObject(obj); | 
|    288 	return *this; | 
   288 	return *this; | 
|    289 } | 
   289 } | 
|    290  | 
   290  | 
|    291 // ============================================================================= | 
   291 // ============================================================================= | 
|    292 // | 
   292 // | 
|    293 void LDBoundingBox::calcVertex (const Vertex& vertex) | 
   293 void LDBoundingBox::calcVertex(const Vertex& vertex) | 
|    294 { | 
   294 { | 
|    295 	m_vertex0.setX (qMin (vertex.x(), m_vertex0.x())); | 
   295 	m_vertex0.setX(qMin(vertex.x(), m_vertex0.x())); | 
|    296 	m_vertex0.setY (qMin (vertex.y(), m_vertex0.y())); | 
   296 	m_vertex0.setY(qMin(vertex.y(), m_vertex0.y())); | 
|    297 	m_vertex0.setZ (qMin (vertex.z(), m_vertex0.z())); | 
   297 	m_vertex0.setZ(qMin(vertex.z(), m_vertex0.z())); | 
|    298 	m_vertex1.setX (qMax (vertex.x(), m_vertex1.x())); | 
   298 	m_vertex1.setX(qMax(vertex.x(), m_vertex1.x())); | 
|    299 	m_vertex1.setY (qMax (vertex.y(), m_vertex1.y())); | 
   299 	m_vertex1.setY(qMax(vertex.y(), m_vertex1.y())); | 
|    300 	m_vertex1.setZ (qMax (vertex.z(), m_vertex1.z())); | 
   300 	m_vertex1.setZ(qMax(vertex.z(), m_vertex1.z())); | 
|    301 	m_isEmpty = false; | 
   301 	m_isEmpty = false; | 
|    302 } | 
   302 } | 
|    303  | 
   303  | 
|    304 // ============================================================================= | 
   304 // ============================================================================= | 
|    305 // | 
   305 // | 
|    306 // Clears the bounding box | 
   306 // Clears the bounding box | 
|    307 // | 
   307 // | 
|    308 void LDBoundingBox::reset() | 
   308 void LDBoundingBox::reset() | 
|    309 { | 
   309 { | 
|    310 	m_vertex0 = Vertex (10000.0, 10000.0, 10000.0); | 
   310 	m_vertex0 = Vertex(10000.0, 10000.0, 10000.0); | 
|    311 	m_vertex1 = Vertex (-10000.0, -10000.0, -10000.0); | 
   311 	m_vertex1 = Vertex(-10000.0, -10000.0, -10000.0); | 
|    312 	m_isEmpty = true; | 
   312 	m_isEmpty = true; | 
|    313 } | 
   313 } | 
|    314  | 
   314  | 
|    315 // ============================================================================= | 
   315 // ============================================================================= | 
|    316 // | 
   316 // |