determine padding for inner ranges on a number line

Multi tool use
Multi tool use


determine padding for inner ranges on a number line



I have a range, which is .1 to .75. Within that range is a subrange of .13 to .74.



Within the range, the subrange takes up ~93.8% of the space.



The left side 'padding' of the subrange within the range takes up ~4.6% and the right side 'padding' ~1.5%.



I need to ensure there is at least 5% 'padding' on both sides of the subrange by expanding the range (not reducing the size of the inner range). How to go about quickly determining what the enlarged extents of the range should be?



What if the inner range was [.5, .74] so that only the right side of the outer range needs to be enlarged to achieve minimum 5% padding of the inner range?



not homework :-)





the outer range should expand so that there is at least 5% of the outer range's length padding both sides of the inner range.
– jedierikb
Jul 3 at 16:42




1 Answer
1



Simple logic (edited after question correction):


Given: RangeLeft, RangeRight, SubLeft, SubRight
MinPadding = (SubRight - SubLeft) * 5 / 90
NewLeft = Min(RangeLeft, SubLeft - MinPadding)
NewRight = Max(RangeRight, SubRight + MinPadding)]





Thanks, but subLeft and subRight cannot be changed. Need to expand the outer range instead.
– jedierikb
Jul 3 at 13:34





It was not stated clearly (yes, I saw some inconsistency in the question)
– MBo
Jul 3 at 15:51





Look at edit...
– MBo
Jul 3 at 15:57





sorry for unclear op. codepen.io/jedierikb/pen/vrMEEV works when both or neither inner values are close to the outer values, but fails when one of the inner ranges is close and the other is not (for example, if sr = 0.54). suggestions?
– jedierikb
Jul 3 at 16:54





This approach gives at least 5% of subrange on both sides
– MBo
Jul 3 at 17:40






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

5iKqCAKJARW,qeW
g7v124xqSLB,VIR,UN7u

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications