Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///By (Contract Miner username Noobplus)
- ///Usage
- ///DataTable with Structure
- /// Image_Length,Image_Width are size datacolumns
- /// Starting_X, Starting_Y are position datacolumns
- /// the four are dimensions of the images to fit in the parent picturebox.
- /// pictureBox2.Width,pictureBox2.Height are dimensions of parent pattern in which images are to be fit
- ///Description
- /// The pictureBox2 is the pattern. In this pattern, smaller images can be placed. The images are stored in C# DataTable as dimensions and positions. When the user clicks on the pictureBox2 where there is not image, the following code checks for irregular polygons in the empty area counterclockwise.
- ///Hope it helps someone ;)
- //regions
- #region regions
- List<Point> points = new List<Point>();
- DataRow[] drNearestTop = dtCurrentPattern.Select("Starting_Y+Image_Length<" + controlRelatedCoords.Y + " and Starting_X<=" + controlRelatedCoords.X + " and Starting_X+Image_Width>=" + controlRelatedCoords.X + "");
- drNearestTop = drNearestTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- int islandStartX = 0;
- int islandStartY = 0;
- if (drNearestTop.Length > 0)
- {
- DataRow[] innerTop = dtCurrentPattern.Select("Starting_Y=" + (DataHelper.GetInt(drNearestTop[0]["Starting_Y"]) + DataHelper.GetInt(drNearestTop[0]["Image_Length"])) + "" +
- " and Starting_X+Image_Width<=" + controlRelatedCoords.X + "" +
- " and Starting_X+Image_Width>" + DataHelper.GetInt(drNearestTop[0]["Starting_X"]) + "" +
- "");
- innerTop = innerTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"])+ DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (innerTop.Length>0)
- {
- islandStartX = (DataHelper.GetInt(innerTop[0]["Starting_X"]) + DataHelper.GetInt(innerTop[0]["Image_Width"]));
- islandStartY = (DataHelper.GetInt(drNearestTop[0]["Starting_Y"]) + DataHelper.GetInt(drNearestTop[0]["Image_Length"]));
- }
- else
- {
- islandStartX = (DataHelper.GetInt(drNearestTop[0]["Starting_X"]) + DataHelper.GetInt(drNearestTop[0]["Image_Width"]));
- islandStartY = (DataHelper.GetInt(drNearestTop[0]["Starting_Y"]) + DataHelper.GetInt(drNearestTop[0]["Image_Length"]));
- }
- }
- else
- {
- //nearest left side horizontally
- drNearestTop = dtCurrentPattern.Select("Starting_Y+Image_Length<" + controlRelatedCoords.Y + " and Starting_X>=" + controlRelatedCoords.X + " ");
- drNearestTop = drNearestTop.OrderBy(row => DataHelper.GetInt(row["Starting_X"])).ToArray<DataRow>();
- if (drNearestTop.Length > 0)
- {
- islandStartX = DataHelper.GetInt(drNearestTop[0]["Starting_X"]);
- islandStartY = DataHelper.GetInt(drNearestTop[0]["Starting_Y"]);
- }
- else
- {
- //nearest left side vertically
- drNearestTop = dtCurrentPattern.Select("Starting_Y<" + controlRelatedCoords.Y + " and Starting_X>=" + controlRelatedCoords.X + " ");
- drNearestTop = drNearestTop.OrderBy(row => DataHelper.GetInt(row["Starting_X"])).ToArray<DataRow>();
- if (drNearestTop.Length > 0)
- {
- islandStartX = DataHelper.GetInt(drNearestTop[0]["Starting_X"]);
- islandStartY = DataHelper.GetInt(drNearestTop[0]["Starting_Y"]);
- }
- else
- {
- islandStartX = pictureBox2.Width;
- islandStartY = 0;
- }
- }
- }
- //MessageBox.Show("nearestTop:" + islandStartX + ":" + islandStartY);
- points.Add(new Point(islandStartX, islandStartY));
- int islandCurrentX = -1;
- int islandCurrentY = -1;
- ///directions
- ///0 left
- ///1 up
- ///2 right
- ///3 down
- string direction = "Left";
- int count = 0;
- string pth = "";
- //testing
- //currentTrackless.Width = 20;
- //currentTrackless.Height = 20;
- //
- while ((islandCurrentX != islandStartX || islandCurrentY != islandStartY) && count < 500)
- {
- int tempIslandX = (islandCurrentX == -1 ? islandStartX : islandCurrentX);
- int tempIslandY = (islandCurrentY == -1 ? islandStartY : islandCurrentY);
- string oldDirection = direction;
- //break;
- count++;
- if (direction == "Left" )//&& 1==2)
- {
- DataRow[] drLeftBottom = dtCurrentPattern.Select("Starting_X+Image_Width=" + tempIslandX + " and " +
- "Starting_Y<=" + tempIslandY + " and " +
- "Starting_Y+Image_Length>" + tempIslandY + "");
- //drLeftBottom = drLeftBottom.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- //DataRow[] drLeftBottomDownwards = dtCurrentPattern.Select("");//inside ifdrlb>0
- DataRow[] drLeftLeft = dtCurrentPattern.Select("Starting_X<" + tempIslandX + " and " +
- "Starting_X+Image_Width>="+tempIslandX+" and " +
- "Starting_Y+Image_Length=" + tempIslandY + "");
- //for leftleft two conditions: if before leftwards ending any box is below
- DataRow[] drLeftTop = dtCurrentPattern.Select("Starting_X=" + tempIslandX + " and " +
- "Starting_Y<" + tempIslandY + " and " +
- "Starting_Y+Image_Length>=" + tempIslandY + "");
- DataRow[] drRight= dtCurrentPattern.Select("Starting_X<=" + tempIslandX + " and " +
- "Starting_X+Image_Length>" + tempIslandY + " and " +
- "Starting_Y=" + tempIslandY + "");
- if (drLeftBottom.Length>0)
- {
- DataRow[] drParallelDown = dtCurrentPattern.Select("Starting_X=" + (DataHelper.GetInt(drLeftBottom[0]["Starting_X"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Width"])) + " and" +
- " Starting_Y>" + tempIslandY + " and " +
- " Starting_Y<=" + (DataHelper.GetInt(drLeftBottom[0]["Starting_Y"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Length"])) + "");
- drParallelDown = drParallelDown.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
- if(drParallelDown.Length>0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = DataHelper.GetInt(drParallelDown[0]["Starting_Y"]);
- direction = "Right";
- }
- else
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = (DataHelper.GetInt(drLeftBottom[0]["Starting_Y"])+ DataHelper.GetInt(drLeftBottom[0]["Image_Length"]));
- direction = "Down";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if(tempIslandX==0)
- {
- DataRow[] drParallelDown = dtCurrentPattern.Select("Starting_X=" + tempIslandX + " and" +
- " Starting_Y>" + tempIslandY + " " +
- " ");
- drParallelDown = drParallelDown.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
- if (drParallelDown.Length > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = DataHelper.GetInt(drParallelDown[0]["Starting_Y"]);
- direction = "Right";
- }
- else
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = pictureBox2.Height;
- direction = "Right";//"Right"Prevold
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if(drLeftLeft.Length>0)
- {
- DataRow[] drParallelLeft = dtCurrentPattern.Select("Starting_Y=" + (DataHelper.GetInt(drLeftLeft[0]["Starting_Y"]) + DataHelper.GetInt(drLeftLeft[0]["Image_Length"])) + " and" +
- " Starting_X<" + tempIslandX + " and " +
- " Starting_X>=" + (DataHelper.GetInt(drLeftLeft[0]["Starting_X"])) + "");
- drParallelLeft = drParallelLeft.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"])+ DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelLeft.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelLeft[0]["Starting_X"])+ DataHelper.GetInt(drParallelLeft[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- else
- {
- islandCurrentX = (DataHelper.GetInt(drLeftLeft[0]["Starting_X"]) );
- islandCurrentY = tempIslandY;
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandY == 0)
- {
- DataRow[] drParallelLeft = dtCurrentPattern.Select("Starting_Y=" + tempIslandY + " and" +
- " Starting_X<" + tempIslandX + "");
- drParallelLeft = drParallelLeft.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelLeft.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelLeft[0]["Starting_X"]) + DataHelper.GetInt(drParallelLeft[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- else
- {
- islandCurrentX = 0;
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drLeftTop.Length > 0)
- {
- DataRow[] drParallellTop = dtCurrentPattern.Select("Starting_X+Image_Width=" + (DataHelper.GetInt(drLeftTop[0]["Starting_X"])) + " and" +
- " Starting_Y+Image_Length<" + tempIslandY + " and " +
- " Starting_Y+Image_Length>=" + (DataHelper.GetInt(drLeftTop[0]["Starting_Y"])) + "");
- drParallellTop = drParallellTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- if (drParallellTop.Length > 0)
- {
- islandCurrentY = (DataHelper.GetInt(drParallellTop[0]["Starting_Y"]) + DataHelper.GetInt(drParallellTop[0]["Image_Length"]));
- //direction = "Down";
- direction = "Up";
- islandCurrentX = tempIslandX;
- }
- else
- {
- islandCurrentY = (DataHelper.GetInt(drLeftTop[0]["Starting_Y"]));
- islandCurrentX = tempIslandX;
- //direction = "Right";//old
- direction = "Left";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandX==pictureBox2.Width)
- {
- DataRow[] drParallellTop = dtCurrentPattern.Select("Starting_X+Image_Width=" + tempIslandX + " and" +
- " Starting_Y+Image_Length<" + tempIslandY + " ");
- drParallellTop = drParallellTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- if (drParallellTop.Length > 0)
- {
- islandCurrentY = (DataHelper.GetInt(drParallellTop[0]["Starting_Y"]) + DataHelper.GetInt(drParallellTop[0]["Image_Length"]));
- //direction = "Down";
- direction = "Up";
- islandCurrentX = tempIslandX;
- }
- else
- {
- islandCurrentY = 0;
- islandCurrentX = tempIslandX;
- direction = "Left";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- //else if (drRight.Length > 0)
- //{
- // DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + (DataHelper.GetInt(drRight[0]["Starting_Y"]) + DataHelper.GetInt(drRight[0]["Image_Length"])) + " and" +
- // " Starting_X>" + tempIslandX + " and " +
- // " Starting_X<=" + (DataHelper.GetInt(drRight[0]["Starting_X"])+ DataHelper.GetInt(drRight[0]["Image_Width"])) + "");
- // drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- // if (drParallelRight.Length > 0)
- // {
- // islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]) );
- // islandCurrentY = tempIslandY;
- // direction = "Up";
- // }
- // else
- // {
- // islandCurrentX = (DataHelper.GetInt(drRight[0]["Starting_X"])+ DataHelper.GetInt(drRight[0]["Image_Length"]));
- // islandCurrentY = tempIslandY;
- // direction = "Right";
- // }
- // points.Add(new Point(islandCurrentX, islandCurrentY));
- //}
- //else if (tempIslandY == pictureBox2.Height)
- //{
- // DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + pictureBox2.Height + " and" +
- // " Starting_X>" + tempIslandX + " ");
- // drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- // if (drParallelRight.Length > 0)
- // {
- // islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]));
- // islandCurrentY = tempIslandY;
- // direction = "Up";
- // }
- // else
- // {
- // islandCurrentX = pictureBox2.Width;
- // islandCurrentY = tempIslandY;
- // direction = "Right";
- // }
- // points.Add(new Point(islandCurrentX, islandCurrentY));
- //}
- else
- {
- direction = "Down";
- }
- }
- #region Down
- else if(direction=="Down")
- {
- DataRow[] drRight = dtCurrentPattern.Select("Starting_X<=" + tempIslandX + " and " +
- "Starting_X+Image_Width>" + tempIslandX + " and " +
- "Starting_Y=" + tempIslandY + "");
- DataRow[] drLeftBottom = dtCurrentPattern.Select("Starting_X+Image_Width=" + tempIslandX + " and " +
- "Starting_Y<=" + tempIslandY + " and " +
- "Starting_Y+Image_Length>" + tempIslandY + "");
- //drLeftBottom = drLeftBottom.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- //DataRow[] drLeftBottomDownwards = dtCurrentPattern.Select("");//inside ifdrlb>0
- DataRow[] drLeftLeft = dtCurrentPattern.Select("Starting_X<" + tempIslandX + " and " +
- "Starting_X+Image_Width>=" + tempIslandX + " and " +
- "Starting_Y+Image_Length=" + tempIslandY + "");
- //for leftleft two conditions: if before leftwards ending any box is below
- if (drRight.Length > 0)
- {
- DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + (DataHelper.GetInt(drRight[0]["Starting_Y"]) ) + " and" +//dtCurrentPattern.Select("Starting_Y+Image_Length=" + (DataHelper.GetInt(drRight[0]["Starting_Y"]) + DataHelper.GetInt(drRight[0]["Image_Length"])) + " and" +" Starting_X>" + tempIslandX + " and " +" Starting_X<=" + (DataHelper.GetInt(drRight[0]["Starting_X"]) + DataHelper.GetInt(drRight[0]["Image_Width"])) + "")
- " Starting_X>" + tempIslandX + " and " +
- " Starting_X<=" + (DataHelper.GetInt(drRight[0]["Starting_X"]) + DataHelper.GetInt(drRight[0]["Image_Width"])) + "");
- drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelRight.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- direction = "Up";
- }
- else
- {
- islandCurrentX = (DataHelper.GetInt(drRight[0]["Starting_X"]) + DataHelper.GetInt(drRight[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandY == pictureBox2.Height)
- {
- DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + pictureBox2.Height + " and" +
- " Starting_X>" + tempIslandX + " ");
- drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelRight.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- direction = "Up";
- }
- else
- {
- islandCurrentX = pictureBox2.Width;
- islandCurrentY = tempIslandY;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drLeftBottom.Length > 0)
- {
- DataRow[] drParallelDown = dtCurrentPattern.Select("Starting_X=" + (DataHelper.GetInt(drLeftBottom[0]["Starting_X"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Width"])) + " and" +
- " Starting_Y>" + tempIslandY + " and " +
- " Starting_Y<=" + (DataHelper.GetInt(drLeftBottom[0]["Starting_Y"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Length"])) + "");
- drParallelDown = drParallelDown.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
- if (drParallelDown.Length > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = DataHelper.GetInt(drParallelDown[0]["Starting_Y"]);
- direction = "Right";
- }
- else
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = (DataHelper.GetInt(drLeftBottom[0]["Starting_Y"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Length"]));
- direction = "Down";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandX == 0)
- {
- DataRow[] drParallelDown = dtCurrentPattern.Select("Starting_X=" + tempIslandX + " and" +
- " Starting_Y>" + tempIslandY + " " +
- " ");
- drParallelDown = drParallelDown.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
- if (drParallelDown.Length > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = DataHelper.GetInt(drParallelDown[0]["Starting_Y"]);
- direction = "Right";
- }
- else
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = pictureBox2.Height;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drLeftLeft.Length > 0)
- {
- DataRow[] drParallelLeft = dtCurrentPattern.Select("Starting_Y=" + (DataHelper.GetInt(drLeftLeft[0]["Starting_Y"]) + DataHelper.GetInt(drLeftLeft[0]["Image_Length"])) + " and" +
- " Starting_X<" + tempIslandX + " and " +
- " Starting_X>=" + (DataHelper.GetInt(drLeftLeft[0]["Starting_X"])) + "");
- drParallelLeft = drParallelLeft.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelLeft.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelLeft[0]["Starting_X"]) + DataHelper.GetInt(drParallelLeft[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- else
- {
- islandCurrentX = (DataHelper.GetInt(drLeftLeft[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandY == 0)
- {
- DataRow[] drParallelLeft = dtCurrentPattern.Select("Starting_Y=" + tempIslandY + " and" +
- " Starting_X<" + tempIslandX + "");
- drParallelLeft = drParallelLeft.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelLeft.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelLeft[0]["Starting_X"]) + DataHelper.GetInt(drParallelLeft[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- else
- {
- islandCurrentX = 0;
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else
- {
- direction = "Right";
- }
- }
- #endregion
- #region Right
- else if(direction=="Right")
- {
- DataRow[] drLeftTop = dtCurrentPattern.Select("Starting_X=" + tempIslandX + " and " +
- "Starting_Y<" + tempIslandY + " and " +
- "Starting_Y+Image_Length>=" + tempIslandY + "");
- DataRow[] drRight = dtCurrentPattern.Select("Starting_X<=" + tempIslandX + " and " +
- "Starting_X+Image_Width>" + tempIslandX + " and " +
- "Starting_Y=" + tempIslandY + "");
- DataRow[] drLeftBottom = dtCurrentPattern.Select("Starting_X+Image_Width=" + tempIslandX + " and " +
- "Starting_Y<=" + tempIslandY + " and " +
- "Starting_Y+Image_Length>" + tempIslandY + "");
- if (drLeftTop.Length > 0)
- {
- DataRow[] drParallellTop = dtCurrentPattern.Select("Starting_X+Image_Width=" + (DataHelper.GetInt(drLeftTop[0]["Starting_X"])) + " and" +
- " Starting_Y+Image_Length<" + tempIslandY + " and " +
- " Starting_Y+Image_Length>=" + (DataHelper.GetInt(drLeftTop[0]["Starting_Y"])) + "");
- drParallellTop = drParallellTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- if (drParallellTop.Length > 0)
- {
- islandCurrentY = (DataHelper.GetInt(drParallellTop[0]["Starting_Y"]) + DataHelper.GetInt(drParallellTop[0]["Image_Length"]));
- direction = "Up";
- islandCurrentX = tempIslandX;
- }
- else
- {
- islandCurrentY = (DataHelper.GetInt(drLeftTop[0]["Starting_Y"]));
- islandCurrentX = tempIslandX;
- //direction="Right";//old
- direction = "Left";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandX == pictureBox2.Width)
- {
- DataRow[] drParallellTop = dtCurrentPattern.Select("Starting_X+Image_Width=" + tempIslandX + " and" +
- " Starting_Y+Image_Length<" + tempIslandY + " ");
- drParallellTop = drParallellTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- if (drParallellTop.Length > 0)
- {
- islandCurrentY = (DataHelper.GetInt(drParallellTop[0]["Starting_Y"]) + DataHelper.GetInt(drParallellTop[0]["Image_Length"]));
- //direction = "Down";
- direction = "Up";
- islandCurrentX = tempIslandX;
- }
- else
- {
- islandCurrentY = 0;
- islandCurrentX = tempIslandX;
- direction = "Left";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drRight.Length > 0)
- {
- DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + (DataHelper.GetInt(drRight[0]["Starting_Y"]) ) + " and" +//+ DataHelper.GetInt(drRight[0]["Image_Length"])
- " Starting_X>" + tempIslandX + " and " +
- " Starting_X<=" + (DataHelper.GetInt(drRight[0]["Starting_X"]) + DataHelper.GetInt(drRight[0]["Image_Width"])) + "");
- drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelRight.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- direction = "Up";
- }
- else
- {
- islandCurrentX = (DataHelper.GetInt(drRight[0]["Starting_X"]) + DataHelper.GetInt(drRight[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandY == pictureBox2.Height)
- {
- DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + pictureBox2.Height + " and" +
- " Starting_X>" + tempIslandX + " ");
- drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelRight.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- direction = "Up";
- }
- else
- {
- islandCurrentX = pictureBox2.Width;
- islandCurrentY = tempIslandY;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drLeftBottom.Length > 0)
- {
- DataRow[] drParallelDown = dtCurrentPattern.Select("Starting_X=" + (DataHelper.GetInt(drLeftBottom[0]["Starting_X"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Width"])) + " and" +
- " Starting_Y>" + tempIslandY + " and " +
- " Starting_Y<=" + (DataHelper.GetInt(drLeftBottom[0]["Starting_Y"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Length"])) + "");
- drParallelDown = drParallelDown.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
- if (drParallelDown.Length > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = DataHelper.GetInt(drParallelDown[0]["Starting_Y"]);
- direction = "Right";
- }
- else
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = (DataHelper.GetInt(drLeftBottom[0]["Starting_Y"]) + DataHelper.GetInt(drLeftBottom[0]["Image_Length"]));
- direction = "Down";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandX == 0)
- {
- DataRow[] drParallelDown = dtCurrentPattern.Select("Starting_X=" + tempIslandX + " and" +
- " Starting_Y>" + tempIslandY + " " +
- " ");
- drParallelDown = drParallelDown.OrderBy(row => DataHelper.GetInt(row["Starting_Y"])).ToArray<DataRow>();
- if (drParallelDown.Length > 0)
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = DataHelper.GetInt(drParallelDown[0]["Starting_Y"]);
- direction = "Right";
- }
- else
- {
- islandCurrentX = tempIslandX;
- islandCurrentY = pictureBox2.Height;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else
- {
- direction = "Up";
- }
- }
- #endregion
- else if(direction=="Up")
- {
- DataRow[] drLeftLeft = dtCurrentPattern.Select("Starting_X<" + tempIslandX + " and " +
- "Starting_X+Image_Width>=" + tempIslandX + " and " +
- "Starting_Y+Image_Length=" + tempIslandY + "");
- DataRow[] drLeftTop = dtCurrentPattern.Select("Starting_X=" + tempIslandX + " and " +
- "Starting_Y<" + tempIslandY + " and " +
- "Starting_Y+Image_Length>=" + tempIslandY + "");
- DataRow[] drRight = dtCurrentPattern.Select("Starting_X<=" + tempIslandX + " and " +
- "Starting_X+Image_Width>" + tempIslandX + " and " +
- "Starting_Y=" + tempIslandY + "");
- if (drLeftLeft.Length > 0)
- {
- DataRow[] drParallelLeft = dtCurrentPattern.Select("Starting_Y=" + (DataHelper.GetInt(drLeftLeft[0]["Starting_Y"]) + DataHelper.GetInt(drLeftLeft[0]["Image_Length"])) + " and" +
- " Starting_X<" + tempIslandX + " and " +
- " Starting_X>=" + (DataHelper.GetInt(drLeftLeft[0]["Starting_X"])) + "");
- drParallelLeft = drParallelLeft.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelLeft.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelLeft[0]["Starting_X"]) + DataHelper.GetInt(drParallelLeft[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- else
- {
- islandCurrentX = (DataHelper.GetInt(drLeftLeft[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandY == 0)
- {
- DataRow[] drParallelLeft = dtCurrentPattern.Select("Starting_Y=" + tempIslandY + " and" +
- " Starting_X<" + tempIslandX + "");
- drParallelLeft = drParallelLeft.OrderByDescending(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelLeft.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelLeft[0]["Starting_X"]) + DataHelper.GetInt(drParallelLeft[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- else
- {
- islandCurrentX = 0;
- islandCurrentY = tempIslandY;
- direction = "Down";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drLeftTop.Length > 0)
- {
- DataRow[] drParallellTop = dtCurrentPattern.Select("Starting_X+Image_Width=" + (DataHelper.GetInt(drLeftTop[0]["Starting_X"])) + " and" +
- " Starting_Y+Image_Length<" + tempIslandY + " and " +
- " Starting_Y+Image_Length>=" + (DataHelper.GetInt(drLeftTop[0]["Starting_Y"])) + "");
- drParallellTop = drParallellTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- if (drParallellTop.Length > 0)
- {
- islandCurrentY = (DataHelper.GetInt(drParallellTop[0]["Starting_Y"]) + DataHelper.GetInt(drParallellTop[0]["Image_Length"]));
- //direction = "Down";
- direction = "Up";
- islandCurrentX = tempIslandX;
- }
- else
- {
- islandCurrentY = (DataHelper.GetInt(drLeftTop[0]["Starting_Y"]));
- islandCurrentX = tempIslandX;
- //direction = "Right";//old
- direction = "Left";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandX == pictureBox2.Width)
- {
- DataRow[] drParallellTop = dtCurrentPattern.Select("Starting_X+Image_Width=" + tempIslandX + " and" +
- " Starting_Y+Image_Length<" + tempIslandY + " ");
- drParallellTop = drParallellTop.OrderByDescending(row => (DataHelper.GetInt(row["Starting_Y"]) + DataHelper.GetInt(row["Image_Length"]))).ToArray<DataRow>();
- if (drParallellTop.Length > 0)
- {
- islandCurrentY = (DataHelper.GetInt(drParallellTop[0]["Starting_Y"]) + DataHelper.GetInt(drParallellTop[0]["Image_Length"]));
- //direction = "Down";
- direction = "Up";
- islandCurrentX = tempIslandX;
- }
- else
- {
- islandCurrentY = 0;
- islandCurrentX = tempIslandX;
- direction = "Left";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (drRight.Length > 0)
- {
- DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + (DataHelper.GetInt(drRight[0]["Starting_Y"]) ) + " and" +//+ DataHelper.GetInt(drRight[0]["Image_Length"])
- " Starting_X>" + tempIslandX + " and " +
- " Starting_X<=" + (DataHelper.GetInt(drRight[0]["Starting_X"]) + DataHelper.GetInt(drRight[0]["Image_Width"])) + "");
- drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelRight.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- direction = "Up";
- }
- else
- {
- islandCurrentX = (DataHelper.GetInt(drRight[0]["Starting_X"]) + DataHelper.GetInt(drRight[0]["Image_Width"]));
- islandCurrentY = tempIslandY;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else if (tempIslandY > pictureBox2.Height)
- {
- DataRow[] drParallelRight = dtCurrentPattern.Select("Starting_Y+Image_Length=" + pictureBox2.Height + " and" +
- " Starting_X>" + tempIslandX + " ");
- drParallelRight = drParallelRight.OrderBy(row => (DataHelper.GetInt(row["Starting_X"]) + DataHelper.GetInt(row["Image_Width"]))).ToArray<DataRow>();
- if (drParallelRight.Length > 0)
- {
- islandCurrentX = (DataHelper.GetInt(drParallelRight[0]["Starting_X"]));
- islandCurrentY = tempIslandY;
- direction = "Up";
- }
- else
- {
- islandCurrentX = pictureBox2.Width;
- islandCurrentY = tempIslandY;
- direction = "Right";
- }
- points.Add(new Point(islandCurrentX, islandCurrentY));
- }
- else
- {
- direction = "Left";
- }
- }
- else
- {
- break;
- }
- pth += "\n(" + islandCurrentX + "," + islandCurrentY + "):"+ oldDirection+"->" + direction;
- }
- //points.Add(new Point(islandStartX, islandStartY));
- //points = points.Distinct().ToList<Point>();
- string pts = "";
- foreach(Control control in pictureBox2.Controls)
- {
- if(control.Name=="xy")
- {
- pictureBox2.Controls.Remove(control);
- }
- }
- foreach (Point p in points)
- {
- Label lbl = new Label();
- lbl.Name = "xy";
- lbl.AutoSize = true;
- lbl.Text= "(" + p.X + "," + p.Y + ")";
- lbl.Top = p.Y;
- lbl.Left = p.X;
- //pictureBox2.Controls.Add(lbl);
- //lbl.BringToFront();
- pts += "(" + p.X + "," + p.Y + ")";
- }
- //currentIsland.Region = points;
- currentIsland.Width = pictureBox2.Width;
- currentIsland.Height = pictureBox2.Height;
- using (GraphicsPath gp = new GraphicsPath())
- {
- gp.AddClosedCurve(points.ToArray());//correct
- currentIsland.Region = new Region(gp);//correct
- }
- currentIsland.BringToFront();
- currentIsland.points = points;//correct
- currentIsland.Invalidate();//correct
- //MessageBox.Show("region length:" + pts);
- //MessageBox.Show("region :" + pth);
- #endregion
Add Comment
Please, Sign In to add comment