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); std::swap(this->m33, other.m33); std::swap(this->m34, other.m34);
} }
float* TransformationMatrix::matrix3x4f() float* TransformationMatrix::matrix3x4f() const
{ {
float out_arr[12]; float out_arr[12];
out_arr[0] = this->m11; out_arr[1] = this->m12; out_arr[2] = this->m13; out_arr[3] = this->m14; 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; return out_arr;
} }
double TransformationMatrix::determinante() double TransformationMatrix::determinante() const
{ {
// translation elements don't influence the determinante // translation elements don't influence the determinante
// because of the 0s on the other side of main diagonal // 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); 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 // from http://mathworld.wolfram.com/MatrixInverse.html
// and https://math.stackexchange.com/questions/152462/inverse-of-transformation-matrix // and https://math.stackexchange.com/questions/152462/inverse-of-transformation-matrix
TransformationMatrix mat; TransformationMatrix mat;
double det = this->determinante(); double det = this->determinante();
if (abs(det) < 1e-9) if (abs(det) < 1e-9)
{
inverse = &mat;
return false; return false;
}
double fac = 1.0 / det; double fac = 1.0 / det;
mat.m11 = fac*(this->m22*this->m33 - this->m23*this->m32); 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 /// Return the row-major form of the represented transformation matrix
/// for admesh transform /// for admesh transform
float * matrix3x4f(); float * matrix3x4f() const;
/// Return the determinante of the matrix /// Return the determinante of the matrix
double determinante(); double determinante() const;
/// Returns the inverse of the matrix /// Returns the inverse of the matrix
bool inverse(TransformationMatrix * inverse); bool inverse(TransformationMatrix * inverse) const;
/// Perform Translation /// Perform Translation
void translate(double x, double y, double z); void translate(double x, double y, double z);

View File

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