How to adjust all the Points in the screen using CImg

235 views Asked by At

I have to draw Lines which has bigger double values like (3000.00,4500.45).

CImg<unsigned char> img(800,800,1,3,20);
img.draw_line( 3000.00, 4500.45, 3478.567, 4500.45, RED);

But i want to keep my screen size limited to 800x800

I thought to take Modulus of the Point's coordinates within 800 Like

3000.00%800=600

I can fit 600 in my Screen . But the problem is , CPP does not support modulus of double value .

double a = 3000.00;
printf("%lf",a%800.0); //Expected 600 but exception
**Invalid operand of type double,double to binary operator%**

How can I fit these large points in my screen using CImg ?

2

There are 2 answers

3
bvalabas On BEST ANSWER

All depend on what you want to perform actually :

  • If you just want to see the part of the line drawn on your 800x800 image, then do nothing. The CImg<T>::draw_line() method implements clipping and it will do this automatically for you.
  • If you want to drawn "random" lines on your screen and don't care about the fact that using a modulo on your coordinates will screw up the original line appearance, then you can use a modulo. In your case, it is probably better to first cast your coordinates into int, then use the % operator afterwards :

img.draw_line( ((int)x0)%800, ((int)y0)%800, ((int)x1)%800, ((int)y1)%800, RED);

but be aware that the line that will be drawn has nothing to do with the original line: doing modulos is not a clipping method for drawing lines.

0
Grijesh Chauhan On

Operand of % remainder operator can't be double (or float) use fmod (double numer, double denom) function instead.