// Returns the direction of the fitted line as a unit vector, using the // least mean squared perpendicular distance. The line runs through the // mean_point, i.e. a point p on the line is given by: // p = mean_point() + lambda * vector_fit() for some real number lambda. // Note that the result (0<=x<=1, -1<=y<=-1) is directionally ambiguous // and may be negated without changing its meaning. FCOORD LLSQ::vector_fit() const { double x_var = x_variance(); double y_var = y_variance(); double covar = covariance(); FCOORD result; if (x_var >= y_var) { if (x_var == 0.0) return FCOORD(0.0f, 0.0f); result.set_x(x_var / sqrt(x_var * x_var + covar * covar)); result.set_y(sqrt(1.0 - result.x() * result.x())); } else { result.set_y(y_var / sqrt(y_var * y_var + covar * covar)); result.set_x(sqrt(1.0 - result.y() * result.y())); } if (covar < 0.0) result.set_y(-result.y()); return result; }
void POLY_BLOCK::rotate(FCOORD rotation) { FCOORD pos; //current pos; ICOORDELT *pt; //current point ICOORDELT_IT pts = &vertices; //iterator do { pt = pts.data (); pos.set_x (pt->x ()); pos.set_y (pt->y ()); pos.rotate (rotation); pt->set_x ((inT16) (floor (pos.x () + 0.5))); pt->set_y ((inT16) (floor (pos.y () + 0.5))); pts.forward (); } while (!pts.at_first ()); compute_bb(); }