示例#1
0
        public void CircumscribeRect()
        {
            Assert.AreEqual(rectI, rectD.Circumscribe());
            Assert.AreEqual(rectI, new RectD(1.6, 2.4, 3.2, 4.1).Circumscribe());
            Assert.AreEqual(new RectI(-3, -4, 20, 30), new RectD(-2.1, -3.2, 19.8, 29.1).Circumscribe());

            Assert.AreEqual(rectI, rectF.Circumscribe());
            Assert.AreEqual(rectI, new RectF(1.6f, 2.4f, 3.2f, 4.1f).Circumscribe());
            Assert.AreEqual(new RectI(-3, -4, 20, 30), new RectF(-2.1f, -3.2f, 19.8f, 29.1f).Circumscribe());
        }
示例#2
0
        public void Circumscribe()
        {
            Assert.AreEqual(rectD, RectD.Circumscribe(
                                rectD.TopLeft, rectD.TopRight, rectD.BottomLeft, rectD.BottomRight));

            Assert.AreEqual(rectF, RectF.Circumscribe(
                                rectF.TopLeft, rectF.TopRight, rectF.BottomLeft, rectF.BottomRight));

            // RectI.Circumscribe extends one past the specified points
            Assert.AreEqual(new RectI(1, 2, 5, 6), RectI.Circumscribe(
                                rectI.TopLeft, rectI.TopRight, rectI.BottomLeft, rectI.BottomRight));
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RegularPolygon"/> class with the specified
        /// side length, number of sides, orientation, and vertex neighbors flag.</summary>
        /// <param name="length">
        /// The length of each side of the <see cref="RegularPolygon"/>.</param>
        /// <param name="sides">
        /// The number of sides of the <see cref="RegularPolygon"/>.</param>
        /// <param name="orientation">
        /// The orientation of the <see cref="RegularPolygon"/>.</param>
        /// <param name="vertexNeighbors">
        ///  <c>true</c> if <see cref="RegularPolygon"/> shapes that share only a common vertex are
        /// considered neighbors; otherwise, <c>false</c>.</param>
        /// <exception cref="ArgumentOutOfRangeException"><para>
        /// <paramref name="length"/> is equal to or less than zero.
        /// </para><para>-or-</para><para>
        /// <paramref name="sides"/> is less than three.
        /// </para><para>-or-</para><para>
        /// <paramref name="vertexNeighbors"/> is <c>true</c>, and <paramref name="sides"/> is
        /// greater than four.</para></exception>
        /// <exception cref="InvalidEnumArgumentException">
        /// <paramref name="orientation"/> is not a valid <see cref="PolygonOrientation"/> value.
        /// </exception>

        public RegularPolygon(double length, int sides,
                              PolygonOrientation orientation, bool vertexNeighbors)
        {
            if (length <= 0.0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(
                    "length", length, Strings.ArgumentNotPositive);
            }

            if (sides < 3)
            {
                ThrowHelper.ThrowArgumentOutOfRangeExceptionWithFormat(
                    "sides", sides, Strings.ArgumentLessValue, 3);
            }

            if (vertexNeighbors && sides > 4)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException(
                    "vertexNeighbors", vertexNeighbors, Strings.ArgumentTrue);
            }

            Length          = length;
            Sides           = sides;
            Orientation     = orientation;
            VertexNeighbors = vertexNeighbors;

            // compute maximum neighbors on edges and vertices
            Connectivity = (vertexNeighbors ? 2 * sides : sides);

            // determine whether a top connection exists
            HasTopIndex = (vertexNeighbors || (sides % 2 == 0 ?
                                               orientation == PolygonOrientation.OnEdge :
                                               orientation == PolygonOrientation.OnVertex));

            // compute angle of one segment between vertices
            double angle, segment = (2.0 * Math.PI) / sides;

            // compute radii of circumscribed and inscribed circles
            OuterRadius = length / (2.0 * Math.Sin(segment / 2.0));
            InnerRadius = OuterRadius * Math.Cos(segment / 2.0);

            // compute angle of first vertex and check orientation
            switch (orientation)
            {
            case PolygonOrientation.OnEdge:
                angle = (sides % 2 == 0 ? segment : 0.0);
                break;

            case PolygonOrientation.OnVertex:
                angle = (sides % 2 == 0 ? 0.0 : segment);
                break;

            default:
                ThrowHelper.ThrowInvalidEnumArgumentException(
                    "orientation", (int)orientation, typeof(PolygonOrientation));
                angle = 0.0;
                break;
            }

            // halve angle and rotate 90° counter-clockwise
            angle = (angle - Math.PI) / 2.0;

            // compute and store vertex coordinates around center
            Vertices = new PointD[sides];
            for (int i = 0; i < sides; i++, angle += segment)
            {
                Vertices[i] = new PointD(
                    OuterRadius * Math.Cos(angle), OuterRadius * Math.Sin(angle));
            }

            // compute and store circumscribed rectangle
            Bounds = RectD.Circumscribe(Vertices);
        }
示例#4
0
        /// <summary>
        /// Renders the visual content of the <see cref="MapViewRenderer"/>.</summary>
        /// <param name="context">
        /// The <see cref="DrawingContext"/> for the rendering.</param>
        /// <remarks><para>
        /// <b>OnRender</b> calls the base class implementation of <see cref="UIElement.OnRender"/>,
        /// and then immediately returns if the associated <see cref="MapView"/> has not been fully
        /// initialized yet, or already been disposed of.
        /// </para><para>
        /// Otherwise, <b>OnRender</b> redraws the current <see cref="MapViewControl.Viewport"/>.
        /// The <see cref="Graphics.MapView.Extent"/> of the associated <see cref="MapView"/>
        /// outside the current <see cref="MapViewControl.Viewport"/> remains empty.
        /// </para></remarks>

        protected override void OnRender(DrawingContext context)
        {
            base.OnRender(context);
            if (MapView.Catalog == null || MapView.IsDisposed)
            {
                return;
            }

            // check if there is anything to render
            Rect viewRegion = Control.Viewport;

            if (viewRegion.Width == 0 || viewRegion.Height == 0)
            {
                return;
            }

            // distance from center point to upper-left corner
            double centerX = MapView.TileWidth / 2.0;
            double centerY = MapView.TileHeight / 2.0;

            // compute sites covered by viewport
            RectD region     = viewRegion.ToRectD();
            RectI intRegion  = region.Circumscribe();
            RectI siteRegion = MapView.ViewToSite(region);

            // resize & clear paint buffer
            bool mustClear = EnsureBufferSize(intRegion.Size);

            PaintBuffer.Lock();
            if (mustClear)
            {
                PaintBuffer.Clear();
            }

            // cache performance options
            this._bitmapGrid   = ApplicationOptions.Instance.View.BitmapGrid;
            this._opaqueImages = ApplicationOptions.Instance.View.OpaqueImages;

            // draw entities of all sites within region
            for (int x = siteRegion.Left; x < siteRegion.Right; x++)
            {
                for (int y = siteRegion.Top; y < siteRegion.Bottom; y++)
                {
                    Site site = MapView.WorldState.Sites[x, y];

                    // compute upper-left corner of bitmap tile
                    PointD display = MapView.SiteToView(site.Location);
                    PointI pixel   = new PointI(
                        Fortran.NInt(display.X - centerX),
                        Fortran.NInt(display.Y - centerY));

                    // draw entities in current site
                    DrawEntities(pixel, intRegion, site);
                }
            }

            // copy paint buffer to viewport
            PaintBuffer.Unlock();
            context.DrawImage(PaintBuffer,
                              new Rect(region.Left, region.Top, PaintBuffer.Width, PaintBuffer.Height));

            // draw optional decoration on all sites
            DrawDecoration(context, siteRegion);
        }