Drawing using Integer/Float

Started by Steve Elliott, March 27, 2019, 09:34:15

Previous topic - Next topic

Steve Elliott

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.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Derron

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


Bye
Ron

Steve Elliott

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.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Steve Elliott

#18
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.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Qube

QuoteAGK 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.
Mac Studio M1 Max ( 10 core CPU - 24 core GPU ), 32GB LPDDR5, 512GB SSD,
Beelink SER7 Mini Gaming PC, Ryzen 7 7840HS 8-Core 16-Thread 5.1GHz Processor, 32G DDR5 RAM 1T PCIe 4.0 SSD
MSI MEG 342C 34" QD-OLED Monitor

Until the next time.

Steve Elliott

#20
Quote
Apart from that there are the commands Round, Trunc, Floor and Ceil.

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


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
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

Derron

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

Steve Elliott

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.
Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb