Ejemplo n.º 1
0
        /// <summary>
        /// Copy constructor that copies the polygon given.
        /// </summary>
        public PolySimple(PolySimple poly)
        {
            // Copy the fields
            m_Contributes = poly.m_Contributes;

            // Copy the points
            foreach (PointF p in poly.m_List)
            {
                m_List.Add(new PointF(p.X, p.Y));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Translates the polygons and returns the results as a new
        /// polygon.
        /// </summary>
        public IPoly Translate(double dx, double dy)
        {
            // Create a new polygon
            PolySimple poly = new PolySimple();

            // Go through those elements
            for (int j = 0; j < PointCount; j++)
            {
                // Get the points
                double x = dx + GetX(j);
                double y = dy + GetY(j);

                // Add it
                poly.Add(x, y);
            }

            // Return the results
            return(poly);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copy constructor that copies the polygon given.
        /// </summary>
        public PolySimple(PolySimple poly)
        {
            // Copy the fields
            m_Contributes = poly.m_Contributes;

            // Copy the points
            foreach (PointF p in poly.m_List)
                m_List.Add(new PointF(p.X, p.Y));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Translates the polygons and returns the results as a new
        /// polygon.
        /// </summary>
        public IPoly Translate(double dx, double dy)
        {
            // Create a new polygon
            PolySimple poly = new PolySimple();

            // Go through those elements
            for (int j = 0; j < PointCount; j++)
            {
                // Get the points
                double x = dx + GetX(j);
                double y = dy + GetY(j);

                // Add it
                poly.Add(x, y);
            }

            // Return the results
            return poly;
        }
Ejemplo n.º 5
0
        /**
         * Return true if the given object is equal to this one.
         * <p>
         * <strong>WARNING:</strong> This method failse if the first point
         * appears more than once in the list.
         */
        public override bool Equals(object obj)
        {
            // See if we can cast the object
            if (!(obj is PolySimple))
            {
                return(false);
            }

            PolySimple that = (PolySimple)obj;

            // Compare the sizees
            int this_num = this.m_List.Count;
            int that_num = that.m_List.Count;

            if (this_num != that_num)
            {
                return(false);
            }

            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // !!! WARNING: This is not the greatest algorithm.  It fails if !!!
            // !!! the first point in "this" poly appears more than once.    !!!
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            if (this_num > 0)
            {
                double this_x           = this.GetX(0);
                double this_y           = this.GetY(0);
                int    that_first_index = -1;
                int    that_index       = 0;
                for (that_index = 0; (that_first_index == -1) && (that_index < that_num); that_index++)
                {
                    double that_x = that.GetX(that_index);
                    double that_y = that.GetY(that_index);
                    if ((this_x == that_x) && (this_y == that_y))
                    {
                        that_first_index = that_index;
                    }
                }
                if (that_first_index == -1)
                {
                    return(false);
                }
                that_index = that_first_index;
                for (int this_index = 0; this_index < this_num; this_index++)
                {
                    this_x = this.GetX(this_index);
                    this_y = this.GetY(this_index);
                    double that_x = that.GetX(that_index);
                    double that_y = that.GetY(that_index);

                    if ((this_x != that_x) || (this_y != that_y))
                    {
                        return(false);
                    }

                    that_index++;
                    if (that_index >= that_num)
                    {
                        that_index = 0;
                    }
                }
            }
            return(true);
        }