Live data from Hacker News

Drawing a circle, point-by-point, without floating point support

yurichev.com

21–30 of 42 posts

Re: Drawing a circle, point-by-point, without floating point support

#21
post #3

> It requires only additions, subtractions and bit shifts: 2x is the same as x Does any of this mean anything in JS, where AFAIK there are no real ints? 2x is an fpu operation under the hood, and not a bit shift.

Funny enough JavaScript now has BigInt, which is purely integer:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re: Drawing a circle, point-by-point, without floating point support

#23

Earlier quoted context omitted.

Actually that book is paywalled now. It's been somewhat of a controversy that people contributed to the book thinking it was a community resource but now it's unavailable.

wow. although the last time he updated the (singular) username and password was october. i think people could just ask around for it. still, controversial indeed. Weirdly, the book itself says: > Q: May I print this book / use it for teaching? > A: Of course! That’s why the book is licensed under the Creative Commons license (CC BY-SA 4.0) So it would be legal for anyone else to host this.

I found a few versions which are hosted elsewhere:

2017 https://mirrors.ocf.berkeley.edu/parrot/misc/openbooks/progr...

2018 http://ebook.pldworld.com/_eBook/Reverse%20Engineering%20for...

In addition, some foreign languages still seem to be available:

French https://beginners.re/RE4B-FR.pdf

German https://beginners.re/RE4B-DE.pdf

Italian https://beginners.re/RE4B-IT.pdf

Japanese https://beginners.re/RE4B-JA.pdf

Polish https://beginners.re/RE4B-PL.pdf

Re: Drawing a circle, point-by-point, without floating point support

#24
post #8
post #5

You can always try Bresenham’s circle drawing algorithm.

Back in the '80s in Bulgaria, I was only able to find the Bresenham's algorithm for circles, but needed to draw an ellipse (in 6052 assembly, well, machine code), and was so proud that I manage to do it.

The lessons you learn on your own stick the best, don't they?

I remember a similar "heureka" moment when I derived a line-drawing algorithm that respected "subpixel" starting and ending points. That is, don't assume a line starts/ends in the middle of a pixel (like most algos do), but rather at an arbitrary point.

I forgot why I needed this (something to do with near-axis-aligned polygon slopes not looking right on a highly rasterized problem). But I do remember the elation when I finally got it to work :-) Also early 1990s, no internet and no English for extra fun.

Re: Drawing a circle, point-by-point, without floating point support

#25
post #21
post #3

> It requires only additions, subtractions and bit shifts: 2x is the same as x Does any of this mean anything in JS, where AFAIK there are no real ints? 2x is an fpu operation under the hood, and not a bit shift.

Funny enough JavaScript now has BigInt, which is purely integer: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

It also has typed arrays (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Type...), but you can’t calculate with those values (you write floats into them that get rounded to integers, and values conceptually become floats when you read them)

WebAssembly has i32 and i64.

Re: Drawing a circle, point-by-point, without floating point support

#26
post #3

> It requires only additions, subtractions and bit shifts: 2x is the same as x Does any of this mean anything in JS, where AFAIK there are no real ints? 2x is an fpu operation under the hood, and not a bit shift.

JS VMs have real ints (and you can summon them smi reliably usually with |0 ), but you're very much better off calling into some browser capability that will leverage the gpu most of the time.

Re: Drawing a circle, point-by-point, without floating point support

#27
post #19

Earlier quoted context omitted.

This is the era where prior art doesn't exist. Why read a book when you can blog about discovering "something new". I could probably make a killing blogging about my "discovery" of the algorithms in the book "Hacker's Delight".

This always blows my mind - for the first time in human history we live in a world where almost all prior art is relatively easily discoverable, and people don't even bother. I guess I shouldn't be surprised, after all, I've met a lot of people.

The sheer weight of information can make it harder to find. Also, nobody gets paid for being the prior art.

Re: Drawing a circle, point-by-point, without floating point support

#28
post #15

Earlier quoted context omitted.

I think, using the `(…) | 0` (expression binary ORed with zero) construct most JS engines will use true integers in optimized code.

In fact, the specification even guarantees that for all the bitwise operators.

However, this is relatively new and there may still be some legacy engines around.

Re: Drawing a circle, point-by-point, without floating point support

#30
post #27
post #19

Earlier quoted context omitted.

This always blows my mind - for the first time in human history we live in a world where almost all prior art is relatively easily discoverable, and people don't even bother. I guess I shouldn't be surprised, after all, I've met a lot of people.

The sheer weight of information can make it harder to find. Also, nobody gets paid for being the prior art.

Finding the prior art pays you back the time you’d have spent repeating the same mistakes, though.
Post reply on HN