rounding slice distribution by percentage

Started by
0 comments, last by irreversible 13 years, 9 months ago
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!
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!

This topic is closed to new replies.

Advertisement