Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rhoThetaToImageMaxMinLine(const double rho,double theta,number& x1, number& y1,number& x2,number& y2) {
- const double x_orig_mid = rho * std::cos(theta + M_PI);
- const double y_orig_mid = rho * std::sin(theta + M_PI);
- int x = (this->width / 2)+(x_orig_mid);
- int y = (this->height / 2)+(y_orig_mid);
- int top,right,bottom,left = 0;
- top = x + ceil(y * std::tan( theta ) );
- right = y + ceil(int(this->width - x) * std::tan( theta - (M_PI / 2) ));
- bottom = x - floor(int(this->height - y) * std::tan( theta - M_PI ));
- left = y - floor(x * std::tan( theta - ((M_PI) + (M_PI / 2)) ) );
- this->height--;
- this->width--;//why is this necessary??
- if ( top >= 0 && top <= this->width ) {
- x1 = top;
- y1 = 0;
- if ( right >= 0 && right <= this->height ) {
- x2 = this->width;
- y2 = right;
- } else {
- if ( bottom < 0 ) {
- x2 = 0;
- y2 = left;
- } else {
- x2 = bottom;
- y2 = this->height;
- }
- }
- #ifdef DEBUGON
- std::cout << "top" << std::endl;
- #endif
- }
- if ( right >= 0 && right <= this->height ) { //three quaters
- x1 = this->width;
- y1 = right;
- if ( bottom >= 0 && bottom <= this->width ) {
- x2 = bottom;
- y2 = this->height;
- } else {
- if ( left < 0 ) {
- x2 = top;
- y2 = 0;
- } else {
- x2 = 0;
- y2 = left;// + 1;//This gives pixel perfect lines as a result from rouding.
- }
- }
- #ifdef DEBUGON
- std::cout << "right" << std::endl;
- #endif
- }
- if ( bottom >= 0 && bottom <= this->width ) {
- x1 = bottom;
- y1 = this->height;
- if ( left >= 0 && left <= this->height ) {
- x2 = 0;
- y2 = left;
- } else {
- if ( top > this->width ) {
- x2 = this->width;
- y2 = right ; //+1 else a but arises at rho:245 theta:3.67683 x1:568 y1:767 x2:1023 y2:4294967295
- } else {
- x2 = top;
- y2 = 0;
- }
- }
- #ifdef DEBUGON
- std::cout << "bottom" << std::endl;
- #endif
- }
- if ( left >= 0 && left <= this->height ) {
- x1 = 0;
- y1 = left;// - 1;//This gives pixel perfect lines as a result from rouding errors.
- if ( top >= 0 && top <= this->width ) {
- x2 = top;
- y2 = 0;
- } else {
- if ( right > this->height ) {
- x2 = bottom;
- y2 = this->height;
- } else {
- x2 = this->width;
- y2 = right;
- }
- }
- #ifdef DEBUGON
- std::cout << "left" << std::endl;
- #endif
- }
- if (x2 > this->height ) {
- x2 = this->height - 1;
- }
- this->height++;
- this->width++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement