cent_percent_dotnet

Counterclockwise empty polygon

May 6th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 44.62 KB | None | 0 0
  1. int islandCurrentX = -1;
  2.                                                     int islandCurrentY = -1;
  3.                                                    
  4.                                                     string direction = "Left";
  5.                                                     int count = 0;
  6.                                                     string pth = "";
  7.                                                     //testing
  8.                                                     currentTrackless.Width = 20;
  9.                                                     currentTrackless.Height = 20;
  10.                                                     //
  11.                                                     while ((islandCurrentX != islandStartX || islandCurrentY != islandStartY) && count < 500)
  12.                                                     {
  13.                                                         int tempIslandX = (islandCurrentX == -1 ? islandStartX : islandCurrentX);
  14.                                                         int tempIslandY = (islandCurrentY == -1 ? islandStartY : islandCurrentY);
  15.                                                         //break;
  16.                                                         count++;
  17.                                                         if (islandCurrentX == 144 && islandCurrentY == 420)
  18.                                                         //if(islandCurrentX==120 && islandCurrentY==233)
  19.                                                         {
  20.  
  21.                                                         }
  22. if (direction == "Left")//left
  23.                                                         {
  24.                                                             DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
  25.                                                                 "Starting_Y+Image_Length=" + tempIslandY + " and " +
  26.                                                                 "Starting_X<" + tempIslandX + " and " +
  27.                                                                 "Starting_X+Image_Width>" + tempIslandX + "");
  28.                                                             DataRow[] drNearestLeftwardsBRDG = dtCurrentPattern.Select("" +
  29.                                                                 "Starting_Y=" + tempIslandY + " and " +
  30.                                                                 "Starting_X<" + tempIslandX + "" +
  31.                                                                 "" +
  32.                                                                 "");
  33.                                                             drNearestLeftwardsBRDG = drNearestLeftwardsBRDG.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"]))).ToArray<DataRow>();
  34.  
  35.                                                             DataRow[] drNearestLeftwards = dtCurrentPattern.Select("" +
  36.                                                                 "Starting_Y+Image_Length=" + tempIslandY + " and " +
  37.                                                                 "Starting_X+Image_Width=" + tempIslandX + "" +
  38.                                                                 "" +
  39.                                                                 "");
  40.                                                             DataRow[] drNearestLeftwards0 = dtCurrentPattern.Select("" +
  41.                                                                 "Starting_Y=" + tempIslandY + " and " +
  42.                                                                 "Starting_X+Image_Width<" + tempIslandX + "" +
  43.                                                                 "" +
  44.                                                                 "");
  45.                                                             drNearestLeftwards0 = drNearestLeftwards0.OrderByDescending(row => DataHelper.GetInt(row["Starting_X"])).ToArray<DataRow>();
  46.                                                             DataRow[] drNearestDownwards = dtCurrentPattern.Select("" +
  47.                                                                 "Starting_Y<=" + tempIslandY + " and " +
  48.                                                                 "Starting_Y+Image_Length>" + tempIslandY + " and " +
  49.                                                                 "Starting_X+Image_Width=" + tempIslandX + "" +
  50.                                                                 "" +
  51.                                                                 "");
  52.                                                             DataRow[] drNearestDownwards0 = dtCurrentPattern.Select("" +
  53.                                                                 "Starting_Y>" + tempIslandY + " and " +
  54.                                                                 //"Starting_Y+Image_Length>=" + tempIslandY + " and " +
  55.                                                                 "Starting_X=" + tempIslandX + "" +
  56.                                                                 "" +
  57.                                                                 "");
  58.                                                             drNearestDownwards0 = drNearestDownwards0.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
  59.                                                             DataRow[] drNearestUpwards = dtCurrentPattern.Select("" +
  60.                                                                 "Starting_X=" + tempIslandX + " and " +
  61.                                                                 "Starting_Y+Image_Length=" + tempIslandY + "" +
  62.                                                                 "" +
  63.                                                                 "");
  64.                                                             if((tempIslandX > 0 && drNearestDownwards.Length > 0))
  65.                                                             {
  66.                                                                 islandCurrentX = tempIslandX;
  67.                                                                 islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"]) + DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
  68.                                                                 direction = "Down";
  69.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  70.                                                             }
  71.                                                             else if (drNearestLeftwards.Length > 0)
  72.                                                             {
  73.                                                                 islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]));
  74.                                                                 islandCurrentY = tempIslandY;
  75.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  76.                                                             }
  77.                                                             else if (((tempIslandX > 0 && drNearestDownwards.Length > 0) || (tempIslandX == 0 && drNearestDownwards0.Length > 0)|| (tempIslandY == 0 && drNearestLeftwards0.Length > 0)))// && drNearestLeftwards.Length == 0  )
  78.                                                             {
  79.                                                                 if (tempIslandY == 0 && drNearestLeftwards0.Length > 0)
  80.                                                                 {
  81.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestLeftwards0[0]["Starting_X"]) + DataHelper.GetInt(drNearestLeftwards0[0]["Image_Width"]));
  82.                                                                     direction = "Down";
  83.                                                                 }
  84.                                                                 else
  85.                                                                 {
  86.                                                                     islandCurrentX = tempIslandX;
  87.                                                                     if (tempIslandX == 0)
  88.                                                                         islandCurrentY = (DataHelper.GetInt(drNearestDownwards0[0]["Starting_Y"]));
  89.  
  90.                                                                     else
  91.                                                                         islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"]) + DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
  92.                                                                     if (islandCurrentX == 0)
  93.                                                                         direction = "Right";
  94.                                                                     else
  95.                                                                         direction = "Down";
  96.                                                                 }
  97.                                                                
  98.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  99.                                                             }
  100.                                                            
  101.  
  102.                                                             else if (drNearestUpwards.Length > 0 && tempIslandX > 0)
  103.                                                             {
  104.                                                                 islandCurrentX = tempIslandX;
  105.                                                                 islandCurrentY = (DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]));
  106.                                                                 direction = "Up";
  107.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  108.                                                             }
  109.                                                             else if (drBetweenBridging.Length > 0)
  110.                                                             {
  111.                                                                 if (drNearestLeftwardsBRDG.Length > 0)
  112.                                                                 {
  113.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestLeftwardsBRDG[0]["Starting_X"]) + DataHelper.GetInt(drNearestLeftwardsBRDG[0]["Image_Width"]));
  114.                                                                     islandCurrentY = (DataHelper.GetInt(drNearestLeftwardsBRDG[0]["Starting_Y"]) );
  115.                                                                     direction = "Up";
  116.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  117.                                                                 }
  118.                                                                 else
  119.                                                                 {
  120.                                                                     islandCurrentX = 0;
  121.                                                                     direction = "Up";
  122.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  123.                                                                 }
  124.                                                             }
  125.                                                             else
  126.                                                             {
  127.                                                                 DataRow[] drMonai = dtCurrentPattern.Select("Starting_X=" + islandCurrentX + "" +
  128.                                                                     " and Starting_Y=" + islandCurrentY + "");
  129.                                                                 if (drMonai.Length > 0)
  130.                                                                 {
  131.                                                                     direction = "Right";
  132.                                                                 }
  133.                                                                 else
  134.                                                                 {
  135.                                                                     //islandCurrentX = 0;
  136.                                                                     //islandCurrentY = tempIslandY;
  137.                                                                     direction = "Down";
  138.                                                                 }
  139.                                                             }
  140.                                                             pth += "\n"+islandCurrentX + ":" + islandCurrentY + ":" + "Left;";
  141.                                                             currentTrackless.Left = islandCurrentX;
  142.                                                             currentTrackless.Top = islandCurrentY;
  143.                                                             //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
  144.                                                         }
  145.                                                         else if (direction == "Down")//down
  146.                                                         {
  147.                                                             DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
  148.                                                                "Starting_X=" + tempIslandX + " and " +
  149.                                                                "Starting_Y<" + tempIslandY + " and " +
  150.                                                                "Starting_Y+Image_Length>" + tempIslandY + "");
  151.                                                             DataRow[] drNearestDownwardsBRDG = dtCurrentPattern.Select("" +
  152.                                                                 "Starting_X=" + tempIslandX + " and " +
  153.                                                                 "Starting_Y>" + tempIslandY + "" +
  154.                                                                 "" +
  155.                                                                 "");
  156.                                                             drNearestDownwardsBRDG = drNearestDownwardsBRDG.OrderBy(row => (DataHelper.GetInt(row["Starting_Y"]))).ToArray<DataRow>();
  157.                                                             DataRow[] drNearestDownwards = dtCurrentPattern.Select("" +
  158.                                                                 "Starting_Y=" + tempIslandY + " and " +
  159.                                                                 "Starting_X+Image_Width=" + tempIslandX + "" +
  160.                                                                 "" +
  161.                                                                 "");
  162.                                                             DataRow[] drNearestRightwards = dtCurrentPattern.Select("" +
  163.                                                                 "Starting_Y=" + tempIslandY + " and " +
  164.                                                                 "Starting_X<=" + tempIslandX + " and " +
  165.                                                                 "Starting_X+Image_Width>" + tempIslandX + "" +
  166.                                                                 "" +
  167.                                                                 "");
  168.                                                             DataRow[] drNearestRightwards0 = dtCurrentPattern.Select("" +
  169.                                                                 "Starting_Y=" + tempIslandY + " and " +
  170.                                                                 "Starting_X>" + tempIslandX + " " +
  171.                                                                 //"and " +
  172.                                                                 //"Starting_X+Image_Width>=" + tempIslandX + "" +
  173.                                                                 "" +
  174.                                                                 "");//wrong
  175.                                                             drNearestRightwards0 = drNearestRightwards0.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]))).ToArray<DataRow>();
  176.                                                             DataRow[] drNearestLeftwards = dtCurrentPattern.Select("" +
  177.                                                                 "Starting_X+Image_Width=" + tempIslandX + " and " +
  178.                                                                 "Starting_Y+Image_Length=" + tempIslandY + "" +
  179.                                                                 "" +
  180.                                                                 "");
  181.                                                             if (tempIslandY < pictureBox2.Height && drNearestRightwards.Length > 0)
  182.                                                             {
  183.                                                                 islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
  184.                                                                 direction = "Right";
  185.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  186.                                                             }
  187.                                                             else if (drNearestDownwards.Length > 0)
  188.                                                             {
  189.                                                                 islandCurrentX = tempIslandX;
  190.                                                                 islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"]) + DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
  191.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  192.                                                             }
  193.                                                             else if (((tempIslandY < pictureBox2.Height && drNearestRightwards.Length > 0) || (tempIslandY == pictureBox2.Height && drNearestRightwards0.Length > 0)) && drNearestDownwards.Length == 0)
  194.                                                             {
  195.                                                                 if (tempIslandY == pictureBox2.Height)
  196.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestRightwards0[0]["Starting_X"]));
  197.                                                                 //islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
  198.                                                                 else
  199.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
  200.                                                                 islandCurrentX = tempIslandX; ;
  201.                                                                 if (tempIslandY == pictureBox2.Height)
  202.                                                                     direction = "Right";
  203.                                                                 else
  204.                                                                     direction = "Right";
  205.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  206.                                                             }
  207.                                                             else if (drNearestLeftwards.Length > 0 && tempIslandY < pictureBox2.Height)
  208.                                                             {
  209.                                                                 islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]));
  210.                                                                 islandCurrentY = tempIslandY;
  211.                                                                 direction = "Left";
  212.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  213.                                                             }
  214.                                                             else if (drBetweenBridging.Length > 0)
  215.                                                             {
  216.                                                                 if (drNearestDownwardsBRDG.Length > 0)
  217.                                                                 {
  218.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestDownwardsBRDG[0]["Starting_X"]));
  219.                                                                     islandCurrentY = (DataHelper.GetInt(drNearestDownwardsBRDG[0]["Starting_Y"]) );
  220.                                                                     direction = "Up";
  221.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  222.                                                                 }
  223.                                                                 else
  224.                                                                 {
  225.                                                                     islandCurrentX = pictureBox2.Width;
  226.                                                                     direction = "Up";
  227.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  228.                                                                 }
  229.                                                             }
  230.                                                             else
  231.                                                             {
  232.                                                                 DataRow[] drMonai = dtCurrentPattern.Select("Starting_X=" + islandCurrentX + "" +
  233.                                                                     " and Starting_Y+Image_Length=" + islandCurrentY + "");
  234.                                                                 if (drMonai.Length > 0)
  235.                                                                 {
  236.                                                                     direction = "Right";
  237.                                                                 }
  238.                                                                 else
  239.                                                                     //islandCurrentX = tempIslandX;
  240.                                                                     //islandCurrentY = pictureBox2.Height;
  241.                                                                     direction = "Down";
  242.                                                                 //direction = "Up";prevCorr
  243.                                                             }
  244.                                                             pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "down;";
  245.                                                             currentTrackless.Left = islandCurrentX;
  246.                                                             currentTrackless.Top = islandCurrentY;
  247.                                                             //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
  248.                                                         }
  249.                                                         else if (direction == "Right")//right
  250.                                                         {
  251.                                                             DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
  252.                                                                 "Starting_Y=" + tempIslandY + " and " +
  253.                                                                 "Starting_X<" + tempIslandX + " and " +
  254.                                                                 "Starting_X+Image_Width>" + tempIslandX + "");
  255.                                                             DataRow[] drNearestRightwardsBRDG = dtCurrentPattern.Select("" +
  256.                                                                 "Starting_Y+Image_Length=" + tempIslandY + " and " +
  257.                                                                 "Starting_X>" + tempIslandX + "" +
  258.                                                                 "" +
  259.                                                                 "");
  260.                                                             drNearestRightwardsBRDG = drNearestRightwardsBRDG.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) )).ToArray<DataRow>();
  261.                                                             DataRow[] drNearestRightwards = dtCurrentPattern.Select("" +
  262.                                                                 "Starting_Y=" + tempIslandY + " and " +
  263.                                                                 "Starting_X=" + tempIslandX + "" +
  264.                                                                 "" +
  265.                                                                 "");
  266.                                                             DataRow[] drNearestUpwards = dtCurrentPattern.Select("" +
  267.                                                                 "Starting_Y<" + tempIslandY + " and " +
  268.                                                                 "Starting_Y+Image_Length>=" + tempIslandY + " and " +
  269.                                                                 "Starting_X=" + tempIslandX + "" +
  270.                                                                 "" +
  271.                                                                 "");
  272.                                                             DataRow[] drNearestUpwards0 = dtCurrentPattern.Select("" +
  273.                                                                 "Starting_Y<" + tempIslandY + " and " +
  274.                                                                 //"Starting_Y+Image_Length>=" + tempIslandY + " and " +
  275.                                                                 "Starting_X+Image_Width=" + tempIslandX + "" +
  276.                                                                 "" +
  277.                                                                 "");
  278.                                                             drNearestUpwards0 = drNearestUpwards0.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"])+ DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
  279.                                                             DataRow[] drNearestDownwards = dtCurrentPattern.Select("" +
  280.                                                                 "Starting_X+Image_Width=" + tempIslandX + " and " +
  281.                                                                 "Starting_Y=" + tempIslandY + "" +
  282.                                                                 "" +
  283.                                                                 "");
  284.                                                             if((tempIslandX < pictureBox2.Width && drNearestUpwards.Length > 0))
  285.                                                             {
  286.                                                                 islandCurrentY = (DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]));
  287.                                                                 direction = "Up";
  288.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  289.                                                             }
  290.                                                             else if (drNearestRightwards.Length > 0)
  291.                                                             {
  292.                                                                 islandCurrentX = (DataHelper.GetInt(drNearestRightwards[0]["Starting_X"]) + DataHelper.GetInt(drNearestRightwards[0]["Image_Width"]));
  293.                                                                 islandCurrentY = tempIslandY;
  294.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  295.                                                             }
  296.                                                             else if (((tempIslandX < pictureBox2.Width && drNearestUpwards.Length > 0) || (tempIslandX == pictureBox2.Width && drNearestUpwards0.Length > 0)) && drNearestRightwards.Length == 0)
  297.                                                             {
  298.                                                                 if (tempIslandX == pictureBox2.Width)
  299.                                                                     islandCurrentY = (DataHelper.GetInt(drNearestUpwards0[0]["Starting_Y"]) + DataHelper.GetInt(drNearestUpwards0[0]["Image_Length"]));
  300.                                                                 else
  301.                                                                     islandCurrentY = (DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]) );
  302.                                                                 islandCurrentX = tempIslandX;
  303.                                                                 if (tempIslandX == pictureBox2.Width)
  304.                                                                     direction = "Left";
  305.                                                                 else
  306.                                                                     direction = "Up";
  307.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  308.                                                             }
  309.                                                            
  310.  
  311.                                                             else if (drNearestDownwards.Length > 0 && tempIslandX < pictureBox2.Width)
  312.                                                             {
  313.                                                                 islandCurrentX = tempIslandX;
  314.                                                                 islandCurrentY = (DataHelper.GetInt(drNearestDownwards[0]["Starting_Y"])+ DataHelper.GetInt(drNearestDownwards[0]["Image_Length"]));
  315.                                                                 //direction = 1;
  316.                                                                 direction = "Down";
  317.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  318.                                                             }
  319.                                                             else if(drBetweenBridging.Length>0)
  320.                                                             {
  321.                                                                 if (drNearestRightwardsBRDG.Length > 0)
  322.                                                                 {
  323.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestRightwardsBRDG[0]["Starting_X"]));
  324.                                                                     islandCurrentY = (DataHelper.GetInt(drNearestRightwardsBRDG[0]["Starting_Y"]) + DataHelper.GetInt(drNearestRightwardsBRDG[0]["Image_Length"]));
  325.                                                                     direction = "Up";
  326.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  327.                                                                 }
  328.                                                                 else
  329.                                                                 {
  330.                                                                     islandCurrentX = pictureBox2.Width;
  331.                                                                     direction = "Up";
  332.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  333.                                                                 }
  334.                                                             }
  335.                                                             else
  336.                                                             {
  337.                                                                 //islandCurrentX = pictureBox2.Width;
  338.                                                                 //islandCurrentY = tempIslandY;
  339.                                                                 //direction = "Down";
  340.                                                                 DataRow[] drMonai = dtCurrentPattern.Select("Starting_X+Image_Width=" + islandCurrentX + "" +
  341.                                                                     " and Starting_Y+Image_Length=" + islandCurrentY + "");
  342.                                                                 if (drMonai.Length > 0)
  343.                                                                 {
  344.                                                                     direction = "Up";
  345.                                                                 }
  346.                                                                 else
  347.                                                                     //direction = "Down";prevCorr
  348.                                                                     direction = "Left";
  349.                                                             }
  350.                                                             //points.Add(new Point(islandCurrentX, islandCurrentY));
  351.                                                             pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "right;";
  352.                                                             currentTrackless.Left = islandCurrentX;
  353.                                                             currentTrackless.Top = islandCurrentY;
  354.                                                             //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
  355.                                                         }
  356.                                                         else if (direction == "Up")//all wrong//UP
  357.                                                         {
  358.                                                             DataRow[] drBetweenBridging = dtCurrentPattern.Select("" +
  359.                                                                 "Starting_X+Image_width=" + tempIslandX + " and " +
  360.                                                                 "Starting_Y<" + tempIslandY + " and " +
  361.                                                                 "Starting_Y+Image_Length>" + tempIslandY + "");
  362.                                                             DataRow[] drNearestUpwardsBRDG = dtCurrentPattern.Select("" +
  363.                                                                 "Starting_X+Image_width=" + tempIslandX + " and " +
  364.                                                                 "Starting_Y<" + tempIslandY + "" +
  365.                                                                 "" +
  366.                                                                 "");
  367.                                                             drNearestUpwardsBRDG = drNearestUpwardsBRDG.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"])+ DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
  368.  
  369.                                                             DataRow[] drNearestUpwards = dtCurrentPattern.Select("" +
  370.                                                                 "Starting_Y+Image_Length=" + tempIslandY + " and " +
  371.                                                                 "Starting_X=" + tempIslandX + "" +
  372.                                                                 "" +
  373.                                                                 "");
  374.                                                             DataRow[] drNearestLeftwards = dtCurrentPattern.Select("" +
  375.                                                                 "Starting_X<=" + tempIslandX + " and " +
  376.                                                                 "Starting_X+Image_Width>" + tempIslandX + " and " +
  377.                                                                 "Starting_Y+Image_Length=" + tempIslandX + "" +
  378.                                                                 "" +
  379.                                                                 "");
  380.                                                             DataRow[] drNearestLeftwards0 = dtCurrentPattern.Select("" +
  381.                                                                 "Starting_Y=" + tempIslandY + " and " +
  382.                                                                 //"Starting_Y+Image_Length>=" + tempIslandY + " and " +
  383.                                                                 "Starting_X<" + tempIslandX + "" +
  384.                                                                 "" +
  385.                                                                 "");
  386.                                                             drNearestLeftwards0 = drNearestLeftwards0.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"])+ DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
  387.                                                             DataRow[] drNearestRightwards = dtCurrentPattern.Select("" +
  388.                                                                 "Starting_X=" + tempIslandX + " and " +
  389.                                                                 "Starting_Y=" + tempIslandY + "" +
  390.                                                                 "" +
  391.                                                                 "");
  392.                                                             if (tempIslandY > 0 && drNearestLeftwards.Length > 0)
  393.                                                             {
  394.                                                                 islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]));
  395.                                                                 direction = "Right";        
  396.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  397.                                                             }
  398.                                                             else if (drNearestUpwards.Length > 0)
  399.                                                             {
  400.                                                                 islandCurrentX = tempIslandX;
  401.                                                                 islandCurrentY = DataHelper.GetInt(drNearestUpwards[0]["Starting_Y"]);
  402.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  403.                                                             }
  404.                                                             if (((tempIslandY > 0 && drNearestLeftwards.Length > 0) || (tempIslandY == 0 && drNearestLeftwards0.Length > 0))&& drNearestUpwards.Length == 0)
  405.                                                             {
  406.                                                                 if (tempIslandY == 0)
  407.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestLeftwards0[0]["Starting_X"]) + DataHelper.GetInt(drNearestLeftwards0[0]["Image_Width"]));
  408.                                                                 else
  409.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]) );
  410.                                                                 islandCurrentY = tempIslandY;
  411.                                                                 if (tempIslandY == 0)
  412.                                                                     direction = "Down";
  413.                                                                 else
  414.                                                                     direction = "Right";
  415.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  416.                                                             }
  417.                                                            
  418.  
  419.                                                             else if (drNearestLeftwards.Length > 0 && tempIslandY > 0)
  420.                                                             {
  421.                                                                 islandCurrentX = DataHelper.GetInt(drNearestLeftwards[0]["Starting_X"]);
  422.                                                                 islandCurrentY = tempIslandY;
  423.                                                                 direction = "Left";
  424.                                                                 points.Add(new Point(islandCurrentX, islandCurrentY));
  425.                                                             }
  426.                                                             else if (drBetweenBridging.Length > 0)
  427.                                                             {
  428.                                                                 if (drNearestUpwardsBRDG.Length > 0)
  429.                                                                 {
  430.                                                                     islandCurrentX = (DataHelper.GetInt(drNearestUpwardsBRDG[0]["Starting_X"]) + DataHelper.GetInt(drNearestUpwardsBRDG[0]["Image_Width"]));
  431.                                                                     islandCurrentY = (DataHelper.GetInt(drNearestUpwardsBRDG[0]["Starting_Y"])+ DataHelper.GetInt(drNearestUpwardsBRDG[0]["Image_Length"]));
  432.                                                                     direction = "Up";
  433.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  434.                                                                 }
  435.                                                                 else
  436.                                                                 {
  437.                                                                     islandCurrentX = 0;
  438.                                                                     direction = "Up";
  439.                                                                     points.Add(new Point(islandCurrentX, islandCurrentY));
  440.                                                                 }
  441.                                                             }
  442.                                                             else
  443.                                                             {
  444.                                                                 DataRow[] drMonai = dtCurrentPattern.Select("Starting_X+Image_Width=" + islandCurrentX + "" +
  445.                                                                     " and Starting_Y=" + islandCurrentY + "");
  446.                                                                 if (drMonai.Length > 0)
  447.                                                                 {
  448.                                                                     direction = "Left";
  449.                                                                 }
  450.                                                                 //islandCurrentX = tempIslandX;
  451.                                                                 //islandCurrentY = 0;
  452.                                                                 else
  453.                                                                 //direction = "Left";//prevCorr
  454.                                                                 direction = "Down";
  455.                                                             }
  456.                                                             pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "up;";
  457.                                                             currentTrackless.Left = islandCurrentX;
  458.                                                             currentTrackless.Top = islandCurrentY;
  459.                                                             //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
  460.                                                         }
  461. pth += "\n" + islandCurrentX + ":" + islandCurrentY + ":" + "up;";
  462.                                                             currentTrackless.Left = islandCurrentX;
  463.                                                             currentTrackless.Top = islandCurrentY;
  464.                                                             //MessageBox.Show(":" + currentTrackless.Left + ":" + currentTrackless.Top + ":");
  465.                                                         }
  466.                                                     }
Add Comment
Please, Sign In to add comment