For example I have 4 sets of Coordinates
(1,1)
(1,3)
(3,3)
(3,1)
It's the out line of a Square Shape
Is there a way I can find the list of sets of Coordinates on it's parameter?
The expected out put should be:
(1,2)
(2,1)
(2,3)
(3,2)
and is there a way I can find the list of sets of Coordinates within the Shape?
The expected out put should be:
(2,2)
Note that the set of coordinates I used isn't Array
but I declared them individually int x1 x2 x3 x4 y1 y2 y3 y4
I've come out with something like this:
if (s[x].getPX1() == s[x].getPX2())
{
if (s[x].getPY1() < s[x].getPY2())
{
int yy = s[x].getPY1()+1;
for (yy;yy < s[x].getPY2();yy++)
{
cout << "(" << s[x].getPX1() << ", " << yy << ")" <<endl;
}
}
else if (s[x].getPY1() > s[x].getPY2())
{
int yy = s[x].getPY2()+1;
for (yy;yy < s[x].getPY1();yy++)
{
cout << "(" << s[x].getPX1() << ", " << yy << ")" <<endl;
}
}
if (s[x].getPX2() < s[x].getPX3())
{
int xx = s[x].getPX2()+1;
for (xx; xx < s[x].getPX3(); xx++)
{
cout << "(" << xx << ", " << s[x].getPY2() << ")" <<endl;
}
}
else if (s[x].getPX2() > s[x].getPX3())
{
int xx = s[x].getPX3()+1;
for (xx; xx < s[x].getPX2(); xx++)
{
cout << "(" << xx << ", " << s[x].getPY2() << ")" <<endl;
}
}
if (s[x].getPY3() < s[x].getPY4())
{
int yy2 = s[x].getPY3()+1;
for (yy2; yy2 < s[x].getPY4(); yy2++)
{
cout << "(" << s[x].getPX3() << ", " << yy2 << ")" <<endl;
}
}
else if (s[x].getPY3() > s[x].getPY4())
{
int yy2 = s[x].getPY4()+1;
for (yy2; yy2 < s[x].getPY3(); yy2++)
{
cout << "(" << s[x].getPX3() << ", " << yy2 << ")" <<endl;
}
}
if (s[x].getPX4() < s[x].getPX1())
{
int xx2 = s[x].getPX4()+1;
for (xx2; xx2 < s[x].getPX1(); xx2++)
{
cout << "(" << xx2 << ", " << s[x].getPY4() << ")" <<endl;
}
}
else if (s[x].getPX4() > s[x].getPX1())
{
int xx2 = s[x].getPX1()+1;
for (xx2; xx2 < s[x].getPX4(); xx2++)
{
cout << "(" << xx2 << ", " << s[x].getPY4() << ")" <<endl;
}
}
}
It's kinda inefficient this way. Is there a better way to handle this?
Note that the code isn't even completed yet, the part just handle only if user input the "Vertical" coordinates first, I'll still have to come out with the "Horizontal" coordinates first scenario.
The coordinates will be input in an ordered sequence, but will not restrict where to begin.
Any help will be appreciated!
Thanks in advance!