////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Constructor
  * @param r
  * @param at
  */
 internal RectIterator(Rectangle r, AffineTransform at)
 {
     _x = r.GetX();
     _y = r.GetY();
     _w = r.GetWidth();
     _h = r.GetHeight();
     _affine = at;
     if (_w < 0 || _h < 0)
     {
         _index = 6;
     }
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Adds a <code>Rectangle</code> object to this
  * <code>Rectangle</code>.  The resulting <code>Rectangle</code>
  * is the union of the two <code>Rectangle</code> objects.
  * @param r the <code>Rectangle</code> to add to this
  * <code>Rectangle</code>.
  */
 public void Add(Rectangle r)
 {
     int x1 = Math.Min(GetMinX(), r.GetMinX());
     int x2 = Math.Max(GetMaxX(), r.GetMaxX());
     int y1 = Math.Min(GetMinY(), r.GetMinY());
     int y2 = Math.Max(GetMaxY(), r.GetMaxY());
     SetRect(x1, y1, x2 - x1, y2 - y1);
 }
Exemple #3
0
 public abstract void Enlarge(Rectangle r);
Exemple #4
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Determines whether or not the interior of the arc intersects
         * the interior of the specified rectangle.
         *
         * @param x The X coordinate of the rectangle's upper-left corner.
         * @param y The Y coordinate of the rectangle's upper-left corner.
         * @param w The width of the rectangle.
         * @param h The height of the rectangle.
         *
         * @return <CODE>true</CODE> if the arc intersects the rectangle,
         * <CODE>false</CODE> if the arc doesn't intersect the rectangle.
         */
        public override bool Intersects(int x, int y, int w, int h)
        {
            double aw = GetWidth();
            double ah = GetHeight();

            if (w <= 0 || h <= 0 || aw <= 0 || ah <= 0)
            {
                return false;
            }
            double ext = GetAngleExtent();
            if (ext == 0)
            {
                return false;
            }

            double ax = GetX();
            double ay = GetY();
            double axw = ax + aw;
            double ayh = ay + ah;
            double xw = x + w;
            double yh = y + h;

            // check bbox
            if (x >= axw || y >= ayh || xw <= ax || yh <= ay)
            {
                return false;
            }

            // extract necessary data
            double axc = GetCenterX();
            double ayc = GetCenterY();
            Point sp = GetStartPoint();
            Point ep = GetEndPoint();
            double sx = sp.GetX();
            double sy = sp.GetY();
            double ex = ep.GetX();
            double ey = ep.GetY();

            /*
             * Try to catch rectangles that intersect arc in areas
             * outside of rectagle with left top corner coordinates
             * (Min(center x, start point x, end point x),
             *  Min(center y, start point y, end point y))
             * and rigth bottom corner coordinates
             * (Max(center x, start point x, end point x),
             *  Max(center y, start point y, end point y)).
             * So we'll check axis segments outside of rectangle above.
             */
            if (ayc >= y && ayc <= yh)
            { // 0 and 180
                if ((sx < xw && ex < xw && axc < xw &&
                     axw > x && ContainsAngle(0)) ||
                    (sx > x && ex > x && axc > x &&
                     ax < xw && ContainsAngle(180)))
                {
                    return true;
                }
            }
            if (axc >= x && axc <= xw)
            { // 90 and 270
                if ((sy > y && ey > y && ayc > y &&
                     ay < yh && ContainsAngle(90)) ||
                    (sy < yh && ey < yh && ayc < yh &&
                     ayh > y && ContainsAngle(270)))
                {
                    return true;
                }
            }

            /*
             * For PIE we should check intersection with pie slices;
             * also we should do the same for arcs with extent is greater
             * than 180, because we should cover case of rectangle, which
             * situated between center of arc and chord, but does not
             * intersect the chord.
             */
            Rectangle rect = new Rectangle((int)(x + .5),
                        (int)(y + .5),
                        (int)(w + .5),
                        (int)(h + .5));
            if (_type == PIE || MathEx.Abs(ext) > 180)
            {
                // for PIE: try to find intersections with pie slices
                if (rect.IntersectsLine((int)(axc + .5),
                            (int)(ayc + .5),
                            (int)(sx + .5),
                            (int)(sy + .5)) ||
                rect.IntersectsLine((int)(axc + .5),
                        (int)(ayc + .5),
                        (int)(ex + .5),
                        (int)(ey + .5)))
                {
                    return true;
                }
            }
            else
            {
                // for CHORD and OPEN: try to find intersections with chord
                if (rect.IntersectsLine((int)(sx + .5),
                            (int)(sy + .5), (int)(ex + .5),
                            (int)(ey + .5)))
                {
                    return true;
                }
            }

            // finally check the rectangle corners inside the arc
            if (Contains(x, y) || Contains(x + w, y) ||
                Contains(x, y + h) || Contains(x + w, y + h))
            {
                return true;
            }

            return false;
        }
Exemple #5
0
 ///////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Constructs a new arc, initialized to the specified location,
  * size, angular extents, and closure type.
  *
  * @param ellipseBounds The framing rectangle that defines the
  * outer boundary of the full ellipse of which this arc is a
  * partial section.
  * @param start The starting angle of the arc in degrees.
  * @param extent The angular extent of the arc in degrees.
  * @param type The closure type for the arc:
  * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
  */
 public Arc(Rectangle ellipseBounds,
               double start, double extent, int type)
     : this(type)
 {
     X = ellipseBounds.GetX();
     Y = ellipseBounds.GetY();
     Width = ellipseBounds.GetWidth();
     Height = ellipseBounds.GetHeight();
     Start = start;
     Extent = extent;
 }
Exemple #6
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // 13JUN2009  -------------------  -------------      ----------------------
 // 08NOV2008  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Sets the location, size, angular extents, and closure type of
  * this arc to the specified values.
  *
  * @param rect The framing rectangle that defines the
  * outer boundary of the full ellipse of which this arc is a
  * partial section.
  * @param angSt The starting angle of the arc in degrees.
  * @param angExt The angular extent of the arc in degrees.
  * @param closure The closure type for the arc:
  * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
  */
 public void SetArc(Rectangle rect, double angSt, double angExt,
            int closure)
 {
     SetArc(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight(),
            angSt, angExt, closure);
 }
Exemple #7
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Resets this <code>Polygon</code> object to an empty polygon.
  * The coordinate arrays and the data in them are left untouched
  * but the number of points is reset to zero to mark the old
  * vertex data as invalid and to start accumulating new vertex
  * data at the beginning.
  * All internally-cached data relating to the old vertices
  * are discarded.
  * that since the coordinate arrays from before the reset
  * are reused, creating a new empty <code>Polygon</code> might
  * be more memory efficient than resetting the current one if
  * the number of vertices in the new polygon data is significantly
  * smaller than the number of vertices in the data from before the
  * reset.
  */
 public void Reset()
 {
     NumOfNpoints = 0;
     _bounds = null;
 }
Exemple #8
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * {@inheritDoc}
  */
 public bool Intersects(Rectangle r)
 {
     return Intersects(r.X, r.Y, r.Width, r.Height);
 }
Exemple #9
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Tests if the interior of the specified {@link PathIterator}
  * intersects the interior of a specified {@link Rectangle}.
  * <p>
  * This method provides a basic facility for implementors of
  * the {@link IShape} interface to implement support for the
  * {@link IShape#intersects(Rectangle)} method.
  * <p>
  * This method object may conservatively return true in
  * cases where the specified rectangular area intersects a
  * segment of the path, but that segment does not represent a
  * boundary between the interior and exterior of the path.
  * Such a case may occur if some set of segments of the
  * path are retraced in the reverse direction such that the
  * two sets of segments cancel each other out without any
  * interior area between them.
  * To determine whether segments represent true boundaries of
  * the interior of the path would require extensive calculations
  * involving all of the segments of the path and the winding
  * rule and are thus beyond the scope of this implementation.
  *
  * @param pi the specified {@code PathIterator}
  * @param r the specified {@code Rectangle}
  * @return {@code true} if the specified {@code PathIterator} and
  *         the interior of the specified {@code Rectangle}
  *         intersect each other; {@code false} otherwise.
  */
 public static bool Intersects(PathIterator pi, Rectangle r)
 {
     return Intersects(pi, r.X, r.Y, r.Width, r.Height);
 }
Exemple #10
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Tests if the specified {@link Rectangle} is entirely inside the
  * closed boundary of the specified {@link PathIterator}.
  * <p>
  * This method provides a basic facility for implementors of
  * the {@link IShape} interface to implement support for the
  * {@link IShape#contains(Rectangle)} method.
  * <p>
  * This method object may conservatively return false in
  * cases where the specified rectangular area intersects a
  * segment of the path, but that segment does not represent a
  * boundary between the interior and exterior of the path.
  * Such segments could lie entirely within the interior of the
  * path if they are part of a path with a {@link #WIND_NON_ZERO}
  * winding rule or if the segments are retraced in the reverse
  * direction such that the two sets of segments cancel each
  * other out without any exterior area falling between them.
  * To determine whether segments represent true boundaries of
  * the interior of the path would require extensive calculations
  * involving all of the segments of the path and the winding
  * rule and are thus beyond the scope of this implementation.
  *
  * @param pi the specified {@code PathIterator}
  * @param r a specified {@code Rectangle}
  * @return {@code true} if the specified {@code PathIterator} contains
  *         the specified {@code Rectangle}; {@code false} otherwise.
  */
 public static bool Contains(PathIterator pi, Rectangle r)
 {
     return Contains(pi, r.X, r.Y, r.Width, r.Height);
 }
            ////////////////////////////////////////////////////////////////////////
            //--------------------------------- REVISIONS --------------------------
            // Date       Name                 Tracking #         Description
            // ---------  -------------------  -------------      ------------------
            // 18JUN2009  James Shen                 	          Initial Creation
            ////////////////////////////////////////////////////////////////////////
            /**
             *
             * @param mapDirection
             * @param X
             * @param Y
             * @param Width
             * @param Height
             */
            private void DrawRouteImage(MapDirection mapDirection, int x, int y,
                    int width, int height)
            {
                if (!_routeDrawWaypointOnly)
                {
                    _sutherlandHodgman = new SutherlandHodgman(_screenBounds);

                    ArrayList polyline = new ArrayList();
                    int minLevel = NeedShowLevel(mapDirection.Polyline.NumLevels, GetZoom());
                    for (int i = 0; i < mapDirection.Polyline.GetVertexCount(); i++)
                    {
                        int level = mapDirection.Polyline.GetLevel(i);
                        if (level >= minLevel)
                        {
                            polyline.Add(mapDirection.Polyline.GetVertex(i));
                        }
                    }
                    ArrayList clippedPts = _sutherlandHodgman.ClipPline(polyline);

                    GeoPoint newPt1;
                    GeoPoint newPt2;

                    GeoPoint drawPt1 = new GeoPoint(0, 0), drawPt2 = new GeoPoint(0, 0);
                    const int steps = 1;
                    int numOfTiles = MAP_TILE_WIDTH / _mapDrawingTileWidth;
                    Rectangle drawArea = new Rectangle();
                    Rectangle intersectRect = new Rectangle(0, 0, width, height);
                    int xIndex;
                    for (xIndex = 0; xIndex < numOfTiles; xIndex++)
                    {
                        int yIndex;
                        for (yIndex = 0; yIndex < numOfTiles; yIndex++)
                        {
                            bool hasPt1 = false;
                            GeoLatLng pt1 = null;
                            _routeGraphics2D.Clear(Color.White);
                            drawArea.X = xIndex * _mapDrawingTileWidth;
                            drawArea.Y = yIndex * _mapDrawingTileWidth;
                            drawArea.Width = drawArea.Height = _mapDrawingTileWidth;
                            drawArea = intersectRect.Intersection(drawArea);
                            int totalPointSize = clippedPts.Count;
                            if (!drawArea.IsEmpty())
                            {
                                _routeGraphics2D.SetClip(0, 0,
                                        drawArea.Width, drawArea.Height);
                                try
                                {
                                    for (int j = 0; j < totalPointSize; j += steps)
                                    {
                                        GeoLatLng pt = (GeoLatLng)clippedPts[j];
                                        int level = minLevel;
                                        if (hasPt1 == false)
                                        {
                                            if (level >= minLevel)
                                            {
                                                {
                                                    {
                                                        hasPt1 = true;
                                                        pt1 = pt;
                                                        continue;
                                                    }
                                                }
                                            }
                                        }
                                        if (hasPt1)
                                        {
                                            if (level >= minLevel)
                                            {
                                                GeoLatLng pt2 = pt;
                                                newPt1 = FromLatLngToMapPixel(pt1);
                                                newPt2 = FromLatLngToMapPixel(pt2);
                                                newPt1.X -= x + xIndex * _mapDrawingTileWidth;
                                                newPt1.Y -= y + yIndex * _mapDrawingTileWidth;
                                                newPt2.X -= x + xIndex * _mapDrawingTileWidth;
                                                newPt2.Y -= y + yIndex * _mapDrawingTileWidth;
                                                drawPt1.X = (int)newPt1.X;
                                                drawPt1.Y = (int)newPt1.Y;
                                                drawPt2.X = (int)newPt2.X;
                                                drawPt2.Y = (int)newPt2.Y;

                                                if ((drawPt1.Distance(drawPt2) > 0))
                                                {
                                                    _routeGraphics2D.DrawLine(RoutePen, (int)drawPt1.X,
                                                            (int)drawPt1.Y,
                                                            (int)drawPt2.X, (int)drawPt2.Y);
                                                    pt1 = pt2;
                                                    if (_readListener != null)
                                                    {
                                                        _readListener.readProgress(j,
                                                                totalPointSize);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                catch (Exception)
                                {

                                }
                            }

                            _routeGraphics.DrawRGB(_routeGraphics2D.GetRGB(), 0,
                                    _mapDrawingTileWidth,
                                    xIndex * _mapDrawingTileWidth,
                                    yIndex * _mapDrawingTileWidth,
                                    _mapDrawingTileWidth,
                                    _mapDrawingTileWidth, true);
                        }
                    }
                }
                else
                {
                    _routeGraphics.SetColor(TRANSPARENCY);
                    _routeGraphics.FillRect(0, 0, MAP_TILE_WIDTH, MAP_TILE_WIDTH);
                }
            }
Exemple #12
0
 public override void Enlarge(Rectangle r)
 {
     r.Add((int)(_x0 + 0.5), (int)(_y0 + 0.5));
     double t = -_xcoeff1 / (2 * _xcoeff2);
     if (t > 0 && t < 1)
     {
         r.Add((int)(XforT(t) + .5), (int)(YforT(t) + .5));
     }
     r.Add((int)(_x1 + 0.5), (int)(_y1 + 0.5));
 }
Exemple #13
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Returns a new <code>Rectangle</code> object representing the
  * union of this <code>Rectangle</code> with the specified
  * <code>Rectangle</code>.
  * @param r the <code>Rectangle</code> to be combined with
  * this <code>Rectangle</code>
  * @return the smallest <code>Rectangle</code> containing both
  * the specified <code>Rectangle</code> and this
  * <code>Rectangle</code>.
  */
 public Rectangle CreateUnion(Rectangle r)
 {
     return Union(r);
 }
Exemple #14
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Returns a new <code>Rectangle</code> object representing the
  * intersection of this <code>Rectangle2D</code> with the specified
  * <code>Rectangle</code>.
  * @param r the <code>Rectangle</code> to be intersected with
  * this <code>Rectangle</code>
  * @return the largest <code>Rectangle</code> contained in both
  * 		the specified <code>Rectangle</code> and in this
  *		<code>Rectangle</code>.
  */
 public Rectangle CreateIntersection(Rectangle r)
 {
     return Intersection(r);
 }
Exemple #15
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Checks whether or not this <code>Rectangle</code> entirely contains
  * the specified <code>Rectangle</code>.
  *
  * @param     rect   the specified <code>Rectangle</code>
  * @return    <code>true</code> if the <code>Rectangle</code>
  *            is contained entirely inside this <code>Rectangle</code>;
  *            <code>false</code> otherwise
  */
 public override bool Contains(Rectangle rect)
 {
     return Contains(rect.X, rect.Y, rect._size.GetWidth(), rect._size.GetHeight());
 }
Exemple #16
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * {@inheritDoc}
  */
 public bool Intersects(Rectangle r)
 {
     return Intersects(r.GetX(), r.GetY(), r.GetWidth(), r.GetHeight());
 }
Exemple #17
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * {@inheritDoc}
  */
 public bool Contains(Rectangle r)
 {
     return Contains(r.X, r.Y, r.Width, r.Height);
 }
Exemple #18
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 private Rectangle GetCachedBounds()
 {
     if (_cachedBounds != null)
     {
         return _cachedBounds;
     }
     Rectangle r = new Rectangle();
     if (_curves.Count > 0)
     {
         Curve c = (Curve)_curves[0];
         // First point is always an order 0 curve (moveto)
         r.SetRect((int)(c.GetX0() + .5),
                 (int)(c.GetY0() + .5), 0, 0);
         for (int i = 1; i < _curves.Count; i++)
         {
             ((Curve)_curves[i]).Enlarge(r);
         }
     }
     return (_cachedBounds = r);
 }
Exemple #19
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Invalidates or flushes any internally-cached data that depends
  * on the vertex coordinates of this <code>Polygon</code>.
  * This method should be called after any direct manipulation
  * of the coordinates in the <code>xpoints</code> or
  * <code>ypoints</code> arrays to avoid inconsistent results
  * from methods such as <code>getBounds</code> or <code>contains</code>
  * that might cache data from earlier computations relating to
  * the vertex coordinates.
  */
 public void Invalidate()
 {
     _bounds = null;
 }
Exemple #20
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 private void InvalidateBounds()
 {
     _cachedBounds = null;
 }
Exemple #21
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /*
         * Calculates the bounding box of the points passed to the constructor.
         * Sets <code>bounds</code> to the result.
         * @param xpoints[] array of <i>x</i> coordinates
         * @param ypoints[] array of <i>y</i> coordinates
         * @param npoints the total number of points
         */
        private void CalculateBounds(int[] xpoints, int[] ypoints, int npoints)
        {
            int boundsMinX = int.MaxValue;
            int boundsMinY = int.MaxValue;
            int boundsMaxX = int.MinValue;
            int boundsMaxY = int.MinValue;

            for (int i = 0; i < npoints; i++)
            {
                int x = xpoints[i];
                boundsMinX = Math.Min(boundsMinX, x);
                boundsMaxX = Math.Max(boundsMaxX, x);
                int y = ypoints[i];
                boundsMinY = Math.Min(boundsMinY, y);
                boundsMaxY = Math.Max(boundsMaxY, y);
            }
            _bounds = new Rectangle(boundsMinX, boundsMinY,
                    boundsMaxX - boundsMinX,
                    boundsMaxY - boundsMinY);
        }
 public LinearGradientBrush(Rectangle rect, Color color1, Color color2,
         float angle)
     : this(rect, color1, color2, angle, NO_CYCLE)
 {
 }
Exemple #23
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 private bool Contains(int x, int y, int w, int h,
              Rectangle origrect)
 {
     if (!(Contains(x, y) &&
           Contains(x + w, y) &&
           Contains(x, y + h) &&
           Contains(x + w, y + h)))
     {
         return false;
     }
     // If the shape is convex then we have done all the testing
     // we need.  Only PIE arcs can be concave and then only if
     // the angular extents are greater than 180 degrees.
     if (_type != PIE || MathEx.Abs(GetAngleExtent()) <= 180.0)
     {
         return true;
     }
     // For a PIE shape we have an additional test for the case where
     // the angular extents are greater than 180 degrees and all four
     // rectangular corners are inside the shape but one of the
     // rectangle edges spans across the "missing wedge" of the arc.
     // We can test for this case by checking if the rectangle intersects
     // either of the pie angle segments.
     if (origrect == null)
     {
         origrect = new Rectangle((int)(x + .5),
                     (int)(y + .5),
                     (int)(w + .5),
                     (int)(h + .5));
     }
     double halfW = GetWidth() / 2.0;
     double halfH = GetHeight() / 2.0;
     double xc = GetX() + halfW;
     double yc = GetY() + halfH;
     double angle = MathEx.ToRadians(-GetAngleStart());
     double xe = xc + halfW * MathEx.Cos(angle);
     double ye = yc + halfH * MathEx.Sin(angle);
     if (origrect.IntersectsLine((int)(xc + .5),
                 (int)(yc + .5),
                 (int)(xe + .5),
                 (int)(ye + .5)))
     {
         return false;
     }
     angle += MathEx.ToRadians(-GetAngleExtent());
     xe = xc + halfW * MathEx.Cos(angle);
     ye = yc + halfH * MathEx.Sin(angle);
     return !origrect.IntersectsLine((int)(xc + .5),
                 (int)(yc + .5),
                 (int)(xe + .5),
                 (int)(ye + .5));
 }
 public LinearGradientBrush(Rectangle rect, Color color1, Color color2,
         float angle, int fillType)
 {
     _start = new Point(rect.X, rect.Y);
     _end = new Point(rect.X + rect.Width, rect.Y + rect.Height);
     _gradientTransform = new AffineTransform();
     _fractions = new[] { 0, 100 };
     _colors = new[] { color1, color2 };
     bool opaque = true;
     for (int i = 0; i < _colors.Length; i++)
     {
         opaque = opaque && (_colors[i].GetAlpha() == 0xff);
     }
     _transparency = opaque ? Color.OPAQUE : Color.TRANSLUCENT;
     RectangleFP r = Utils.ToRectangleFP(rect);
     _wrappedBrushFP = new LinearGradientBrushFP(r.GetLeft(), r.GetTop(),
             r.GetRight(), r.GetBottom(),
             MathFP.ToRadians(SingleFP.FromFloat(angle)));
     for (int i = 0; i < _colors.Length; i++)
     {
         ((LinearGradientBrushFP)_wrappedBrushFP)
                 .SetGradientColor(SingleFP.FromFloat(_fractions[i]
                 / 255.0f),
                 _colors[i]._value);
     }
     ((LinearGradientBrushFP)_wrappedBrushFP).UpdateGradientTable();
     _wrappedBrushFP.SetMatrix(Utils.ToMatrixFP(_gradientTransform));
     _wrappedBrushFP.FillMode = fillType;
 }
Exemple #25
0
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Determines whether or not the interior of the arc entirely contains
  * the specified rectangle.
  *
  * @param r The <CODE>Rectangle</CODE> to test.
  *
  * @return <CODE>true</CODE> if the arc contains the rectangle,
  * <CODE>false</CODE> if the arc doesn't contain the rectangle.
  */
 public override bool Contains(Rectangle r)
 {
     return Contains(r.GetX(), r.GetY(), r.GetWidth(), r.GetHeight(), r);
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 15JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Constructs a {@code LinearGradientBrush}.
         *
         * @param start the gradient axis start {@code Point} in user space
         * @param end the gradient axis end {@code Point} in user space
         * @param fractions numbers ranging from 0 to 255 specifying the
         *                  distribution of colors along the gradient
         * @param colors array of colors corresponding to each fractional Value
         * @param fillType either {@code NO_CYCLE}, {@code REFLECT},
         *                    or {@code REPEAT}
         * @param gradientTransform transform to apply to the gradient
         *
         * @throws NullPointerException
         * if one of the points is null,
         * or {@code fractions} array is null,
         * or {@code colors} array is null,
         * or {@code cycleMethod} is null,
         * or {@code colorSpace} is null,
         * or {@code gradientTransform} is null
         * @throws IllegalArgumentException
         * if start and end points are the same points,
         * or {@code fractions.length != colors.length},
         * or {@code colors} is less than 2 in size,
         * or a {@code fractions} Value is less than 0.0 or greater than 1.0,
         * or the {@code fractions} are not provided in strictly increasing order
         */
        public LinearGradientBrush(Point start, Point end,
                int[] fractions, Color[] colors,
                AffineTransform gradientTransform, int fillType)
        {
            if (fractions == null)
            {
                throw new NullReferenceException("Fractions array cannot be null");
            }

            if (colors == null)
            {
                throw new NullReferenceException("Colors array cannot be null");
            }

            if (gradientTransform == null)
            {
                throw new NullReferenceException("Gradient transform cannot be " +
                        "null");
            }

            if (fractions.Length != colors.Length)
            {
                throw new ArgumentException("Colors and fractions must " +
                        "have equal size");
            }

            if (colors.Length < 2)
            {
                throw new ArgumentException("User must specify at least " +
                        "2 colors");
            }

            // check that values are in the proper range and progress
            // in increasing order from 0 to 1
            int previousFraction = -255;
            for (int i = 0; i < fractions.Length; i++)
            {
                int currentFraction = fractions[i];
                if (currentFraction < 0 || currentFraction > 255)
                {
                    throw new ArgumentException("Fraction values must " +
                            "be in the range 0 to 255: " +
                            currentFraction);
                }

                if (currentFraction <= previousFraction)
                {
                    throw new ArgumentException("Keyframe fractions " +
                            "must be increasing: " +
                            currentFraction);
                }

                previousFraction = currentFraction;
            }

            // We have to deal with the cases where the first gradient stop is not
            // equal to 0 and/or the last gradient stop is not equal to 1.
            // In both cases, create a new point and replicate the previous
            // extreme point's color.
            bool fixFirst = false;
            bool fixLast = false;
            int len = fractions.Length;
            int off = 0;

            if (fractions[0] != 0)
            {
                // first stop is not equal to zero, fix this condition
                fixFirst = true;
                len++;
                off++;
            }
            if (fractions[fractions.Length - 1] != 255)
            {
                // last stop is not equal to one, fix this condition
                fixLast = true;
                len++;
            }

            this._fractions = new int[len];
            Array.Copy(fractions, 0, this._fractions, off, fractions.Length);
            this._colors = new Color[len];
            Array.Copy(colors, 0, this._colors, off, colors.Length);

            if (fixFirst)
            {
                this._fractions[0] = 0;
                this._colors[0] = colors[0];
            }
            if (fixLast)
            {
                this._fractions[len - 1] = 255;
                this._colors[len - 1] = colors[colors.Length - 1];
            }

            // copy the gradient transform
            this._gradientTransform = new AffineTransform(gradientTransform);

            // determine transparency
            bool opaque = true;
            for (int i = 0; i < colors.Length; i++)
            {
                opaque = opaque && (colors[i].GetAlpha() == 0xff);
            }
            _transparency = opaque ? Color.OPAQUE : Color.TRANSLUCENT;

            // check input parameters
            if (start == null || end == null)
            {
                throw new NullReferenceException("Start and end points must be" +
                        "non-null");
            }

            if (start.Equals(end))
            {
                throw new ArgumentException("Start point cannot equal" +
                        "endpoint");
            }

            // copy the points...
            this._start = new Point(start.GetX(), start.GetY());
            this._end = new Point(end.GetX(), end.GetY());

            Rectangle rectangle = new Rectangle(start, end);
            float dx = start.X - end.X;
            float dy = start.Y - end.Y;
            double angle = MathEx.Atan2(dy, dx);
            int intAngle = SingleFP.FromDouble(angle);
            RectangleFP r = Utils.ToRectangleFP(rectangle);
            _wrappedBrushFP = new LinearGradientBrushFP(r.GetLeft(), r.GetTop(),
                    r.GetRight(), r.GetBottom(),
                    intAngle);
            for (int i = 0; i < colors.Length; i++)
            {
                ((LinearGradientBrushFP)_wrappedBrushFP).SetGradientColor
                        (SingleFP.FromFloat(fractions[i] / 100.0f),
                        colors[i]._value);
            }
            ((LinearGradientBrushFP)_wrappedBrushFP).UpdateGradientTable();
            _wrappedBrushFP.SetMatrix(Utils.ToMatrixFP(gradientTransform));
            _wrappedBrushFP.FillMode = fillType;
        }
Exemple #27
0
 public override void Enlarge(Rectangle r)
 {
     r.Add((int)(_x0 + .5),
             (int)(_y0 + .5));
     double[] eqn = { _xcoeff1, 2 * _xcoeff2, 3 * _xcoeff3 };
     int numroots = QuadCurve.SolveQuadratic(eqn, eqn);
     for (int i = 0; i < numroots; i++)
     {
         double t = eqn[i];
         if (t > 0 && t < 1)
         {
             r.Add((int)(XforT(t) + .5), (int)(YforT(t) + .5));
         }
     }
     r.Add((int)(_x1 + .5), (int)(_y1 + .5));
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 02NOV2008  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Sets the framing rectangle of this <code>IShape</code> to
  * be the specified <code>Rectangle</code>.  The framing rectangle is
  * used by the subclasses of <code>RectangularShape</code> to define
  * their geometry.
  * @param r the specified <code>Rectangle</code>
  */
 public void SetFrame(Rectangle r)
 {
     SetFrame(r.GetX(), r.GetY(), r.GetWidth(), r.GetHeight());
 }
Exemple #29
0
 internal static RectangleFP ToRectangleFP(Rectangle rect)
 {
     return new RectangleFP(
             SingleFP.FromInt(rect.GetMinX()),
             SingleFP.FromInt(rect.GetMinY()),
             SingleFP.FromInt(rect.GetMaxX()),
             SingleFP.FromInt(rect.GetMaxY()));
 }
Exemple #30
0
 public override void Enlarge(Rectangle r)
 {
     r.Add((int)(_x0 + 0.5), (int)(_y0 + 0.5));
     r.Add((int)(_x1 + 0.5), (int)(_y1 + 0.5));
 }