/* check whether a/b is a valid approximation */ static inline uint32_t matches(uint32_t a, uint32_t b, uint32_t alpha_num, uint32_t d_num, uint32_t denum) { if (less_or_equal(a, b, alpha_num - d_num, denum)) return 0; if (less(a ,b, alpha_num + d_num, denum)) return 1; return 0; }
bool is_point_inside_triangle(const Point &point, const Triangle &triangle) { // TODO: check whether the point is in the same plane as triangle. // By now this function returns true if the _projection_ of the point is inside triangle const Vector u = triangle[1] - triangle[0]; const Vector v = triangle[2] - triangle[0]; const Vector r = point - triangle[0]; // find components of r along u and v const double determinant = (u*u)*(v*v) - (u*v)*(u*v); check( determinant != 0, DegeneratedTriangleError() ); const double ru = ( (r*u)*(v*v) - (u*v)*(r*v) ) / determinant; const double rv = ( (u*u)*(r*v) - (r*u)*(u*v) ) / determinant; return greater_or_equal( ru, 0 ) && greater_or_equal( rv, 0 ) && less_or_equal( ru + rv, 1 ); }
int kthSmallest(vector<vector<int>>& matrix, int k) { if (matrix.empty() || matrix[0].empty()) { return 0; } int m = matrix.size(), n = matrix[0].size(); int low = matrix[0][0], high = matrix[m-1][n-1]; while (low <= high) { int mid = low + (high - low) / 2; int count = less_or_equal(matrix, mid); if (count < k) low = mid + 1; else high = mid - 1; } return low; }
std::pair<std::vector<int>, std::vector<int>> divide(std::vector<int> a, const std::vector<int>& b) { std::vector<int> res; if (a.size() >= b.size()) res.resize(a.size() - b.size() + 1); else res.resize(a.size()); for (int i = i = res.size() - 1; i >= 0; i--) { int c = -1; while (less_or_equal(multiply(b, c + 1), a, i)) c++; res[i] = c; a = minus(a, multiply(b, c), i); //a = delete_leading_zeros(a); } return std::make_pair(res, a); }
Matrix & Matrix::diagonalize(int rotations_count, /*out*/ Matrix & transformation, Real precision /*=DEFAULT_REAL_PRECISION*/) { static const size_t OFF_DIAGONAL_ITEMS_COUNT = VECTOR_SIZE*(VECTOR_SIZE - 1)/2; static const int off_diagonal_items[OFF_DIAGONAL_ITEMS_COUNT] = { element_index(0,1), element_index(0,2), element_index(1, 2) }; transformation = Matrix::IDENTITY; for (int iter = 0; iter < rotations_count; ++iter) { Real max = -1; for (int i = 0; i < OFF_DIAGONAL_ITEMS_COUNT; ++i) { Real a = fabs(get_at_index(off_diagonal_items[i])); if (max < 0 || a > max) { max = a; } } if (less_or_equal(max, 0, precision)) { return *this; } do_jacobi_rotation((iter + 1) % VECTOR_SIZE, (iter + 2) % VECTOR_SIZE, transformation); } return *this; }
/** * \brief Less than or equal to operator. */ friend bool operator<= (Parent const& lhs, Parent const& rhs) { return less_or_equal(lhs, rhs); }
// Returns true, if first point is between second and third bool is_point_between(const Point &inner_point, const Point &outer_point1, const Point &outer_point2) { const double squared_length = (outer_point2 - outer_point1).sqared_norm(); return ( less_or_equal( (inner_point - outer_point1).sqared_norm(), squared_length ) && less_or_equal( (outer_point2 - inner_point).sqared_norm(), squared_length ) ); }
bool String::operator<=(CVarRef v) const { return less_or_equal(m_px, v); }
bool String::operator<=(litstr v) const { return less_or_equal(m_px, v); }
/** * \brief Less than or equal to operator. */ FRAMEWORK_ALWAYS_INLINE friend bool operator<= (Parent const& lhs, Parent const& rhs) { return less_or_equal(lhs, rhs); }