Beispiel #1
0
        public void VolumeTestTriangle()
        {
            var expected = 50m;
            var pyramid  = new Pyramid(5, 6, 10, _CalcTypes.VolumeCalc, _3DBases.Triangle);

            Assert.AreEqual(pyramid.Volume, expected);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            #region Algo.1

            //var algo1 = new Algorithms1();
            //var result = algo1.TwoSum(new int[] { 1, 7, 11, 15, 8 }, 9);

            #endregion

            #region Algo.2

            //var node1 = new ListNode(2);
            //node1.next = new ListNode(4);
            //node1.next.next = new ListNode(3);

            //var node2 = new ListNode(5);
            //node2.next = new ListNode(6);
            //node2.next.next = new ListNode(4);

            //var algo2 = new Algorithms2();
            //var result = algo2.AddTwoNumbers(node1, node2);

            #endregion

            #region Pyramid

            var pyramid = new Pyramid();
            pyramid.PrintPyramid();

            #endregion


            Console.ReadKey();
        }
Beispiel #3
0
        public void LocalFunctionExample_Should_Return_Tranigle()
        {
            Pyramid pyramid = new Pyramid(5, 5, 5);
            LocalFunctionExample examplePyramid = new LocalFunctionExample(pyramid);

            Assert.AreEqual((5.0 * 5 * 5) / 3, examplePyramid.ObjectVolumn);
        }
        public Route <int> FindLongestRoute(Pyramid <int> pyramid)
        {
            _memorizer = new Dictionary <Pyramid <int>, NumericRoute>();
            var res = FindLongestRouteWithMem(pyramid);

            return(res);
        }
Beispiel #5
0
    public static void Main()
    {
        var pyramid = new Pyramid(0);

        pyramid.GetHeight();
        pyramid.PrintTriangle();
    }
Beispiel #6
0
        /// <summary>
        /// Добавление фигуры
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonOk_Click(object sender, EventArgs e)
        {
            FigureBase figure = null;

            try
            {
                if (comboBoxType.Text == _figureKey[FigureType.Ball])
                {
                    figure = new Ball(GetCorrect(Convert.ToDouble, maskedTextBox1.Text));
                }

                if (comboBoxType.Text == _figureKey[FigureType.Pyramid])
                {
                    figure = new Pyramid(GetCorrect(Convert.ToDouble, maskedTextBox2.Text),
                                         GetCorrect(Convert.ToDouble, maskedTextBox3.Text));
                }

                if (comboBoxType.Text == _figureKey[FigureType.Parallelepiped])
                {
                    figure = new Parallelepiped(GetCorrect(Convert.ToDouble, maskedTextBox2.Text),
                                                GetCorrect(Convert.ToDouble, maskedTextBox3.Text), GetCorrect(Convert.ToDouble, maskedTextBox1.Text));
                }

                Figure = figure ?? throw new ArgumentException("Тип не выбран!");

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (ArgumentException)
            {
                MessageBox.Show("Неверные данные!");
            }
        }
        private RenderTargetBitmap createBitmap(BaseSymbol symbol)
        {
            if (symbolCache.ContainsKey(symbol))
            {
                return(symbolCache[symbol]);
            }

            FrameworkElement element;

            switch (symbol.Type)
            {
            default:     // ToDo: support different types
                element = new Pyramid {
                    Color = symbol.Color
                };
                break;
            }
            element.Width = element.Height = symbol.Size;

            element.Measure(new Size(element.Width, element.Height));
            element.Arrange(new Rect(0, 0, element.Width, element.Height));

            var bitmap = new RenderTargetBitmap((int)element.Width * 2, (int)element.Height * 2, 192, 192, PixelFormats.Pbgra32);

            bitmap.Render(element);
            bitmap.Freeze();

            symbolCache.Add(symbol, bitmap);
            return(bitmap);
        }
        public void DataParsedIntoPyramid_FindNumericalRoute_PyramidRuleAppliedCalledWithThePyramid()
        {
            //Arrange
            const string path       = "Some path";
            var          stringData = new[] { "blah", "blah blah" };

            var pyramid = new Pyramid <int>(754);

            var extractor = new Mock <IFileDataExtractor>();

            extractor.Setup(m => m.ExtractLines(path)).Returns(stringData);

            var dataParser = new Mock <IDataParser <int> >();

            dataParser.Setup(m => m.ParseIntoPyramid(stringData)).Returns(new Option <Pyramid <int> >(pyramid));

            var ruleApplier = new Mock <IPyramidRuleApplier <int> >();

            ruleApplier.Setup(m => m.TransformPyramid(pyramid)).Returns(new Pyramid <int>(1));
            var longestRouteFinder = new Mock <ILongestRouteFinder <int> >();

            var routeFinder = new RouteFinder(
                extractor.Object,
                dataParser.Object,
                ruleApplier.Object,
                longestRouteFinder.Object
                );

            //Act
            routeFinder.FindNumericalRouteFromFile(path);

            //Assert
            ruleApplier.Verify(m => m.TransformPyramid(pyramid), Times.Once);
            ruleApplier.VerifyNoOtherCalls();
        }
Beispiel #9
0
        public void PyramidVolumeTest(double baseS, double height)
        {
            Pyramid testPyramid = new Pyramid(baseS, height);
            double  result      = testPyramid.Volume();

            Assert.Equal(250, result, 1);
        }
Beispiel #10
0
        private void FindPyramidRegion(Pyramid pyramid)
        {
            int minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;

            pyramid.Points.ForEach(p =>
            {
                if (minX > p.X)
                {
                    minX = p.X;
                }
                if (minY > p.Y)
                {
                    minY = p.Y;
                }
                if (maxX < p.X)
                {
                    maxX = p.X;
                }
                if (maxY < p.Y)
                {
                    maxY = p.Y;
                }
            });
            pyramid.Begin = new Point(minX, minY);
            pyramid.End   = new Point(maxX, maxY);
        }
Beispiel #11
0
        public static Shape3D Create(string name, ShapeType.Material mType, double arg1, double arg2)
        {
            Shape3D rv = null;

            switch (name)
            {
            case "球":
                rv = Ball.Create(arg1, mType);
                return(rv);

            case "立方體":
                rv = Cube.Create(arg1, mType);
                return(rv);

            case "圓柱體":
                rv = Cylinder.Create(arg1, arg2, mType);
                return(rv);

            case "金字塔":
                rv = Pyramid.Create(arg1, arg2, mType);
                return(rv);

            default:
                return(rv);
            }
        }
        public void TestShapeAddition(double containerHeight, double pyramidS, double pyramidH)
        {
            var box     = new Box(containerHeight);
            var pyramid = new Pyramid(pyramidS, pyramidH);

            Assert.False(box.Add(pyramid));
        }
Beispiel #13
0
        private void PyramidToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HSPyramidForm setup        = new HSPyramidForm(this);
            DialogResult  dialogresult = setup.ShowDialog();

            HornSchunck.pyramidLevel = pyramidLevel;


            if (pyramidON)
            {
                pyramid = Pyramid.PyramidOn;
                HornSchunck.pyramidOn = 1;
            }

            else
            {
                pyramid = Pyramid.PyramidOff;
                HornSchunck.pyramidOn = 0;
            }


            refreshWindow();

            setup.Dispose();
        }
Beispiel #14
0
        private ImageSource GetCachedBitmap(Color color, double size)
        {
            var key = Tuple.Create(color, size);

            if (bitmapCache.ContainsKey(key))
            {
                return(bitmapCache[key]);
            }

            var pin = new Pyramid();

            pin.Width = pin.Height = size;
            pin.Color = color;

            pin.Measure(new Size(pin.Width, pin.Height));
            pin.Arrange(new Rect(0, 0, pin.Width, pin.Height));

            const double hdFactor = 2; // resolution relative to 96 DPI
            var          bitmap   = new RenderTargetBitmap((int)(pin.Width * hdFactor), (int)(pin.Height * hdFactor),
                                                           96 * hdFactor, 96 * hdFactor, PixelFormats.Pbgra32);

            bitmap.Render(pin);
            bitmap.Freeze();

            bitmapCache[key] = bitmap;
            return(bitmap);
        }
Beispiel #15
0
        public void VolumeTestSquare()
        {
            var expected = 83.333m;
            var pyramid  = new Pyramid(5, 6, 10, _CalcTypes.VolumeCalc, _3DBases.Square);

            Assert.AreEqual(pyramid.Volume, expected);
        }
Beispiel #16
0
        public void AreaTestTriangle()
        {
            var expected = 119.957m;
            var pyramid  = new Pyramid(5, 6, 10, _CalcTypes.AreaCalc, _3DBases.Triangle);

            Assert.AreEqual(pyramid.SurfaceArea, expected);
        }
Beispiel #17
0
        public void AreaTestSquare()
        {
            var expected = 128.078m;
            var pyramid  = new Pyramid(5, 6, 10, _CalcTypes.AreaCalc, _3DBases.Square);

            Assert.AreEqual(pyramid.SurfaceArea, expected);
        }
Beispiel #18
0
        private void On_btnAdd_Click(object sender, EventArgs e)
        {
            var bP = GetBasePoint();

            try
            {
                var xDisplacement = Convert.ToSingle((string)tbX.Text);
                var yDisplacement = Convert.ToSingle((string)tbY.Text);
                var zDisplacement = Convert.ToSingle((string)tbZ.Text);

                var newBasePoint = new Vertex(bP.X + xDisplacement, bP.Y + yDisplacement, bP.Z + zDisplacement);

                var sidesNumber = Convert.ToInt32((string)tbSidesNumber.Text);
                var radius      = Convert.ToUInt32((string)tbRadius.Text);
                var height      = Convert.ToSingle((string)tbHeight.Text);
                var pyramid     = new Pyramid(newBasePoint, sidesNumber, radius, height);
                objects3D.Add(pyramid);
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message, ERROR_MESSAGEBOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Close();
        }
        public static Object chooseObject(OpenGLControl openGLControl, int _chooseIcon, Vertex center)
        {
            Object choose_Object = null;

            //Xử lý chọn Object để vẽ.
            switch (_chooseIcon)
            {
            case 1:    //Cube
                choose_Object = new Cube();
                break;

            case 2:    //Pyramid - Hình chóp đáy là hình vuông
                choose_Object = new Pyramid();
                break;

            case 3:    //Prism - Hình lăng trụ đáy là tam giác đều
                choose_Object = new Prism();
                break;

            default:
                break;
            }
            if (choose_Object != null) // nếu tạo được object
            {
                choose_Object.name += Object._countObjects.ToString();
                listObject.Add(choose_Object);
            }
            return(choose_Object);
        }
    public static void pyramid_num_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    PYRAMID_NUM_TEST tests PYRAMID_NUM.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 June 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int n;

        Console.WriteLine("");
        Console.WriteLine("PYRAMID_NUM_TEST");
        Console.WriteLine("  PYRAMID_NUM computes the pyramidal numbers.");
        Console.WriteLine("");

        for (n = 1; n <= 10; n++)
        {
            Console.WriteLine("  "
                              + n.ToString().PadLeft(4) + "  "
                              + Pyramid.pyramid_num(n).ToString().PadLeft(6) + "");
        }
    }
Beispiel #21
0
        public void PyramidAreaWithNegativesTest(double baseLenght, double height, double expecterArea)
        {
            Pyramid pyramid    = new Pyramid(baseLenght, height);
            double  actualArea = pyramid.GetArea();

            Assert.AreEqual(expecterArea, actualArea, 0.0001);
        }
Beispiel #22
0
        public void PyramidVolumeTest(double baseLenght, double height, double expecterArea)
        {
            Pyramid pyramid    = new Pyramid(baseLenght, height);
            double  actualArea = pyramid.GetVolume();

            Assert.AreEqual(expecterArea, actualArea, 0.01);
        }
Beispiel #23
0
        public override void LoadContent()
        {
            _platform = new Box(300, 20, 10, new Vector2(ScreenManager.ScreenWidth / 2f, 500), Color.White, Color.Black, 1);
            _platform.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _refTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 32, 32, 2, 0, 0,
                                                               Color.White, Color.Black);

            _refBody = BodyFactory.Instance.CreateRectangleBody(32, 32, 3f);
            _refGeom = GeomFactory.Instance.CreateRectangleGeom(_refBody, 32, 32);
            _refGeom.FrictionCoefficient = .2f;

            //create the _pyramid near the bottom of the screen.
            _pyramid = new Pyramid(_refBody, _refGeom, 32f / 3f, 32f / 3f, 32, 32, _pyramidBaseBodyCount,
                                   new Vector2(ScreenManager.ScreenCenter.X - _pyramidBaseBodyCount * .5f * (32 + 32 / 3) + 20,
                                               ScreenManager.ScreenHeight - 300));

            _pyramid.Load(PhysicsSimulator);

            //Add the geometries to the watermodel's fluiddragcontroller to make them float.
            _waterModel.FluidDragController.AddGeom(_platform.Geom);

            foreach (Geom geom in _pyramid.Geoms)
            {
                _waterModel.FluidDragController.AddGeom(geom);
            }

            // load a font
            _font = ScreenManager.ContentManager.Load <SpriteFont>("Content/Fonts/detailsfont");

            base.LoadContent();
        }
Beispiel #24
0
        public void Pyramid_GetVolume_Volume()
        {
            Pyramid newPyramid = new Pyramid(3, 4, 10);
            int     result     = newPyramid.GetVolume();

            Assert.AreEqual(result, 40);
        }
Beispiel #25
0
        public void TestMethod2()
        {
            // Arrange
            var pyramidDef = new List <string>
            {
                "215",
                "192 124",
                "117 269 442",
                "218 836 347 235",
                "320 805 522 417 345",
                "229 601 728 835 133 124",
                "248 202 277 433 207 263 257",
                "359 464 504 528 516 716 871 182",
                "461 441 426 656 863 560 380 171 923",
                "381 348 573 533 448 632 387 176 975 449",
                "223 711 445 645 245 543 931 532 937 541 444",
                "330 131 333 928 376 733 017 778 839 168 197 197",
                "131 171 522 137 217 224 291 413 528 520 227 229 928",
                "223 626 034 683 839 052 627 310 713 999 629 817 410 121",
                "924 622 911 233 325 139 721 218 253 223 107 233 230 124 233"
            };
            var    pyramid = new Pyramid(pyramidDef);
            string pathMax;
            // Act
            var maxSum = pyramid.FindMaxSum(out pathMax);

            // Assert
            Assert.AreEqual(8186, maxSum);
            Assert.AreEqual("215, 192, 269, 836, 805, 728, 433, 528, 863, 632, 931, 778, 413, 310, 253", pathMax);
        }
Beispiel #26
0
        public void RollForTile()
        {
            ActiveTile = Pyramid.ActivateTile(new TileRoll());
            Pyramid.FillNextEmptyPyramidPosition(TopDirectionTile, SetAsideTile);
            UpdateDirectionTiles();

            while (Pyramid.HasEmptyPyramidPositions)
            {
                Pyramid.FillNextEmptyPyramidPosition(TopDirectionTile, SetAsideTile);
            }

            SetAsideTile = ActiveTile;

            #region Local Functions
            void UpdateDirectionTiles()
            {
                var tempTopTile = TopDirectionTile;

                TopDirectionTile    = BottomDirectionTile;
                BottomDirectionTile = tempTopTile;
                BottomDirectionTile.FlipDirection();
            }

            #endregion
        }
Beispiel #27
0
        public static Pyramid SetPyramid(out string name, out string type, out double a, out double b, out double h,
                                         out double l, out double area, out double volume, out int tops, out int edges, out int sides)
        {
            Console.Write("Set Name of Pyramid: ");
            name = Console.ReadLine();

            Console.Write("Set Type of Pyramid: ");
            type = Console.ReadLine();

            Console.Write("Enter two sides of pyramid base, height and apophema:\n");
            Console.Write("a: ");
            a = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
            Console.Write("b: ");
            b = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
            Console.Write("h: ");
            h = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
            Console.Write("l: ");
            l = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);

            Pyramid pyramid = new Pyramid();

            pyramid.A    = a;
            pyramid.B    = b;
            pyramid.L    = l;
            pyramid.H    = h;
            pyramid.Name = name;
            pyramid.Type = type;
            area         = pyramid.Area();
            volume       = pyramid.Volume();
            tops         = pyramid.QuantityOfTops();
            edges        = pyramid.QuantityOfEdges();
            sides        = pyramid.QuantityOfSides();

            return(pyramid);
        }
        private void SetScenario(Scenario newScenario)
        {
            scenario = newScenario;

            #region doc:ConfigureLayers

            tourLayer.Shapes.Clear();
            orderLayer.Shapes.Clear();
            depotLayer.Shapes.Clear();

            foreach (var order in scenario.Orders)
            {
                var pin = new Cube {
                    Color = unplannedColor
                };
                pin.Width = pin.Height = Math.Sqrt(order.Quantity) * 10;
                ShapeCanvas.SetLocation(pin, new Point(order.Longitude, order.Latitude));
                orderLayer.Shapes.Add(pin);
                pin.Tag = order;
            }

            foreach (var depot in scenario.Depots)
            {
                var pyramid = new Pyramid();
                pyramid.Width = pyramid.Height = 30;
                pyramid.Color = depot.Color;
                ShapeCanvas.SetLocation(pyramid, new Point(depot.Longitude, depot.Latitude));
                depotLayer.Shapes.Add(pyramid);
            }

            #endregion // doc:ConfigureLayers
        }
        public PyramidChart(ChartView BaseChart)
        {
            pyramid1       = new Pyramid();
            var            = new Variables.Variables();
            this.BaseChart = BaseChart;

            BaseChart.Chart.Header.Text = "Pyramid Series";
            BaseChart.Chart.Series.Add(pyramid1);
            BaseChart.Chart.Legend.Visible     = true;
            BaseChart.Chart.Walls.Left.Visible = false;
            BaseChart.Chart.Walls.Left.Width   = 5;

            pyramid1.SeriesColor         = var.GetPaletteBasic[0];
            pyramid1.Chart.Zoom.Allow    = false;
            pyramid1.Chart.Panning.Allow = ScrollModes.None;

            pyramid1.DefaultNullValue = 0;
            pyramid1.Pen.Width        = 3;
            pyramid1.Pen.Visible      = true;
            pyramid1.Pen.Color        = Color.White;
            pyramid1.Pen.Style        = DashStyle.Solid;
            pyramid1.Pen.Transparency = 50;
            pyramid1.SizePercent      = 80;
            pyramid1.ColorEach        = false;

            for (int i = 0; i < var.GetValorPie1.Length; i++)
            {
                pyramid1.Add(var.GetValorPyramidX[i], var.GetValorPyramidY[i], var.GetValorPyramidName[i], var.GetPaletteBasic[i]);
            }

            pyramid1.Title = "Feudal society";

            BaseChart.Chart.Axes.Left.SetMinMax(BaseChart.Chart.Axes.Left.MinYValue - 50, BaseChart.Chart.Axes.Left.MaxYValue + 50);
            BaseChart.Chart.Axes.Bottom.SetMinMax(BaseChart.Chart.Axes.Bottom.MinYValue + 0.5, BaseChart.Chart.Axes.Bottom.MaxXValue - 0.5);

            BaseChart.Chart.Axes.Bottom.Increment = 5;
            BaseChart.Chart.Axes.Left.Increment   = 5;

            BaseChart.Chart.Axes.Left.Visible         = false;
            BaseChart.Chart.Axes.Left.AxisPen.Visible = true;
            BaseChart.Chart.Axes.Left.Ticks           = new Axis.TicksPen {
                Width = 2, Visible = true, Color = Color.FromRgb(200, 200, 200), EndCap = PenLineCap.Flat, Style = DashStyle.Solid, Length = 10,
            };
            BaseChart.Chart.Axes.Bottom.Visible = false;

            BaseChart.Chart.Axes.Left.Grid.Visible   = false;
            BaseChart.Chart.Axes.Bottom.Grid.Visible = false;
            BaseChart.Chart.Legend.Visible           = false;

            // Themes Marks
            Themes.AplicarMarksTheme1(BaseChart);

            BaseChart.Chart.Series[0].Marks.Font.Size = 18;
            BaseChart.Chart.Panel.MarginLeft          = 5;
            pyramid1.Marks.Style        = MarksStyles.Label;
            pyramid1.Marks.Visible      = false;
            pyramid1.Marks.DrawEvery    = 1;
            pyramid1.Marks.AutoPosition = true;
            pyramid1.Marks.OnTop        = true;
        }
Beispiel #30
0
        public void PyramidVolumeTest()
        {
            Pyramid pyramid = new Pyramid(100, 3);

            double result = pyramid.Volume();

            Assert.Equal(100, result, 2);
        }
 public void RequestSacrifice  (Pyramid p )
 {
     if (p != null)
     {
         if (resourceList.Count > 0 )
         {
             feed = true;
             StartCoroutine(FeedSacrifice(p));
         }
     }
 }
    IEnumerator FeedSacrifice(Pyramid p)
    {
        while (resourceList.Count > 0)
        {
            TempResourceButton b = resourceList[0];
            b.GetComponent<Button>().interactable = false;
            yield return new WaitForSeconds(timeBetweenSacrifices);
            p.ReciveSacrifice(b.sacType);
            resourceList.Remove(b);
            Destroy(b.gameObject);
        }

        feed = false;

    }
Beispiel #33
0
        public Arrow(float baseWidth, float arrowHeight, float lineLength, float lineWidth)
            : base(2)
        {
            this.arrowRadius = arrowHeight/2;
            float halfLength = (arrowHeight + lineLength) / 2;
            float arrowOffset = halfLength - arrowHeight / 2;//halfLength - arrowHeight;
            float lineOffset = halfLength - arrowHeight - lineLength/2;
            arrowPointerCenter = new Vector3(0, arrowOffset, 0);
            Objects[0] = new Pyramid(baseWidth, arrowHeight, baseWidth) { PositionV3 = arrowPointerCenter };
            Objects[1] = new Box(lineWidth, lineLength, lineWidth) { PositionV3 = new Vector3(0,lineOffset, 0)};
            Material = new PhongMaterial() { DiffuseColor = Color.Yellow, AmbientCoefficient=1f};

            foreach (IRenderable rObject in Objects)
                rObject.Material = Material;
        }
Beispiel #34
0
        static Pyramid ExtractPyramid()
        {
            string input = Properties.Resources.problem18_pyramid;
            string[] lines = input.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            Pyramid pyramid = new Pyramid();

            foreach (var line in lines)
            {
                var parts = line.Split(' ');
                pyramid.Items.Add(parts.Select(p => int.Parse(p)).ToArray());
            }

            return pyramid;
        }
Beispiel #35
0
        static Pyramid ExtractPyramid()
        {
            string input = Properties.Resources.problem67_triangle;
            string[] lines = input.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            Pyramid pyramid = new Pyramid();

            foreach (var line in lines)
            {
                var parts = line.Split(' ');
                pyramid.Items.Add(parts.Select(p => int.Parse(p)).ToArray());
            }

            return pyramid;
        }
        /// <summary>
        /// The arrow demo is uses an adaption of Chales Petzold's WPF arrow class 
        /// http://charlespetzold.com/blog/2007/04/191200.html to be used as custom MapSape
        /// </summary>
        /// <param name="layer"></param>
        public void AddPinWithLabel(ShapeLayer layer)
        {
            var center = new System.Windows.Point(8.4, 49); // KA
            var radius = 1; // radius in degrees of latitude

            var rand = new Random();
            Func<System.Windows.Point, double, System.Windows.Point> randomCoordinate = (c, r) =>
            {
                var angle = rand.NextDouble() * 2 * Math.PI;
                var distance = r * Math.Sqrt(rand.NextDouble());

                return new System.Windows.Point
                {
                    X = c.X + distance * Math.Cos(angle),
                    Y = c.Y + distance * Math.Sin(angle)
                };
            };

            bool useBitmapCache = true;

            var pin = new Pyramid();
            pin.Width = pin.Height = 10;

            pin.Measure(new Size(pin.Width, pin.Height));
            pin.Arrange(new Rect(0, 0, pin.Width, pin.Height));

            var bitmap = new RenderTargetBitmap((int)pin.Width, (int)pin.Height, 96, 96, PixelFormats.Pbgra32);
            bitmap.Render(pin);
            bitmap.Freeze();
            for (int i = 0; i < 5000; i++)
            {
                FrameworkElement symbol = null;
                if(useBitmapCache)
                    symbol = new Image { Source = bitmap };
                else
                    symbol = new Pyramid();
                symbol.Width = pin.Height = 10;
                ShapeCanvas.SetLocation(symbol, randomCoordinate(center, radius));
                symbol.ToolTip = "Hello";
                layer.Shapes.Add(symbol);
            }

            this.Map.SetMapLocation(center, 9);
        }
Beispiel #37
0
 private void button1_Click(object sender, EventArgs e)
 {
     textBoxV.Clear();
     if ((textBoxS.Text == "") || (textBoxH.Text == ""))
     {
         MessageBox.Show("Поля пусты");
         return;
     }
     int S, H;
     double V;
     if ((int.TryParse(textBoxS.Text, out S))
         && (int.TryParse(textBoxH.Text, out H))
         && ((S > 0) && (H > 0)))
     {
         Pyramid pyramid = new Pyramid(S, H);
         V = pyramid.ReturnVolume();
         textBoxV.AppendText(V.ToString());
     }
     else
     {
         MessageBox.Show("Введенные данные не корректны!");
     }
 }
        private RenderTargetBitmap createBitmap(BaseSymbol symbol)
        {
            if (symbolCache.ContainsKey(symbol))
                return symbolCache[symbol];

            FrameworkElement element;
            switch (symbol.Type)
            {
                default: // ToDo: support different types
                    element = new Pyramid {Color = symbol.Color};
                    break;
            }
            element.Width = element.Height = symbol.Size;

            element.Measure(new Size(element.Width, element.Height));
            element.Arrange(new Rect(0, 0, element.Width, element.Height));

            var bitmap = new RenderTargetBitmap((int)element.Width, (int)element.Height, 96, 96, PixelFormats.Pbgra32);
            bitmap.Render(element);
            bitmap.Freeze();

            symbolCache.Add(symbol, bitmap);
            return bitmap;
        }
Beispiel #39
0
        public Section(Volume vol, string path, XElement sectionElement)
            : this(vol)
        {
            this._SectionSubPath = path;

            //reader.Read();
            //XElement sectionElement = XDocument.ReadFrom(reader) as XElement;
            Debug.Assert(sectionElement != null);

            if(IO.GetAttributeCaseInsensitive(sectionElement,"name") != null)
                this.Name = IO.GetAttributeCaseInsensitive(sectionElement, "name").Value;

            this.Number = System.Convert.ToInt32(IO.GetAttributeCaseInsensitive(sectionElement,"number").Value);
            if (this.Name == null)
                this.Name = this.Number.ToString();

            foreach (XNode node in sectionElement.Nodes())
            {
                XElement elem = node as XElement;
                if (elem == null)
                    continue;

                switch (elem.Name.LocalName.ToLower())
                {
                    case "transform":
                        //Load a transform that can be applied to <Pyramids>
                        string Name = IO.GetAttributeCaseInsensitive(elem, "name").Value;
                        string mosaicTransformPath = IO.GetAttributeCaseInsensitive(elem, "path").Value;
                        bool UseForVolume = System.Convert.ToBoolean(IO.GetAttributeCaseInsensitive(elem, "UseForVolume").Value);
                        string TilePrefix = null;
                        if (IO.GetAttributeCaseInsensitive(elem, "FilePrefix") != null)
                            TilePrefix = IO.GetAttributeCaseInsensitive(elem, "FilePrefix").Value;

                        string TilePostfix = IO.GetAttributeCaseInsensitive(elem, "FilePostfix").Value;
                        TilesToSectionMapping mapping = new TilesToSectionMapping(this,
                                                                                Name,
                                                                                this.Path,
                                                                                mosaicTransformPath,
                                                                                TilePrefix,
                                                                                TilePostfix);

                        PyramidTransformNames.Add(Name);

                        WarpedTo.Add(Name, mapping);

                        if (UseForVolume ||  string.IsNullOrEmpty(DefaultPyramidTransform))
                        {
                            DefaultPyramidTransform = Name;
                        }

                        break;
                    case "pyramid":
                        //Load an image pyramid whose tiles can be warped using a <transform>
                        Name = IO.GetAttributeCaseInsensitive(elem, "name").Value;
            //                        string Pyramidpath = GetAttributeCaseInsensitive(elem,"path").Value;

                        /*PORT: The viewmodel needs to set this
                        if (UI.State.CurrentMode.Length == 0)
                            UI.State.CurrentMode = Pyramidpath;
                        */

                        Pyramid pyramid = new Pyramid(elem);

                        if(!this.ImagePyramids.ContainsKey(pyramid.Name))
                            this.ImagePyramids.Add(pyramid.Name, pyramid);

                        if (DefaultPyramid == null || DefaultPyramid.Length == 0)
                            DefaultPyramid = pyramid.Name;
                        else
                        {
                            if (this.ImagePyramids[DefaultPyramid].GetLevels().Count < pyramid.GetLevels().Count)
                                DefaultPyramid = pyramid.Name;
                        }

                        ChannelNames.Add(pyramid.Name);
                        break;
                    case "tileset":
                        //Load a pre-transformed pyramid whose tiles have a fixed size
                        TileGridMapping tilegridmapping = TileGridMapping.CreateFromTilesetElement(elem, this);
                        this.AddTileset(tilegridmapping);
                        DefaultTileset = tilegridmapping.Name;
                        /*PORT: The viewmodel needs to set this
                        if (UI.State.CurrentMode.Length == 0 || UI.State.CurrentMode == "8-bit")
                            UI.State.CurrentMode = mosaicTransformPath;
                        */
                        break;
                    case "channelinfo":
                        this.ChannelInfoArray = ChannelInfo.FromXML(elem);
                        break;
                    case "notes":
                        if (elem.Value != null)
                        {
                            //string SourceFilename = IO.GetAttributeCaseInsensitive(elem, "SourceFilename").Value;

                            string NotesString = elem.Value;

                            NotesString = NotesString.Trim();
                            this.Notes = Uri.UnescapeDataString(NotesString);
                            /*
                            if (String.Compare(encodingType, "txt", true) == 0)
                            {
                                this.Notes = Uri.UnescapeDataString(elem.Value);
                            }
                            else
                            {

                                //Convert the string from hex to bytes
                                System.Text.UTF8Encoding encoder = new UTF8Encoding();
                                this.Notes = encoder.GetString(encoder.GetBytes(NotesString));
                            }
                             */
                        }

                        break;
                }
            }
        }
Beispiel #40
0
 public Pyramid()
 {
     singleton = this;
 }