Making functions constant and the entries double precision

This commit is contained in:
Oekn5w 2018-06-29 17:57:13 +02:00 committed by Joseph Lenox
parent 418719cfb9
commit a2e8aca4c4
3 changed files with 62 additions and 60 deletions

View File

@ -68,7 +68,7 @@ void TransformationMatrix::swap(TransformationMatrix &other)
std::swap(this->m33, other.m33); std::swap(this->m34, other.m34);
}
float* TransformationMatrix::matrix3x4f()
float* TransformationMatrix::matrix3x4f() const
{
float out_arr[12];
out_arr[0] = this->m11; out_arr[1] = this->m12; out_arr[2] = this->m13; out_arr[3] = this->m14;
@ -77,21 +77,24 @@ float* TransformationMatrix::matrix3x4f()
return out_arr;
}
double TransformationMatrix::determinante()
double TransformationMatrix::determinante() const
{
// translation elements don't influence the determinante
// because of the 0s on the other side of main diagonal
return m11*(m22*m33 - m23*m32) - m12*(m21*m33 - m23*m31) + m13*(m21*m32 - m31*m22);
}
bool TransformationMatrix::inverse(TransformationMatrix* inverse)
bool TransformationMatrix::inverse(TransformationMatrix* inverse) const
{
// from http://mathworld.wolfram.com/MatrixInverse.html
// and https://math.stackexchange.com/questions/152462/inverse-of-transformation-matrix
TransformationMatrix mat;
double det = this->determinante();
if (abs(det) < 1e-9)
{
inverse = &mat;
return false;
}
double fac = 1.0 / det;
mat.m11 = fac*(this->m22*this->m33 - this->m23*this->m32);

View File

@ -27,13 +27,13 @@ public:
/// Return the row-major form of the represented transformation matrix
/// for admesh transform
float * matrix3x4f();
float * matrix3x4f() const;
/// Return the determinante of the matrix
double determinante();
double determinante() const;
/// Returns the inverse of the matrix
bool inverse(TransformationMatrix * inverse);
bool inverse(TransformationMatrix * inverse) const;
/// Perform Translation
void translate(double x, double y, double z);

View File

@ -6,60 +6,59 @@
%}
%name{Slic3r::TransformationMatrix} class TransformationMatrix {
TransformationMatrix();
~TransformationMatrix();
Clone<TransformationMatrix> clone()
%code{% RETVAL = THIS; %};
TransformationMatrix();
~TransformationMatrix();
Clone<TransformationMatrix> clone()
%code{% RETVAL = THIS; %};
float m11;
%code%{ RETVAL = THIS->m11; %}
void set_m11(float value)
%code%{ THIS->m11 = value; %}
float m12;
%code%{ RETVAL = THIS->m12; %}
void set_m12(float value)
%code%{ THIS->m12 = value; %}
float m13;
%code%{ RETVAL = THIS->m13; %}
void set_m13(float value)
%code%{ THIS->m13 = value; %}
float m14;
%code%{ RETVAL = THIS->m14; %}
void set_m14(float value)
%code%{ THIS->m14 = value; %}
float m21;
%code%{ RETVAL = THIS->m21; %}
void set_m21(float value)
%code%{ THIS->m21 = value; %}
float m22;
%code%{ RETVAL = THIS->m22; %}
void set_m22(float value)
%code%{ THIS->m22 = value; %}
float m23;
%code%{ RETVAL = THIS->m23; %}
void set_m23(float value)
%code%{ THIS->m23 = value; %}
float m24;
%code%{ RETVAL = THIS->m24; %}
void set_m24(float value)
%code%{ THIS->m24 = value; %}
float m31;
%code%{ RETVAL = THIS->m31; %}
void set_m31(float value)
%code%{ THIS->m31 = value; %}
float m32;
%code%{ RETVAL = THIS->m32; %}
void set_m32(float value)
%code%{ THIS->m32 = value; %}
float m33;
%code%{ RETVAL = THIS->m33; %}
void set_m33(float value)
%code%{ THIS->m33 = value; %}
float m34;
%code%{ RETVAL = THIS->m34; %}
void set_m34(float value)
%code%{ THIS->m34 = value; %}
double m11;
%code%{ RETVAL = THIS->m11; %}
void set_m11(double value)
%code%{ THIS->m11 = value; %}
double m12;
%code%{ RETVAL = THIS->m12; %}
void set_m12(double value)
%code%{ THIS->m12 = value; %}
double m13;
%code%{ RETVAL = THIS->m13; %}
void set_m13(double value)
%code%{ THIS->m13 = value; %}
double m14;
%code%{ RETVAL = THIS->m14; %}
void set_m14(double value)
%code%{ THIS->m14 = value; %}
double m21;
%code%{ RETVAL = THIS->m21; %}
void set_m21(double value)
%code%{ THIS->m21 = value; %}
double m22;
%code%{ RETVAL = THIS->m22; %}
void set_m22(double value)
%code%{ THIS->m22 = value; %}
double m23;
%code%{ RETVAL = THIS->m23; %}
void set_m23(double value)
%code%{ THIS->m23 = value; %}
double m24;
%code%{ RETVAL = THIS->m24; %}
void set_m24(double value)
%code%{ THIS->m24 = value; %}
double m31;
%code%{ RETVAL = THIS->m31; %}
void set_m31(double value)
%code%{ THIS->m31 = value; %}
double m32;
%code%{ RETVAL = THIS->m32; %}
void set_m32(double value)
%code%{ THIS->m32 = value; %}
double m33;
%code%{ RETVAL = THIS->m33; %}
void set_m33(double value)
%code%{ THIS->m33 = value; %}
double m34;
%code%{ RETVAL = THIS->m34; %}
void set_m34(double value)
%code%{ THIS->m34 = value; %}
};