コード例 #1
0
        public static ArrayList turn_round_object_quadric(IAroundObject obj, int x1, int y1, int x2, int y2, ArrayList around_objs)
        {
            Hashtable visited = new Hashtable();

            visited.Add(obj, obj);
            return(turn_round_object_quadric1(obj, x1, y1, x2, y2, visited, around_objs));
        }
コード例 #2
0
        public static ArrayList turn_round_object_quadric1( IAroundObject obj, int x1, int y1, int x2, int y2, Hashtable visited, ArrayList around_objects )
        {
            Rectangle rect = obj.AroundRect;
            ArrayList path1 = new ArrayList();
            ArrayList path2 = new ArrayList();
            int dy, dx, i;
            int len1, len2;

            if( y1 == rect.Top || y1 == rect.Bottom ) {
                path1.Add( new Point(rect.Left, y1) );
                dy = y2 - y1;
                int y = y1 + Math.Sign( dy ) * rect.Height;
                len1 = x1 - rect.Left;

                if( Math.Abs( dy ) < rect.Height ) {
                    if( x2 != rect.Left ) {
                        path1.Add( new Point( rect.Left, y ) );
                        path1.Add( new Point( rect.Right, y ) );
                        len1 += rect.Height + rect.Width;
                        len1 += rect.Height - Math.Abs( dy );
                    } else
                        len1 += Math.Abs( dy );
                } else {
                    if( x2 != rect.Left ) {
                        path1.Add( new Point( rect.Left, y ) );
                        len1 += rect.Height;
                        len1 += x2 - rect.Left;
                    }
                }

                path2.Add( new Point( rect.Right, y1 ) );
                len2 = rect.Right - x1;
                if( Math.Abs( dy ) < rect.Height ) {
                    if( x2 != rect.Right ) {
                        path2.Add( new Point( rect.Right, y ) );
                        path2.Add( new Point( rect.Left, y ) );
                        len2 += rect.Height + rect.Width;
                        len2 += rect.Height - Math.Abs( dy );
                    } else
                        len2 += Math.Abs( dy );
                } else {
                    if( x2 != rect.Right ) {
                        path2.Add( new Point( rect.Right, y ) );
                        len2 += rect.Height;
                        len2 += rect.Right - x2;
                    }
                }
            } else {
                path1.Add( new Point( x1, rect.Top ) );
                dx = x2 - x1;
                int x = x1 + Math.Sign( dx ) * rect.Width;

                len1 = y1 - rect.Top;
                if( Math.Abs( dx ) < rect.Width ) {
                    if( y2 != rect.Top ) {
                        path1.Add( new Point( x, rect.Top ) );
                        path1.Add( new Point( x, rect.Bottom ) );
                        len1 += rect.Width + rect.Height;
                        len1 += rect.Width - Math.Abs( dx );
                    } else
                        len1 += Math.Abs( dx );
                } else {
                    if( y2 != rect.Top ) {
                        path1.Add( new Point( x, rect.Top ) );
                        len1 += rect.Width;
                        len1 += y2 - rect.Top;
                    }
                }

                path2.Add( new Point( x1, rect.Bottom ) );
                len2 = rect.Bottom - y1;
                if( Math.Abs( dx ) < rect.Width ) {
                    if( y2 != rect.Bottom ) {
                        path2.Add( new Point( x, rect.Bottom ) );
                        path2.Add( new Point( x, rect.Top ) );
                        len2 += rect.Width + rect.Height;
                        len2 += rect.Width - Math.Abs( dx );
                    } else
                        len2 += Math.Abs( dx );
                } else {
                    if( y2 != rect.Bottom ) {
                        path2.Add( new Point( x, rect.Bottom ) );
                        len2 += rect.Width;
                        len2 += rect.Bottom - y2;
                    }
                }
            }

            Point first = new Point( x1, y1 );
            Point last = new Point( x2, y2 );
            Point prev = first;
            bool path1_good = true;
            for( i = 0; path1_good && i <= path1.Count; i++ ) {
                Point pt;
                if( i != path1.Count )
                    pt = (Point)path1[i];
                else
                    pt = last;
                foreach( IAroundObject o in around_objects ) {
                    if( Geometry.rect_inters_with_quadric_segment( o.AroundRect, prev.X, prev.Y, pt.X, pt.Y ) ) {
                        path1_good = false;
                        break;
                    }
                }
                prev = pt;
            }

            bool path2_good = true;
            prev = first;
            for( i = 0; path2_good && i <= path2.Count; i++ ) {
                Point pt;
                if( i != path2.Count )
                    pt = (Point)path2[i];
                else
                    pt = last;
                foreach( IAroundObject o in around_objects ) {
                    if( Geometry.rect_inters_with_quadric_segment( o.AroundRect, prev.X, prev.Y, pt.X, pt.Y ) ) {
                        path2_good = false;
                        break;
                    }
                }
                prev = pt;
            }

            if( path1_good && path2_good ) {
                if( len1 < len2 )
                    return path1;
                else
                    return path2;
            }

            if( path1_good )
                return path1;
            else
                return path2;
        }
コード例 #3
0
        public static ArrayList turn_round_object_quadric1(IAroundObject obj, int x1, int y1, int x2, int y2, Hashtable visited, ArrayList around_objects)
        {
            Rectangle rect = obj.AroundRect;
            ArrayList path1 = new ArrayList();
            ArrayList path2 = new ArrayList();
            int       dy, dx, i;
            int       len1, len2;

            if (y1 == rect.Top || y1 == rect.Bottom)
            {
                path1.Add(new Point(rect.Left, y1));
                dy = y2 - y1;
                int y = y1 + Math.Sign(dy) * rect.Height;
                len1 = x1 - rect.Left;

                if (Math.Abs(dy) < rect.Height)
                {
                    if (x2 != rect.Left)
                    {
                        path1.Add(new Point(rect.Left, y));
                        path1.Add(new Point(rect.Right, y));
                        len1 += rect.Height + rect.Width;
                        len1 += rect.Height - Math.Abs(dy);
                    }
                    else
                    {
                        len1 += Math.Abs(dy);
                    }
                }
                else
                {
                    if (x2 != rect.Left)
                    {
                        path1.Add(new Point(rect.Left, y));
                        len1 += rect.Height;
                        len1 += x2 - rect.Left;
                    }
                }

                path2.Add(new Point(rect.Right, y1));
                len2 = rect.Right - x1;
                if (Math.Abs(dy) < rect.Height)
                {
                    if (x2 != rect.Right)
                    {
                        path2.Add(new Point(rect.Right, y));
                        path2.Add(new Point(rect.Left, y));
                        len2 += rect.Height + rect.Width;
                        len2 += rect.Height - Math.Abs(dy);
                    }
                    else
                    {
                        len2 += Math.Abs(dy);
                    }
                }
                else
                {
                    if (x2 != rect.Right)
                    {
                        path2.Add(new Point(rect.Right, y));
                        len2 += rect.Height;
                        len2 += rect.Right - x2;
                    }
                }
            }
            else
            {
                path1.Add(new Point(x1, rect.Top));
                dx = x2 - x1;
                int x = x1 + Math.Sign(dx) * rect.Width;

                len1 = y1 - rect.Top;
                if (Math.Abs(dx) < rect.Width)
                {
                    if (y2 != rect.Top)
                    {
                        path1.Add(new Point(x, rect.Top));
                        path1.Add(new Point(x, rect.Bottom));
                        len1 += rect.Width + rect.Height;
                        len1 += rect.Width - Math.Abs(dx);
                    }
                    else
                    {
                        len1 += Math.Abs(dx);
                    }
                }
                else
                {
                    if (y2 != rect.Top)
                    {
                        path1.Add(new Point(x, rect.Top));
                        len1 += rect.Width;
                        len1 += y2 - rect.Top;
                    }
                }

                path2.Add(new Point(x1, rect.Bottom));
                len2 = rect.Bottom - y1;
                if (Math.Abs(dx) < rect.Width)
                {
                    if (y2 != rect.Bottom)
                    {
                        path2.Add(new Point(x, rect.Bottom));
                        path2.Add(new Point(x, rect.Top));
                        len2 += rect.Width + rect.Height;
                        len2 += rect.Width - Math.Abs(dx);
                    }
                    else
                    {
                        len2 += Math.Abs(dx);
                    }
                }
                else
                {
                    if (y2 != rect.Bottom)
                    {
                        path2.Add(new Point(x, rect.Bottom));
                        len2 += rect.Width;
                        len2 += rect.Bottom - y2;
                    }
                }
            }

            Point first      = new Point(x1, y1);
            Point last       = new Point(x2, y2);
            Point prev       = first;
            bool  path1_good = true;

            for (i = 0; path1_good && i <= path1.Count; i++)
            {
                Point pt;
                if (i != path1.Count)
                {
                    pt = (Point)path1[i];
                }
                else
                {
                    pt = last;
                }
                foreach (IAroundObject o in around_objects)
                {
                    if (Geometry.rect_inters_with_quadric_segment(o.AroundRect, prev.X, prev.Y, pt.X, pt.Y))
                    {
                        path1_good = false;
                        break;
                    }
                }
                prev = pt;
            }

            bool path2_good = true;

            prev = first;
            for (i = 0; path2_good && i <= path2.Count; i++)
            {
                Point pt;
                if (i != path2.Count)
                {
                    pt = (Point)path2[i];
                }
                else
                {
                    pt = last;
                }
                foreach (IAroundObject o in around_objects)
                {
                    if (Geometry.rect_inters_with_quadric_segment(o.AroundRect, prev.X, prev.Y, pt.X, pt.Y))
                    {
                        path2_good = false;
                        break;
                    }
                }
                prev = pt;
            }

            if (path1_good && path2_good)
            {
                if (len1 < len2)
                {
                    return(path1);
                }
                else
                {
                    return(path2);
                }
            }

            if (path1_good)
            {
                return(path1);
            }
            else
            {
                return(path2);
            }
        }
コード例 #4
0
        public static ArrayList turn_round_object_quadric( IAroundObject obj, int x1, int y1, int x2, int y2, ArrayList around_objs )
        {
            Hashtable visited = new Hashtable();

            visited.Add( obj, obj );
            return turn_round_object_quadric1( obj, x1, y1, x2, y2, visited, around_objs );
        }