I have a square-shape zone described by some conditions as follows:
x < b && x >= a && y < d && y >= c
I would like to extract the top-right and bottom-left corners coordinates. (Let's assume that the whole condition is given in $cond. Also, store the pairs in two lists @xy_b
and @xy_t
). For this example: @xy_b = (a , c)
and @xy_t = (b, d)
.
REMARKS
- The order of conditiones might be scrambled (e.g.
y < d && x >= a && x < d && y >= c
). - Expect both
x < a
anda > x
- There is no condition like
b =< x < a
. - Expect conditions like:
x <= b && x >= a
orx < b && x > a
(treat them the same unless you have a better convention to distinguish the,). Expect some or all of the conditions may be missed. If one of the conditions is issued it should be consider correspondingly zero or infinity. For example in the following condition set:
x < b && x >= a && y >= c
the upper limit for y
must be infinity. If the lower limit is missing, it should be considered zero.
It would be very easy to over complicate this problem.
However, the following is a proof of concept that attempts to break this down into the simplest regular expressions.
Here is the code that demonstrates this logic:
Outputs: