int factor(mpz_t x_1, mpz_t x_2, mpz_t d, mpz_t n, mpz_t tmp, mpz_t *factors) { int num_factors = 0; while (IS_ONE(n) != 0 && IS_PRIME(n) == 0) { /*pollard(x_1, x_2, d, n, 2, 1, MAX_NUMBER_OF_TRIES);*/ pollard_brent(x_1, x_2, d, n, 2, 3, MAX_NUMBER_OF_TRIES); if(FAILED(d)) { return 0; } while (IS_ONE(d) != 0 && IS_PRIME(d) == 0) { /*pollard(x_2, x_2, tmp, d, 2, 1, MAX_NUMBER_OF_TRIES);*/ pollard_brent(x_1, x_2, d, n, 2, 3, MAX_NUMBER_OF_TRIES); if(FAILED(tmp)) { return 0; } mpz_set(d, tmp); } do { ADD_FACTOR(factors, num_factors, d); mpz_divexact(n, n, d); } while (mpz_divisible_p(n, d)); } if(IS_ONE(n) != 0) { ADD_FACTOR(factors, num_factors, n); } return num_factors; }
// whether the matrix have scale factor bool Matrix::HasScale() const { float l0 = Vector( m[0] , m[4] , m[8] ).Length(); float l1 = Vector( m[1] , m[5] , m[9] ).Length(); float l2 = Vector( m[2] , m[6] , m[7] ).Length(); #define IS_ONE(x) ((x)>0.999f && (x)<1.001f ) return !( IS_ONE(l0) && IS_ONE(l1) && IS_ONE(l2) ); #undef IS_ONE }
Point Transform::operator()(const Point& p) const { float tpX = m.m[0][0] * p.x + m.m[0][1] * p.y + m.m[0][2] * p.z + m.m[0][3]; float tpY = m.m[1][0] * p.x + m.m[1][1] * p.y + m.m[1][2] * p.z + m.m[1][3]; float tpZ = m.m[2][0] * p.x + m.m[2][1] * p.y + m.m[2][2] * p.z + m.m[2][3]; float tpW = m.m[3][0] * p.x + m.m[3][1] * p.y + m.m[3][2] * p.z + m.m[3][3]; if (IS_ONE(tpW)) return Point(tpX, tpY, tpZ); else { return Point(tpX, tpY, tpZ) / tpW; } }