Hello. First time posting on these forums as I am really stuck on my code. The language I am using is GML (Game Maker Language) and the program Game Maker: Studio. As I could not get any help on GM forums I am seeking help elsewhere.

The game I am making is a remake of a retro game called QIX.
"Qix is an old game where you are drawing boxes in order to fill in the screen with a color or image while avoiding enemies. To pass a level you must fill in a certain percentage of the screen. A more modern game series with this gameplay would be the Gals Panic series."
Youtube: http://www.youtube.com/watch?v=nBt4w3qKI6I&feature=player_detailpage#t=32
Wikipedia: http://en.wikipedia.org/wiki/Qix

I have made it work, but the problem is that it is extremely slow. It takes about a minute for larger area to be drawn. What I am doing:
-After the player finishes his move I have an array of the current lines and it adds the new lines that the player just made to the array.
-It takes two points on each side of the first line and checks a line from one point to the QIX. Depending on the lines crossed it calculates which point is in the closed area without the QIX. This can turn out wrong in some cases, not only because the check (if even number of lines crossed, QIX is in the same area) is wrong, but also the way I check if the lines crossing is wrong. Before drawing I fix this by checking if the QIX is on revealed pixel and if yes, I swap all values(explained later). So suggestions on how to check, which side of the line the QIX is on are welcomed too.
-Then it sets the point that is supposedly not on the side of the QIX to 2 in a 2D array. I also have min and max x and y values of the 2D array, which at the start also equal the point's x and y.
- After that it checks the 2D array from min to max values until there are no values that equal 2. If a value = 2, it checks if a line crosses it. If no, it sets the top, bottom, left and right points to 2, and changes min and max x and y values if needed. This one point that was checked is set to 1.

This way I have a 2D array with 0 for covered and 1 for uncovered points. And here is the code that does that:

do  //This is the code after I have a starting value in the 2D array - pointd
{
    enough=1
    for(for1=minx; for1<=maxx; for1+=1)  //min and max x and y values of the points for checking 
    for(for2=miny; for2<=maxy; for2+=1)  //so it doesn't check everything everytime
    {
        if(pointd[for1,for2]=2)for(aba=1;aba<=thln;aba+=1)  //If it is 2, check it with every line
        {
            if(((for1>=thlposx[aba] and for1<=thlendx[aba]) or (for1<=thlposx[aba] and for1>=thlendx[aba]))
            and((for2>=thlposy[aba] and for2<=thlendy[aba]) or (for2<=thlposy[aba] and for2>=thlendy[aba])))
                {pointd[for1,for2]=1; aba=thln+1}  //If it is on a line, set it to 1, to be drawn and stop checking
        }
    if(pointd[for1,for2]=2) //If it is not on a line, set adjacent point for checking
    {
        enough=0  //stop value to 0, continue with do until
        pointd[for1,for2]=1  //set point to be drawn
        if(pointd[for1-1,for2]=0)pointd[for1-1,for2]=2 //set points to be checked
        if(pointd[for1+1,for2]=0)pointd[for1+1,for2]=2
        if(pointd[for1,for2-1]=0)pointd[for1,for2-1]=2
        if(pointd[for1,for2+1]=0)pointd[for1,for2+1]=2
        if(minx=for1 and for1>1)minx=for1-1 //if this is min or max x or y change it
        if(miny=for2 and for2>1)miny=for2-1
        if(maxx=for1 and for1<319)maxx=for1+1
        if(maxy=for2 and for2<374)maxy=for2+1
        }
    }
}
until enough=1
if(pointd[objQIX.x,objQIX.y]=1) //if it got the wrong part of the screen (the wrong side of the line), change all
{
    for(aaaa=0; aaaa<=320; aaaa+=1)
    for(aaaaa=0; aaaaa<=375; aaaaa+=1)
    if(pointd[aaaa,aaaaa]=1)pointd[aaaa,aaaaa]=0
    else pointd[aaaa,aaaaa]=1
}

It appears that the do until cycle spins less than 100 times in simple cases and 200-400 times for more complicated ones. The problem seems to be this cycle:

if(pointd[for1,for2]=2)for(aba=1;aba<=thln;aba+=1)  //If it is 2, check it with every line
{
    if(((for1>=thlposx[aba] and for1<=thlendx[aba]) or (for1<=thlposx[aba] and for1>=thlendx[aba]))   
    and((for2>=thlposy[aba] and for2<=thlendy[aba]) or (for2<=thlposy[aba] and for2>=thlendy[aba])))
    {pointd[for1,for2]=1; aba=thln+1}  //If it is on a line, set it to 1, to be drawn and stop checking
}

That for cycle does over 100,000 spins in most cases, and even over 1,000,000 for bigger areas.

Any ideas or code on how to speed it up or change it to a more efficient algorithm are welcome. Thank You in advance!

Are you running through every pixel at a time?

How about using a scaling algorithm rather? Let's say, each entry in your grid equals 4 real pixels. Then you already have 1/4 of the number of calculations to do. I don't think that on a game like that, you really need to handle each pixel as a single block.

The original game was a text-mode game, so it worked on 80x25 characters! I guess things have changed a lot since then :)

Not sure if the language supports it, but can't you use regions?

Thank You for the replies!

@Ewald Horn
I was thinking about that, but in some cases 1/4 is still a lot. I changed it to see how it will work out, but I am trying to get rid of few bugs that it brought up.

@pritaeas
What exactly do you mean by regions? I don't know what that is, sorry.

Basically this. I know you're not using that, but that's the idea.

So I got rid of the bugs. It is faster, but it still takes 27 seconds for the whole field to be calculated. That is the time it takes on my laptop and it is meant to be a mobile game.

@pritaeas
I can use rectangles, but I don't see how I can do it with rectangles. The only thing that came to my mind is have each border, create a rectangle from itself to the opposite border. This would be really fast, but there is just one problem. I don't know how to get them all to check on the same side of the shape. If one creates rectangle in the zone with QIX and other in the zone without QIX, it will completely mess up.

This is quite an interesting conundrum. What are the values of the maximum x and maximum y? I'm trying to get a grasp for the scope of the loops.

The total area is 2,2,320,374 set by border lines.

Is that the area in pixels, or is the area from 2 - 320 by 2 - 374 pixels?

There's got to be a way to short-circuit the test algorithm :)

Those are the x and y coordinates of the rectangle formed by the border lines. The area starts at 2,2 and ends at 320,374. The whole room size is 320x480, but the calculations happen only for the area in the border lines.

Ah, that's great, so it's not such a large array at all. As you said, the problem is with the nested loops, there's a lot of expensive looping.

Thank You so much for the help!

I thought about using rectangles before, but I could not come with a solution on how to make it exactly. Last night I came up with this and I think this should finally work.

// s - starting point of path, e - end point
//if one line - opposite of QIX
//Else if on opposite walls
{
   //if towards e(line direction) – away QIX(rectangle from line), towards s – towards QIX,  don’t need the other 2
   // need to continue past collision with the parts of the lines that are not in collision.
}
//else
{
   //if away s – towards e, towards s – away e , away e – away s, towards e – towards s
}

I have not tested it yet.

Let us know, there's nothing like finding a solution to something that's been bugging you for a while :)

Great job on not giving up by the way, I admire that.

I ran into a problem and I remembered that I saw that the first time I thought on how to use rectangles to do it.

ee79fb47b58a1cc436fb26c8e9d2bd04

Oh, but there's more to fill, isn't there?

Hello,

Have you tried the floodFill Algorythm to do the fill and area calc? I'm trying to make the same game, but mine will be on Construct2.

So far i'm still working in the main code (draw and fill the smaller area) the fastest way possible.

Since Construct2 can be extended with javascript plugins, i left Construct2 for a while to mess on javascript code first.

I'm still ignoring the enemies cause thats made on Construct2. For now i just want to draw.

Using floodFill algorythm i have managed to quickly check the whole array on both sides of the path (using last known path point and player movement direction to flood both sides).

Working demo here:
http://luis.peralta.pt/sandbox/js/flood.html

You'll notice a slow fill, but thats because of the HUGE helper table that demo is using (the code sets a class for each cell to help me visualize what's happening in the array).

My next move will be get rid of the table and start drawing HTML canvas polys based on the vertices found on the array. But that's yet to think how to do.

In short, what that code do?

As you'll see, my 2D array uses the following values:
U: unfilled
F: filled
P: path
T1: temporary area being flooded at the same time area 2 is
T2: temporary area being flooed at the same time area 1 is

The game starts with the perimeter set to F so the player can move safely around the array.

As soon the player gets out of the safe area (F) it starts drawing the path setting (P) as it goes. If the player inverts the direction, it starts removing P and setting U again (erasing the path).

An array with the cardeal points to where the player is moving is saved. So i can kill the player when he colides with the path without the exception mentioned above (move back).

When the player reaches the F (safe/filled area), i check the direction the player was having and from the lastX and lastY (which will be the last path point) i run the floodFill algorythm on the pixels on each side.

the first flood will set T1 (temp area 1) on all adjacent U's of the first pixel. The second flood will set T2 (temp area 2) on all adjacent U's of the second pixel. While flooding i save the flood count. That will give me the area of both floods.

This process can have 3 possible endings:

If both starting pixels where U, the whole array will be flooded. and F + T1 + T2 = layout area. Then you just fill (set to F) the smaller Tx, or the area where Qix isn't.

If one of the pixels was F, only one flood will happen. In this case, where F + T1 + T2 != layout area, something is yet to temporary fill and calc. That means that the U's yet to calc are the area of the other Tx. More over, this temp fill is the one to pass from Tx to F.

If both pixels were already F, this is yet to code. ;) but will be just a check to get the first U, do the flood, and apply the previous process... (i think)

Feel free to contact me if you have any doubt about that JS code (it's not a mess but might not be easy to read.. sorry).

I didn't exactly understand everything you wrote, but I think you are doing what I have already done. I also used flood fill algorithm(see code in first post), but my area is much bigger and it takes too much time.

P.S. I have new idea with rectangles, but I need to test it out to make sure there aren't any flaws, but I don't have the time right now.

So I have been struggling for 2 weeks to get my idea to work, but with no success. I am posting and hoping some good soul can see where I am making a mistake and help me fix my code.

What my code does is when the player completes a shape, it takes the first line and creates a rectangle from that line in certain direction. The rectangle gets as big as it can in every direction until it hits a line. Then it checks each side of the rectangle and how that side fits with a line. If the line does not completely cover the rectangle side, the part of the rectangle side that is not covered, gets added as line to an array. After we are done with this rectangle, we get the next line in the array and create a rectangle for that one too. We do this until there are no more lines in the array.

It used to work, but it did not make correct rectangles. I went thought that code so many times, changed it so many times and I still can't get it to work. The last change I made even made it add lines to the array until the array gets too big and it shows error and crashes.

Here is the latest code:

if(draw_points=1)
{
    llc=1
    llx1[1]=thlposx[firstnew]   //thl starting values are the drawn lines, all in the array
    lly1[1]=thlposy[firstnew]   //firstnew is the first drawn line for the last shape, the shape which will be checked
    llx2[1]=thlendx[firstnew]
    lly2[1]=thlendy[firstnew]
    //lld 1 <-  2 ^  3 ->  4 v
    //if lld is 1 we have right line of rectangle, 2 - bottom, 3 - left, 4 - top
    if(thlposx[firstnew]=thlendx[firstnew])lld[1]=1
    else lld[1]=2
    for(ap=1; ap<=llc; ap+=1)
    {
        rectx1=0; recty1=0; rectx2=322; recty2=375  //Border lines form rectangle with coordinates 2,2,320,374
        if(lld[ap]=1){recty1=min(lly1[ap],lly2[ap]); rectx2=llx2[ap]; recty2=max(lly1[ap],lly2[ap]);}
        else if(lld[ap]=2){rectx1=min(llx1[ap],llx2[ap]); recty2=lly2[ap]; rectx2=max(llx1[ap],llx2[ap])}
        else if(lld[ap]=3){recty1=min(lly1[ap],lly2[ap]); rectx1=llx1[ap]; recty2=max(lly1[ap],lly2[ap]);}
        else if(lld[ap]=4){rectx1=min(llx1[ap],llx2[ap]); recty1=lly1[ap]; rectx2=max(llx1[ap],llx2[ap])}
        vallld=lld[ap]
        if(vallld=1 or vallld=3) //Have x2 or x1
        {                
            if(vallld=1)for(aba=1;aba<=thln;aba+=1) //Find x1
            {
                if(thlposx[aba]=thlendx[aba] and thlposx[aba]>rectx1 and thlposx[aba]<rectx2 and (
                (min(thlposy[aba],thlendy[aba])>=min(recty1,recty2) and min(thlposy[aba],thlendy[aba])<max(recty1,recty2)) 
                or (max(thlposy[aba],thlendy[aba])>min(recty1,recty2) and max(thlposy[aba],thlendy[aba])<=max(recty1,recty2)))){rectx1=thlposx[aba]; aban=aba}
            }
            if(vallld=3)for(aba=1;aba<=thln;aba+=1) //Find x2
            {
                if(thlposx[aba]=thlendx[aba] and thlposx[aba]>rectx1 and thlposx[aba]<rectx2 and (
                (min(thlposy[aba],thlendy[aba])>=min(recty1,recty2) and min(thlposy[aba],thlendy[aba])<max(recty1,recty2)) 
                or (max(thlposy[aba],thlendy[aba])>min(recty1,recty2) and max(thlposy[aba],thlendy[aba])<=max(recty1,recty2)))){rectx2=thlposx[aba]; aban=aba}
            }
            if(rectx1!=0 and rectx2!=322)
            {
                if!(min(thlposy[aban],thlendy[aban])<=min(recty1,recty2) and max(thlposy[aban],thlendy[aban])>=max(recty1,recty2))
                {
                    if(min(thlposy[aban],thlendy[aban])<=min(recty1,recty2) and max(thlposy[aban],thlendy[aban])<max(recty1,recty2) and max(thlposy[aban],thlendy[aban])>min(recty1,recty2))
                    { llc+=1; llx1[llc]=thlposx[aban]; lly1[llc]=max(thlposy[aban],thlendy[aban]); llx2[llc]=thlposx[aban]; lly2[llc]=max(recty1,recty2); lld[llc]=vallld}
                    else if(min(thlposy[aban],thlendy[aban])>min(recty1,recty2) and min(thlposy[aban],thlendy[aban])<max(recty1,recty2) and max(thlposy[aban],thlendy[aban])>=max(recty1,recty2))
                    { llc+=1; llx1[llc]=thlposx[aban]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aban]; lly2[llc]=min(thlposy[aban],thlendy[aban]); lld[llc]=vallld}
                    else if(min(thlposy[aban],thlendy[aban])>min(recty1,recty2) and max(thlposy[aban],thlendy[aban])<max(recty1,recty2))
                    {llc+=1; llx1[llc]=thlposx[aban]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aban]; lly2[llc]=min(thlposy[aban],thlendy[aban]); lld[llc]=vallld
                    llc+=1; llx1[llc]=thlposx[aban]; lly1[llc]=max(thlposy[aban],thlendy[aban]); llx2[llc]=thlposx[aban]; lly2[llc]=max(recty1,recty2); lld[llc]=vallld}
                    else {llc+=1; llx1[llc]=thlposx[aban]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aban]; lly2[llc]=max(recty1,recty2); lld[llc]=vallld}
                }
                for(aba=1;aba<=thln;aba+=1) //This should check how rectangle line fits drawn lines
                {
                    if(thlposy[aba]=thlendy[aba] and thlposy[aba]=recty1 and (min(rectx1,rectx2)<max(thlposx[aba],thlendx[aba]) and max(rectx1,rectx2)>min(thlposx[aba],thlendx[aba])) or (min(rectx1,rectx2)<max(thlposx[aba],thlendx[aba]) and max(rectx1,rectx2)>=max(thlposx[aba],thlendx[aba])))
                    {
                        if!(min(thlposx[aba],thlendx[aba])<=min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])>=max(rectx1,rectx2))
                        { //And create a new rectangle to be checked if it is not perfect
                            if(min(thlposx[aba],thlendx[aba])<=min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])<max(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])>min(rectx1,rectx2))
                            {llc+=1; llx1[llc]=max(thlposx[aba],thlendx[aba]); lly1[llc]=thlposy[aba]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aba]; lld[llc]=2}
                            else if(min(thlposx[aba],thlendx[aba])>min(rectx1,rectx2) and min(thlposx[aba],thlendx[aba])<max(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])>=max(rectx1,rectx2))
                            {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aba]; llx2[llc]=min(thlposx[aba],thlendx[aba]); lly2[llc]=thlposy[aba]; lld[llc]=2}
                            else if(min(thlposx[aba],thlendx[aba])>min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])<max(rectx1,rectx2))
                            {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aba]; llx2[llc]=min(thlposx[aba],thlendx[aba]); lly2[llc]=thlposy[aba]; lld[llc]=2
                            llc+=1; llx1[llc]=max(thlposx[aba],thlendx[aba]); lly1[llc]=thlposy[aba]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aba]; lld[llc]=2}
                            else {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aba]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aba]; lld[llc]=2}
                        }
                    }
                }
                for(aba=1;aba<=thln;aba+=1) //This should check how rectangle line fits drawn lines
                {
                    if(thlposy[aba]=thlendy[aba] and thlposy[aba]=recty2 and (min(rectx1,rectx2)<max(thlposx[aba],thlendx[aba]) and max(rectx1,rectx2)>min(thlposx[aba],thlendx[aba])) or (min(rectx1,rectx2)<max(thlposx[aba],thlendx[aba]) and max(rectx1,rectx2)>=max(thlposx[aba],thlendx[aba])))
                    {
                        if!(min(thlposx[aba],thlendx[aba])<=min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])>=max(rectx1,rectx2))
                        { //And create a new rectangle to be checked if it is not perfect
                            if(min(thlposx[aba],thlendx[aba])<=min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])<max(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])>min(rectx1,rectx2))
                            {llc+=1; llx1[llc]=max(thlposx[aba],thlendx[aba]); lly1[llc]=thlposy[aba]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aba]; lld[llc]=4}
                            else if(min(thlposx[aba],thlendx[aba])>min(rectx1,rectx2) and min(thlposx[aba],thlendx[aba])<max(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])>=max(rectx1,rectx2))
                            {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aba]; llx2[llc]=min(thlposx[aba],thlendx[aba]); lly2[llc]=thlposy[aba]; lld[llc]=4}
                            else if(min(thlposx[aba],thlendx[aba])>min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])<max(rectx1,rectx2))
                            {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aba]; llx2[llc]=min(thlposx[aba],thlendx[aba]); lly2[llc]=thlposy[aba]; lld[llc]=4
                            llc+=1; llx1[llc]=max(thlposx[aba],thlendx[aba]); lly1[llc]=thlposy[aba]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aba]; lld[llc]=4}
                            else {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aba]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aba]; lld[llc]=4}
                        }
                    }
                }
            }
        }
        else if(vallld=2 or vallld=4) //Have y2 or y1
        {                
            if(vallld=2)for(aba=1;aba<=thln;aba+=1) //Find y1
            {
                if(thlposy[aba]=thlendy[aba] and thlposy[aba]>recty1 and thlposy[aba]<recty2 and (
                (min(thlposx[aba],thlendx[aba])>=min(rectx1,rectx2) and min(thlposx[aba],thlendx[aba])<max(rectx1,rectx2)) 
                or (max(thlposx[aba],thlendx[aba])>min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])<=max(rectx1,rectx2)))){recty1=thlposy[aba]; aban=aba}
            }
            if(vallld=4)for(aba=1;aba<=thln;aba+=1) //Find y2
            {
                if(thlposy[aba]=thlendy[aba] and thlposy[aba]>recty1 and thlposy[aba]<recty2 and (
                (min(thlposx[aba],thlendx[aba])>=min(rectx1,rectx2) and min(thlposx[aba],thlendx[aba])<max(rectx1,rectx2)) 
                or (max(thlposx[aba],thlendx[aba])>min(rectx1,rectx2) and max(thlposx[aba],thlendx[aba])<=max(rectx1,rectx2)))){recty2=thlposy[aba]; aban=aba}
            }
            if(recty1!=0 and recty2!=375)
            {
                if!(min(thlposx[aban],thlendx[aban])<=min(rectx1,rectx2) and max(thlposx[aban],thlendx[aban])>=max(rectx1,rectx2))
                {
                    if(min(thlposx[aban],thlendx[aban])<=min(rectx1,rectx2) and max(thlposx[aban],thlendx[aban])<max(rectx1,rectx2) and max(thlposx[aban],thlendx[aban])>min(rectx1,rectx2))
                    {llc+=1; llx1[llc]=max(thlposx[aban],thlendx[aban]); lly1[llc]=thlposy[aban]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aban]; lld[llc]=vallld}
                    else if(min(thlposx[aban],thlendx[aban])>min(rectx1,rectx2) and min(thlposx[aban],thlendx[aban])<max(rectx1,rectx2) and max(thlposx[aban],thlendx[aban])>=max(rectx1,rectx2))
                    {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aban]; llx2[llc]=min(thlposx[aban],thlendx[aban]); lly2[llc]=thlposy[aban]; lld[llc]=vallld}
                    else if(min(thlposx[aban],thlendx[aban])>min(rectx1,rectx2) and max(thlposx[aban],thlendx[aban])<max(rectx1,rectx2))
                    {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aban]; llx2[llc]=min(thlposx[aban],thlendx[aban]); lly2[llc]=thlposy[aban]; lld[llc]=vallld
                    llc+=1; llx1[llc]=max(thlposx[aban],thlendx[aban]); lly1[llc]=thlposy[aban]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aban]; lld[llc]=vallld}
                    else {llc+=1; llx1[llc]=min(rectx1,rectx2); lly1[llc]=thlposy[aban]; llx2[llc]=max(rectx1,rectx2); lly2[llc]=thlposy[aban]; lld[llc]=vallld}
                }
                for(aba=1;aba<=thln;aba+=1)
                {
                    if(thlposx[aba]=thlendx[aba] and thlposx[aba]=rectx1 and (min(recty1,recty2)<max(thlposy[aba],thlendy[aba]) and max(recty1,recty2)>min(thlposy[aba],thlendy[aba])) or (min(recty1,recty2)<max(thlposy[aba],thlendy[aba]) and max(recty1,recty2)>=max(thlposy[aba],thlendy[aba])))
                    {
                        if!(min(thlposy[aba],thlendy[aba])<=min(recty1,recty2) and max(thlposy[aba],thlendy[aba])>=max(recty1,recty2))
                        {
                            if(min(thlposy[aba],thlendy[aba])<=min(recty1,recty2) and max(thlposy[aba],thlendy[aba])<max(recty1,recty2) and max(thlposy[aba],thlendy[aba])>min(recty1,recty2))
                            {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=max(thlposy[aba],thlendy[aba]); llx2[llc]=thlposx[aba]; lly2[llc]=max(recty1,recty2); lld[llc]=1}
                            else if(min(thlposy[aba],thlendy[aba])>min(recty1,recty2) and min(thlposy[aba],thlendy[aba])<max(recty1,recty2) and max(thlposy[aba],thlendy[aba])>=max(recty1,recty2))
                            {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aba]; lly2[llc]=min(thlposy[aba],thlendy[aba]); lld[llc]=1}
                            else if(min(thlposy[aba],thlendy[aba])>min(recty1,recty2) and max(thlposy[aba],thlendy[aba])<max(recty1,recty2))
                            {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aba]; lly2[llc]=min(thlposy[aba],thlendy[aba]); lld[llc]=1
                            llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=max(thlposy[aba],thlendy[aba]); llx2[llc]=thlposx[aba]; lly2[llc]=max(recty1,recty2); lld[llc]=1}
                            else {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aba]; lly2[llc]=max(recty1,recty2); lld[llc]=1}
                        }
                    }
                }
                for(aba=1;aba<=thln;aba+=1)
                {
                    if(thlposx[aba]=thlendx[aba] and thlposx[aba]=rectx2 and (min(recty1,recty2)<max(thlposy[aba],thlendy[aba]) and max(recty1,recty2)>min(thlposy[aba],thlendy[aba])) or (min(recty1,recty2)<max(thlposy[aba],thlendy[aba]) and max(recty1,recty2)>=max(thlposy[aba],thlendy[aba])))
                    {
                        if!(min(thlposy[aba],thlendy[aba])<=min(recty1,recty2) and max(thlposy[aba],thlendy[aba])>=max(recty1,recty2))
                        {
                            if(min(thlposy[aba],thlendy[aba])<=min(recty1,recty2) and max(thlposy[aba],thlendy[aba])<max(recty1,recty2) and max(thlposy[aba],thlendy[aba])>min(recty1,recty2))
                            {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=max(thlposy[aba],thlendy[aba]); llx2[llc]=thlposx[aba]; lly2[llc]=max(recty1,recty2); lld[llc]=3}
                            else if(min(thlposy[aba],thlendy[aba])>min(recty1,recty2) and min(thlposy[aba],thlendy[aba])<max(recty1,recty2) and max(thlposy[aba],thlendy[aba])>=max(recty1,recty2))
                            {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aba]; lly2[llc]=min(thlposy[aba],thlendy[aba]); lld[llc]=3}
                            else if(min(thlposy[aba],thlendy[aba])>min(recty1,recty2) and max(thlposy[aba],thlendy[aba])<max(recty1,recty2))
                            {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aba]; lly2[llc]=min(thlposy[aba],thlendy[aba]); lld[llc]=3
                            llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=max(thlposy[aba],thlendy[aba]); llx2[llc]=thlposx[aba]; lly2[llc]=max(recty1,recty2); lld[llc]=3}
                            else {llc+=1; llx1[llc]=thlposx[aba]; lly1[llc]=min(recty1,recty2); llx2[llc]=thlposx[aba]; lly2[llc]=max(recty1,recty2); lld[llc]=3}
                        }
                    }
                }
            }
        //End of rectangle creating
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.