July 21, 2019, 04:23:18 AM

Author Topic: Drawing using Integer/Float  (Read 510 times)

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 1840
Re: Drawing using Integer/Float
« Reply #15 on: March 27, 2019, 06:13:12 PM »
Quote
@ AGK
What happens if you do not use round() (as this is a custom command) but just cast the float to an integer?

Same thing.
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Mojave, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.1, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
Raspbian Buster, pi4 4Gb RAM,1.5Ghz

Offline Derron

  • Hero Member
  • *****
  • Posts: 2218
Re: Drawing using Integer/Float
« Reply #16 on: March 27, 2019, 06:17:14 PM »
Then this would be a bug imho. Or at least something unexpected.


Bye
Ron

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 1840
Re: Drawing using Integer/Float
« Reply #17 on: March 27, 2019, 06:17:39 PM »
Quote
If I draw a black rect-image on a white background using floats then I will see some grayish border around the rectangle when using SDL

I always thought SDL only worked with integers.
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Mojave, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.1, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
Raspbian Buster, pi4 4Gb RAM,1.5Ghz

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 1840
Re: Drawing using Integer/Float
« Reply #18 on: March 27, 2019, 06:23:46 PM »
Quote
@ AGK
What happens if you do not use round() (as this is a custom command) but just cast the float to an integer?

Same thing.

Then this would be a bug imho. Or at least something unexpected.

Not really, like I said anything x.5 and above is correctly rounded up, so 5.5 *is* 6 if you round it up, 5.1 *is* 5 if you round down.  The C++/Blitz Max casting are working at a lower level there.   AGK doesn't have casting as far as I know, you can just pass a float into an integer variable and it will round up or down as I just wrote.
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Mojave, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.1, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
Raspbian Buster, pi4 4Gb RAM,1.5Ghz

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 1961
Re: Drawing using Integer/Float
« Reply #19 on: March 27, 2019, 06:33:37 PM »
Quote
AGK doesn't have casting as far as I know, you can just pass a float into an integer variable and it will round up or down as I just wrote.
Yup, assigning a float value to an integer will just round up / down accordingly. Apart from that there are the commands Round, Trunc, Floor and Ceil.
Until the next time...

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 1840
Re: Drawing using Integer/Float
« Reply #20 on: March 27, 2019, 06:39:44 PM »
Quote
Apart from that there are the commands Round, Trunc, Floor and Ceil.

Aha!  Trunc is the equivalent of casting (and works).

Code: [Select]
fnum As Float
num As Integer

fnum = 2.1 + 0.5      // rounds down eg2)  2.9 + 0.5 rounds up - prints 3
num = Trunc( fnum )
Print( num )          // prints 2
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Mojave, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.1, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
Raspbian Buster, pi4 4Gb RAM,1.5Ghz

Offline Derron

  • Hero Member
  • *****
  • Posts: 2218
Re: Drawing using Integer/Float
« Reply #21 on: March 27, 2019, 07:12:59 PM »
So it seem we kind of gave you some AGK experience points. Level up?


@ float to integer
if it rounds without telling you then I think it is unexpected behaviour. It might be some convenience thing but rounding rules differ according to who you ask (economics, programming, ...).
Nonetheless - we found "trunc" and so you can have your "+0.5" thing working - while we also found out that it seems to not be needed in all cases as you can render at floating point positions.


@ SDL
Yes it might be able to only handle integer positions - but if you just use SDL as "graphics basement" and put your own GL commands on top then you can of course do how you like (this is how Brucey handled in in SDL.mod I think).


bye
Ron

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 1840
Re: Drawing using Integer/Float
« Reply #22 on: March 27, 2019, 07:19:29 PM »
Quote
So it seem we kind of gave you some AGK experience points. Level up?

lol yes AGK was completely new to me, now I'm picking up the language bit by bit.

Quote
@ SDL
Yes it might be able to only handle integer positions - but if you just use SDL as "graphics basement" and put your own GL commands on top then you can of course do how you like (this is how Brucey handled in in SDL.mod I think).

Ah, so I was right.  Thanks to you and Qube for explaining how it was achieved in SDL. I've some experience with SDL/C++ but never liked that limitation.
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Mojave, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.1, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
Raspbian Buster, pi4 4Gb RAM,1.5Ghz