Hacker News new | past | comments | ask | show | jobs | submit login
The Skyline Problem in Racket (jeapostrophe.github.io)
5 points by soegaard 6 days ago | hide | past | favorite | 4 comments





Ok maybe I'm an idiot but wouldn't the simplest algorithm be

1) Choose highest building. Draw it's roof horizontal only.

2) Repeat 1) choosing building by next height lower, unless lower building roof within range of an existing rendered roof x+width, then exclude that building from rendering.

3) Once all buildings roofs drawn, draw the building side verticals downwards from each until they hit a roof or ground (either from a cache or detecting pixel colour), in which case stop.


How do you efficiently choose the highest building in step 1?

Yes so I see your point, it'd need a pre-sort by height which is a double iteration of the arrays.

> 2) Repeat 1) choosing building by next height lower, unless lower building roof within range of an existing rendered roof x+width, then exclude that building from rendering.

How do you implement the unless-part?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: