Jump to content
  • Advertisement
Sign in to follow this  
irreversible

rounding slice distribution by percentage

This topic is 3046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having some trouble coming up with a way that would accomplish the following:

I have n slices whose ratios total 100%
I can adjust any border between two adjacent slices
I want to snap either one or both of the slices that are being adjusted with 1% accuracy

The procedure seems easy enough:

1) convert the slice border from pixel position to the respective percentage value for both slices
2) snap both slices to 1%
3) choose the one that has a smaller snap difference as the primary and ignore the other
4) convert the snapped position back to pixel coordinates
5) profit

Problem is: there can be any number of slices in the set whose total ratios always amount to 100%; as such I think I need to compensate for the change in the two slices to make the snap work. I'm not sure how to do this. Since I'm pretty sure the code is correct, I'm stuck looking at a logic failure. Unfortunately, I can't figure it out on my own... So any ideas or pointers would be awesome!

Share this post


Link to post
Share on other sites
Advertisement
Ah, I was looking at this from a whole wrong perspective. Figured it out now. Since the code/solution is kind of confusing without knowing the context I won't post it, but if anyone's interested, just let me know!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!