Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast may be needed #411

Open
scuniff opened this issue Dec 7, 2023 · 3 comments
Open

Cast may be needed #411

scuniff opened this issue Dec 7, 2023 · 3 comments

Comments

@scuniff
Copy link

scuniff commented Dec 7, 2023

In file:

Regarding this code:

        int sizeX = rl.width;
	int sizeY = rl.height;
	double vx = sizeX/d.width;
	double vy = sizeY/d.height;
	int x = (int) (vx*region.x);
	int y = (int) (vy*region.y);

As is, the division is being done in integer precision.
If double precision is really wanted then sizeX and sizeY need to be cast to double:

	int sizeX = rl.width;
	int sizeY = rl.height;
	double vx = (double)sizeX/d.width;
	double vy = (double)sizeY/d.height;
	int x = (int) (vx*region.x);
	int y = (int) (vy*region.y);

Example snippet:

       double d;
	
	int a=5;
	int b = 2;

	d = a/b;		
	System.out.println("no cast, d is " + d);
			
	d = (double) a/b;
	System.out.println("with cast, d is " + d);

Output:

no cast, d is 2.0
with cast, d is 2.5

@dominikl
Copy link
Member

I don't think this matters. Close?

@scuniff
Copy link
Author

scuniff commented Dec 26, 2023

Sounds ok to me .

I did though look into the code some and got a basic understanding.
The following example shows what the width of the new rectangle would be with and without double precision.

Referring to lines 130 – 138 and just focusing on the width calculation:

	Dimension d = birdEyeView.getImageSize();
	Rectangle rl = canvas.getBounds();
	int sizeX = rl.width;
	int sizeY = rl.height;
	double vx = sizeX/d.width;
	double vy = sizeY/d.height;
	int x = (int) (vx*region.x);
	int y = (int) (vy*region.y);
	int w = (int) (vx*region.width);

Assume:

Canvas is 500x500
Image is 260x260
Region is 200x200

Then……

sizeX=500 // canvas
d.width = 260 // image

then vx would be:
double vx = sizeX/d.width;

vx = 1.9 // double precsion
vx=1 // int precision

Assume:
region.width=200

then width of new Rectangle would be:
int w = (int) (vx*region.width);

w = 380 // with double precision
w = 200 // with int precision

Is this difference between the 2 precisions ok??

@scuniff scuniff closed this as completed Dec 26, 2023
@scuniff scuniff reopened this Dec 26, 2023
@scuniff
Copy link
Author

scuniff commented Dec 26, 2023

Sorry, closed this by accident....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants