Example #1
0
        public static GraphManager <PointI> CreatePolygonGridManager(
            GraphDialog dialog, RegularPolygon polygon)
        {
            int         width = 20, height = 20;
            PolygonGrid grid = new PolygonGrid(polygon);

            grid.Size = new SizeI(width, height);

            // shrink grid until it fits in output box
            double outputWidth  = dialog.OutputBox.Width - 16;
            double outputHeight = dialog.OutputBox.Height - 16;

            while (grid.DisplayBounds.Width > outputWidth)
            {
                grid.Size = new SizeI(--width, height);
            }
            while (grid.DisplayBounds.Height > outputHeight)
            {
                grid.Size = new SizeI(width, --height);
            }

            var manager = new GraphManager <PointI>(dialog, 4);

            manager.Graph    = grid;
            manager.Renderer = new GraphRenderer <PointI>(manager);
            return(manager);
        }
        public static void Initialization_with_Dimensions_with_Insufficient_Sides_Creates_5_Sided_Shape(int numberOfSides, double circumRadius)
        {
            RegularPolygon regularPolygon = new RegularPolygon(numberOfSides, circumRadius);

            Assert.AreEqual(5, regularPolygon.Points.Count);
            Assert.AreEqual(5, regularPolygon.Angles.Count);
            Assert.AreEqual(5, regularPolygon.Sides.Count);
            Assert.AreEqual(GeometryLibrary.ZeroTolerance, regularPolygon.Tolerance);
            Assert.AreEqual(0, regularPolygon.Centroid.X, Tolerance);
            Assert.AreEqual(0, regularPolygon.Centroid.Y, Tolerance);

            Assert.AreEqual(5, regularPolygon.NumberOfSides);
            Assert.AreEqual(11.75570505, regularPolygon.SideLength, Tolerance);

            Assert.AreEqual(circumRadius, regularPolygon.CircumRadius, Tolerance);
            Assert.AreEqual(0, regularPolygon.CircumCenter.X, Tolerance);
            Assert.AreEqual(0, regularPolygon.CircumCenter.Y, Tolerance);

            Assert.AreEqual(8.090169944, regularPolygon.Apothem, Tolerance);
            Assert.AreEqual(8.090169944, regularPolygon.InRadius, Tolerance);
            Assert.AreEqual(0, regularPolygon.InCenter.X, Tolerance);
            Assert.AreEqual(0, regularPolygon.InCenter.Y, Tolerance);

            Assert.AreEqual(108, regularPolygon.AngleInterior.Degrees, Tolerance);
            Assert.AreEqual(540, regularPolygon.AngleInteriorSum.DegreesRaw, Tolerance);
        }
Example #3
0
        /// <summary>
        /// Enables or disables all hosted controls based on the current <see
        /// cref="AreaSection.MapGrid"/>.</summary>
        /// <remarks>
        /// <b>EnableControls</b> disables any arrow buttons whose directions are not supported by
        /// the <see cref="PolygonGrid.Element"/> shape of the current <see
        /// cref="AreaSection.MapGrid"/>.</remarks>

        private void EnableControls()
        {
            RegularPolygon element = MasterSection.Instance.Areas.MapGrid.Element;

            // vertex neighbors enable all directions
            if (element.VertexNeighbors)
            {
                return;
            }

            bool isSquare = (element.Sides == 4);
            bool onEdge   = (element.Orientation == PolygonOrientation.OnEdge);

            // connections are symmetrical in all directions
            bool vertical = onEdge, diagonal = !isSquare || !onEdge;
            bool horizontal = (isSquare && onEdge) || (!isSquare && !onEdge);

            NorthToggle.IsEnabled     = vertical;
            NorthEastToggle.IsEnabled = diagonal;
            EastToggle.IsEnabled      = horizontal;
            SouthEastToggle.IsEnabled = diagonal;
            SouthToggle.IsEnabled     = vertical;
            SouthWestToggle.IsEnabled = diagonal;
            WestToggle.IsEnabled      = horizontal;
            NorthWestToggle.IsEnabled = diagonal;
        }
        public void RegularPolygon_Constructor()
        {
            Polygon polygon = new RegularPolygon(4, 4 * Feet);

            polygon.IsRectangle().Should().BeTrue();
            polygon.Area.Should().Be(16 * SquareFeet);
        }
Example #5
0
        /// <summary>
        /// Draws an image frame that is centered within, masked and outlined by the specified <see
        /// cref="RegularPolygon"/>.</summary>
        /// <param name="context">
        /// The <see cref="DrawingContext"/> for the drawing.</param>
        /// <param name="brush">
        /// The <see cref="Brush"/> used to draw the <paramref name="polygon"/> outline.</param>
        /// <param name="target">
        /// The region within <paramref name="context"/> on which the copied image frame is
        /// centered.</param>
        /// <param name="sourceBitmap">
        /// A <see cref="WriteableBitmap"/> containing the image frame to copy.</param>
        /// <param name="source">
        /// The region within <paramref name="sourceBitmap"/> that covers the image frame to copy.
        /// </param>
        /// <param name="polygon">
        /// The <see cref="RegularPolygon"/> whose <see cref="RegularPolygon.Vertices"/> provide the
        /// clipping region and outline for the copied frame.</param>
        /// <param name="scalingX">
        /// An <see cref="ImageScaling"/> value indicating the horizontal scaling of the <paramref
        /// name="source"/> region to fit the specified <paramref name="polygon"/>.</param>
        /// <param name="scalingY">
        /// An <see cref="ImageScaling"/> value indicating the vertical scaling of the <paramref
        /// name="source"/> region to fit the specified <paramref name="polygon"/>.</param>
        /// <param name="colorShift">
        /// An optional <see cref="ColorVector"/> applied to all pixels within the drawing. Specify
        /// <see cref="ColorVector.Empty"/> if colors should remain unchanged.</param>
        /// <param name="offset">
        /// An optional pixel offset that is added to the centered location within the <paramref
        /// name="target"/> region.</param>
        /// <param name="scalingVector">
        /// An optional scaling vector that is applied to the transformation matrix of the specified
        /// <paramref name="context"/> object. Specify <see cref="PointI.Empty"/> if no scaling
        /// vector should be applied.</param>
        /// <returns>
        /// <c>true</c> if <see cref="CheckFrame"/> succeeded with the specified arguments;
        /// otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> or <paramref name="polygon"/> is a null reference.
        /// </exception>
        /// <remarks>
        /// <b>DrawOutlineFrame</b> always masks off the specified <paramref name="context"/> with
        /// the specified <paramref name="polygon"/>, and superimposes its outline on the drawn
        /// frame using the specified <paramref name="brush"/>.</remarks>

        public static bool DrawOutlineFrame(DrawingContext context,
                                            Brush brush, Rect target, WriteableBitmap sourceBitmap, RectI source,
                                            RegularPolygon polygon, ImageScaling scalingX, ImageScaling scalingY,
                                            ColorVector colorShift, PointI offset, PointI scalingVector)
        {
            // check drawing parameters
            if (!CheckFrame(sourceBitmap, source, polygon))
            {
                return(false);
            }

            // compute frame bounds centered on target region
            RectD frameTarget = new RectD(
                target.X + (target.Width - polygon.Bounds.Width) / 2.0,
                target.Y + (target.Height - polygon.Bounds.Height) / 2.0,
                polygon.Bounds.Width, polygon.Bounds.Height);

            // mask off region outside polygon outline
            MaskOutline(context, target, polygon);

            // draw frame with specified display parameters
            DrawFrame(null, context, frameTarget, sourceBitmap, source,
                      scalingX, scalingY, colorShift, offset, scalingVector);

            // draw polygon outline around frame
            context.Pop();
            DrawOutline(context, brush, target, polygon);

            return(true);
        }
Example #6
0
        /// <summary>
        /// Given the application parameters, creates regular polygon and depending on the option: saves it to default file or displays it on console
        /// /// </summary>
        /// <param name="parameters">Already parsed application parameters</param>
        private static void ProcessInput(AppParameters parameters)
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();

            try
            {
                RegularPolygon polygon =
                    factory.CreateRegularPolygon(parameters.NumberOfVertices, parameters.SideLength, DefaultInitialVertex);
                switch (parameters.Option)
                {
                case AppParameters.ProcessType.DisplayOnConsole:
                    DU.DisplayText(polygon.ToString());
                    DU.DisplayText("Successfully completed operation", DU.InformationType.OnSuccess);
                    break;

                case AppParameters.ProcessType.SaveToFile:
                    SavePolygonToFile(DefaultFilePath, polygon);
                    break;
                }
            }
            catch (RegularPolygonFactoryLogicalException e)
            {
                DU.DisplayText(e.Message, DU.InformationType.OnError);
            }
        }
Example #7
0
        private void SetStarStyle(int starIndex, StarStyleEnum style)
        {
            RegularPolygon star            = (RegularPolygon)this.FindName("Star" + starIndex.ToString());
            Color          fillColor       = ColorProvider.CustomBlack();
            Color          strokeColor     = ColorProvider.StrokeActive();
            double         strokeThickness = 1.5;

            switch (style)
            {
            case StarStyleEnum.Active:
                fillColor   = ColorProvider.CustomBlack();;
                strokeColor = ColorProvider.StrokeActive();
                break;

            case StarStyleEnum.Solved:
                fillColor   = ColorProvider.CustomGreen();
                strokeColor = ColorProvider.StrokeActive();
                break;

            case StarStyleEnum.Inactive:
                fillColor       = ColorProvider.CustomBlack();;
                strokeColor     = ColorProvider.StrokeInactive();
                strokeThickness = 2;
                break;
            }
            star.Fill            = new SolidColorBrush(fillColor);
            star.Stroke          = new SolidColorBrush(strokeColor);
            star.StrokeThickness = strokeThickness;
        }
Example #8
0
        public void Draw()
        {
            // Arrange
            var canvasMock = new CanvasMock.Canvas();

            var center      = new Point(0, 0);
            var vertexCount = 3;
            var radius      = 2;


            var regularPolygon = new RegularPolygon(vertexCount, radius, center, ColorType.Blue);

            var expectedDrawedLines = new HashSet <Line>
            {
                new Line {
                    From = new Point(2, 0), To = new Point(-1, 1.732)
                },
                new Line {
                    From = new Point(-1, 1.732), To = new Point(-1, -1.732)
                },
                new Line {
                    From = new Point(-1, -1.732), To = new Point(2, 0)
                }
            };
            var expectedColor = ColorType.Blue;

            // Act
            regularPolygon.Draw(canvasMock);

            // Assert
            Assert.Equal(expectedColor, canvasMock.Color);
            Assert.Equal(expectedDrawedLines, canvasMock.LastDrawedLines);
        }
        public static void Factory_with_CircumRadius_Creates_Shape(int numberOfSides, double circumRadius)
        {
            RegularPolygon regularPolygon = RegularPolygon.RegularPolygonByCircumradius(numberOfSides, circumRadius);

            Assert.AreEqual(numberOfSides, regularPolygon.Points.Count);
            Assert.AreEqual(numberOfSides, regularPolygon.Angles.Count);
            Assert.AreEqual(numberOfSides, regularPolygon.Sides.Count);
            Assert.AreEqual(GeometryLibrary.ZeroTolerance, regularPolygon.Tolerance);
            Assert.AreEqual(0, regularPolygon.Centroid.X, Tolerance);
            Assert.AreEqual(0, regularPolygon.Centroid.Y, Tolerance);

            Assert.AreEqual(numberOfSides, regularPolygon.NumberOfSides);
            Assert.AreEqual(11.75570505, regularPolygon.SideLength, Tolerance);

            Assert.AreEqual(circumRadius, regularPolygon.CircumRadius, Tolerance);
            Assert.AreEqual(0, regularPolygon.CircumCenter.X, Tolerance);
            Assert.AreEqual(0, regularPolygon.CircumCenter.Y, Tolerance);

            Assert.AreEqual(8.090169944, regularPolygon.Apothem, Tolerance);
            Assert.AreEqual(8.090169944, regularPolygon.InRadius, Tolerance);
            Assert.AreEqual(0, regularPolygon.InCenter.X, Tolerance);
            Assert.AreEqual(0, regularPolygon.InCenter.Y, Tolerance);

            Assert.AreEqual(108, regularPolygon.AngleInterior.Degrees, Tolerance);
            Assert.AreEqual(540, regularPolygon.AngleInteriorSum.DegreesRaw, Tolerance);
        }
        public void SideLengthLessThen0()
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();


            RegularPolygon a = factory.GetRegularPolygon(3, -10);
        }
        public void CreateRegularPolygon_ValidInput_ShouldReturnCorrectValue()
        {
            RegularPolygon polygon = RegularPolygonFactory.createRegularPolygon(3, 2);

            Assert.AreEqual(3, polygon.VertexNumber);
            Assert.AreEqual(Math.Sqrt(3), polygon.Area, 0.01);
            Assert.AreEqual(3, polygon.VerticesCoordinates().Length);
        }
Example #12
0
 public void Constructor_WhenCalledWithLessThanThreeVertices_ShouldThrowException_()
 {
     Vertex[] vertices = new Vertex[]
     {
         new Vertex(0, 0),
         new Vertex(2, 0),
     };
     RegularPolygon polygon = new RegularPolygon(vertices);
 }
Example #13
0
        public static RegularPolygon CreateRegularPolygon(Drawing drawing, IList <IFigure> dependencies)
        {
            var result = new RegularPolygon()
            {
                Drawing = drawing, Dependencies = dependencies
            };

            return(result);
        }
Example #14
0
 public void CreatePolygon_NotEnoughVertices_ShouldThrow()
 {
     Vertex[] vertices = new Vertex[]
     {
         new Vertex(0, 0),
         new Vertex(1, 0),
     };
     RegularPolygon polygon = new RegularPolygon(vertices);
 }
 public void Polygon()
 {
     for (int i = 3; i < 9; i++)
     {
         var     polygon = new RegularPolygon(30.0 / i, i, PolygonOrientation.OnEdge);
         LineD[] lines   = GeoAlgorithms.ConnectPoints(true, polygon.Vertices);
         CheckSearch(lines);
     }
 }
        public void CreateEquilateralTriangleFromZeroZeroPoint()
        {
            int            numberOfVertices = 3;
            RegularPolygon polygon          = _factory.CreateRegularPolygon(numberOfVertices, _standardLength, _initiaVertex);

            Vertex[] vertices = polygon.Vertices;
            Assert.IsTrue(new Vertex(0, 0).Equals(vertices[0]));
            Assert.IsTrue(new Vertex(2, 0).Equals(vertices[1]));
            Assert.IsTrue(new Vertex(1, 1.73).Equals(vertices[2]));
        }
Example #17
0
		//public static readonly DependencyProperty DirectionProperty =
		//	DependencyProperty.Register("Direction", typeof(Direction), typeof(Direction));

		//public Direction Direction
		//{
		//	get { return (Direction)GetValue(DirectionProperty); }
		//	set { SetValue(DirectionProperty, Direction); }
		//}

		//public static readonly DependencyProperty AngleProperty =
		//	DependencyProperty.Register("Angle", typeof(double), typeof(double));

		//public double Angle
		//{
		//	get { return (double)GetValue(AngleProperty); }
		//	set { SetValue(AngleProperty, value); }
		//}

		public DroidShape()
		{
			var shape = new RegularPolygon();
			shape.InnerRadius = 1;
			shape.PointCount = 3;
			shape.Stretch = Stretch.Fill;
			shape.Stroke = new SolidColorBrush(Colors.Black);
			shape.Margin = new Thickness(3);
			shape.RenderTransformOrigin = new Point(0.5, 0.5);
			Content = shape;
		}
Example #18
0
        private static string AddFigure(eFigure figure, double width, double height, Primitive[] properties)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            Dictionary<string, UIElement> _objectsMap;
            string shapeName;

            try
            {
                ExtractDll();

                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Figure" }).ToString();

                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        switch (figure)
                        {
                            case eFigure.ARC:
                                {
                                    Arc shape = new Arc();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.StartAngle = properties[0];
                                    shape.EndAngle = properties[1];
                                    shape.ArcThickness = properties[2];
                                    shape.ArcThicknessUnit = Microsoft.Expression.Media.UnitType.Pixel;
                                }
                                break;
                            case eFigure.BLOCKARROW:
                                {
                                    BlockArrow shape = new BlockArrow();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.ArrowBodySize = properties[0];
                                    shape.ArrowheadAngle = properties[1];
                                    switch (((string)properties[2]).ToLower())
                                    {
                                        case "up":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Up;
                                            break;
                                        case "down":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Down;
                                            break;
                                        case "left":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Left;
                                            break;
                                        case "right":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Right;
                                            break;
                                    }
                                }
                                break;
                            case eFigure.REGULARPOLYGON:
                                {
                                    RegularPolygon shape = new RegularPolygon();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.PointCount = properties[0];
                                    shape.InnerRadius = properties[1];
                                }
                                break;
                            case eFigure.CALLOUT:
                                {
                                    Callout shape = new Callout();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;
                                    shape.FontFamily = new FontFamily(GraphicsWindow.FontName);
                                    shape.FontSize = GraphicsWindow.FontSize;
                                    shape.FontStyle = GraphicsWindow.FontItalic ? FontStyles.Italic : FontStyles.Normal;
                                    shape.FontWeight = GraphicsWindow.FontBold ? FontWeights.Bold : FontWeights.Normal;
                                    shape.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));

                                    shape.Content = properties[0];
                                    switch (((string)properties[1]).ToLower())
                                    {
                                        case "cloud":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Cloud;
                                            break;
                                        case "oval":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Oval;
                                            break;
                                        case "rectangle":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Rectangle;
                                            break;
                                        case "roundedrectangle":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.RoundedRectangle;
                                            break;
                                    }
                                    Primitive anchor = properties[2];
                                    Point point = new Point(0,1.25);
                                    if (SBArray.GetItemCount(anchor) == 2)
                                    {
                                        Primitive indices = SBArray.GetAllIndices(anchor);
                                        point.X = anchor[indices[1]];
                                        point.Y = anchor[indices[2]];
                                    }
                                    shape.AnchorPoint = point;
                                }
                                break;
                            case eFigure.LINEARROW:
                                {
                                    LineArrow shape = new LineArrow();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.ArrowSize = properties[0];
                                    shape.BendAmount = properties[1];
                                    switch (((string)properties[2]).ToLower())
                                    {
                                        case "none":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.NoArrow;
                                            break;
                                        case "arrow":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.Arrow;
                                            break;
                                        case "open":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.OpenArrow;
                                            break;
                                        case "oval":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.OvalArrow;
                                            break;
                                        case "stealth":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.StealthArrow;
                                            break;
                                    }
                                    switch (((string)properties[3]).ToLower())
                                    {
                                        case "none":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.NoArrow;
                                            break;
                                        case "arrow":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.Arrow;
                                            break;
                                        case "open":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.OpenArrow;
                                            break;
                                        case "oval":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.OvalArrow;
                                            break;
                                        case "stealth":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.StealthArrow;
                                            break;
                                    }
                                    switch (((string)properties[4]).ToLower())
                                    {
                                        case "bottomleft":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomLeft;
                                            break;
                                        case "bottomright":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomRight;
                                            break;
                                        case "topleft":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.TopLeft;
                                            break;
                                        case "topright":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.TopRight;
                                            break;
                                    }
                                }
                                break;
                        }
                        return shapeName;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
 public void RegularPolygon_Constructor()
 {
     Polygon polygon = new RegularPolygon(4, new Distance(4, Feet));
     polygon.IsRectangle().Should().BeTrue();
     polygon.Area.Should().Be(new Area(new SquareFoot(), 16));
 }
Example #20
0
        public void Draw()
        {
            if (SelectedItem == null) return;
            if (gArcs == null) return;
            gArcs.Children.Clear();
            var a = 360.0/Segments;

            if (SelectedItem.Element != null)
            {
                ccCenter.Content = SelectedItem.Element;
                pBack.Visibility = Visibility.Collapsed;
                //ccCenter.Visibility = Visibility.Visible;
            }
            else if (SelectedItem.Icon != null && SelectedItem == RootItem)
            {
                iCenterIcon.Source = new BitmapImage(new Uri(SelectedItem.Icon, UriKind.RelativeOrAbsolute));
                iCenterIcon.Visibility = Visibility.Visible;
                pBack.Visibility = Visibility.Collapsed;
            }
            else
            {
                iCenterIcon.Visibility = Visibility.Collapsed;
                pBack.Visibility = Visibility.Visible;
                //ccCenter.Visibility = Visibility.Collapsed;
            }

            if (!Open)
            {
                BackgroundBrush = null;
                return;
            }
            BackgroundBrush = Brushes.White;

            for (var i = 0; i < Segments; i++)
            {
                var mi = SelectedItem.Items.FirstOrDefault(k => k.Position == i);

                var s = new Arc
                {
                    Width = Size,
                    Height = Size,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Stretch = Stretch.None,
                    StartAngle = i*a,
                    StrokeThickness = 0,
                    Stroke = null,
                    EndAngle = (i + 1)*a - 1
                };
                if (mi != null && mi.Items != null && mi.Items.Count > 0)
                {
                    s.Fill = AccentBrush;
                    s.MouseDown += (e, si) => SelectItem(mi);
                    s.TouchDown += (e, si) => SelectItem(mi);
                }
                else
                {
                    s.Fill = SecondAccentBrush;
                }
                s.ArcThickness = 0;
                s.ArcThicknessUnit = UnitType.Pixel;

                gArcs.Children.Add(s);
                s.BeginAnimation(Arc.ArcThicknessProperty,
                    new DoubleAnimation(ArrowArcSize, new Duration(new TimeSpan(0, 0, 0, 0, 200))));
                const double dDegToRad = Math.PI/180.0;

                if (mi == null) continue;
                var f = new Arc
                {
                    Width = Size - (ArrowArcSize*2) - 3,
                    Height = Size - (ArrowArcSize*2) - 3,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    Stretch = Stretch.None,
                    StartAngle = i*a,
                    StrokeThickness = 0,
                    Stroke = null,
                    EndAngle = (i + 1)*a - 1,
                    Tag =  i
                };
                if (mi.Fill == null) mi.Fill = Brushes.Transparent;
                f.Fill = mi.Fill;
                f.ArcThickness = ItemSize;
                f.ArcThicknessUnit = UnitType.Pixel;
                f.MouseDown += (sender, e) => SelectItem(mi);

                //var eventAsObservable = Observable.FromEventPattern<TouchEventArgs>(f, "TouchDown");
                //eventAsObservable.Throttle(TimeSpan.FromMilliseconds(200)).Subscribe(k => Execute.OnUIThread(() => SelectItem(mi)));

                // Only subscribe to TouchDown on Windows 7: On Windows 8, it causes 
                var win8Version = new Version(6, 2, 9200, 0);
                if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
                    Environment.OSVersion.Version < win8Version)
                {
                    f.TouchDown += (e, si) => SelectItem(mi);
                }
                //f.TouchDown += (sender, e) => SelectItem(mi);

                gArcs.Children.Add(f);
                f.UpdateLayout();


                var sp = new StackPanel {Opacity = 0, IsHitTestVisible = false};
                if (mi.Element != null)
                {
                    var vb = new Viewbox {Width = 20, Height = 20, Stretch = Stretch.Uniform};
                    var pa = new Path {Data = Geometry.Parse(mi.Element), Fill = Brushes.Black};
                    vb.Child = pa;

                    sp.Children.Add(vb);
                }
                else if (!string.IsNullOrEmpty(mi.Icon))
                {
                    var img = new Image {Width = 20, Height = 20, Stretch = Stretch.UniformToFill};
                    var binding = new Binding {Source = mi, Path = new PropertyPath("Icon"), Mode = BindingMode.OneWay};
                    //img.Source = new BitmapImage(new Uri(mi.Icon, UriKind.RelativeOrAbsolute));
                    img.SetBinding(Image.SourceProperty, binding);
                    sp.Children.Add(img);
                }
                else
                {
                    var b = new Border {Background = null, Width = 20, Height = 20};
                    sp.Children.Add(b);
                }
                var tb = new TextBlock {Text = mi.Title};
                var bind = new Binding {Source = mi, Path = new PropertyPath("Title"), Mode = BindingMode.OneWay};
                tb.SetBinding(TextBlock.TextProperty, bind);
                var r = MenuCenterSize/2 + ItemSize - 10;
                var dX = r*Math.Sin((i + 0.5)*a*dDegToRad);

                // We invert the Y coordinate, because the origin in controls 
                // is the upper left corner, rather than the lower left
                var dY = -r*Math.Cos((i + 0.5)*a*dDegToRad);
                tb.Foreground = Brushes.Black;
                tb.FontSize = 9;
                f.TranslatePoint(new Point(ItemSize/2, ItemSize/2), gArcs);
                tb.TextAlignment = TextAlignment.Center;
                tb.HorizontalAlignment = HorizontalAlignment.Center;
                sp.RenderTransform = new TranslateTransform(dX, dY + Size/2 - 15);
                sp.Tag = i;
                sp.Children.Add(tb);
                gArcs.Children.Add(sp);

                sp.BeginAnimation(OpacityProperty,
                    new DoubleAnimation(1.0, new Duration(new TimeSpan(0, 0, 0, 0, 200))));


                if (mi.Items == null || mi.Items.Count <= 0) continue;
                var rp = new RegularPolygon
                {
                    IsHitTestVisible = false,
                    PointCount = 3,
                    Width = 8,
                    Height = 8,
                    Fill = Brushes.White,
                    Margin = new Thickness(-4, 0, 0, 0)
                };
                var r2 = Size/2 - (ArrowArcSize/2) + (rp.Width/2);
                rp.RenderTransform = new TransformGroup
                {
                    Children = new TransformCollection
                    {
                        new RotateTransform((i + 0.5)*a),
                        new TranslateTransform(
                            r2*Math.Sin((i + 0.5)*a*dDegToRad) + 5,
                            -r2*Math.Cos((i + 0.5)*a*dDegToRad) + 5
                            )
                    }
                };
                gArcs.Children.Add(rp);
            }

            //if (SelectedItem.Items == null || SelectedItem.Items.Count <= 0) return;
            //foreach (var i in SelectedItem.Items)
            //    if (i.Fill != null)
            //    {
            //    }
        }