So lets say I have a line ‘s’ from value ‘s0’ to value ‘s1’
s0|--------------------------------------------------------------------|s1
Now I have a range on that line we will call it ‘a’ which also has a start and end a0-a1. The values for a0 and a1 where calculated from a center point of the range and a width.
Which lets say is placed here:
s0|------------------a0|--------------------------------|a1------------|s1
Now let’s say I have a second range ‘b’ which all we are givin is the centerpoint we will call ‘bC’ and the width of the range we will call ‘bW’.
What would be the fastest way to determine if this range ‘b’ can be placed on line ‘s’ with no ranges overlapping, with this process being repeated to additional range ‘c’, ‘d’, ‘e’ etc…
I was thinking have an array
s = [0,100]
and then if I add a range it would be
rC = 50
rW = 50
for(let p=0; p<s.length; p+=2){
let a = [p]
let b = [p+1]
let c = rC-(rW*0.5)
let d = rC+(rW*0.5)
if(a<c && b>d){
s.splice(p,0, c, d)
}
}
but then how do I know an area is a range and not an opening…
anyone else have any ideas?
then if they do overlap, how would I test if I can offset them by the overlap and then see if they are a valid placement.