Exemple #1
0
        public override void RenderAction(IRenderable element, Graphics graphics, ControlRender render)
        {
            ComplexShape complex = element as ComplexShape;

            base.RenderAction(element, graphics, render);

            Region current = null;

            //Set up clipping if required
            if (complex.Clip)
            {
                Region region = new Region(complex.GetPath());
                current = graphics.Clip;
                graphics.SetClip(region, CombineMode.Intersect);
            }

            //Render the children
            if (complex.Children != null)
            {
                foreach (Solid solid in complex.RenderList)
                {
                    graphics.TranslateTransform(solid.Bounds.X, solid.Bounds.Y);

                    IFormsRenderer renderer = render.GetRenderer(solid);
                    renderer.RenderAction(solid, graphics, render);
                    graphics.TranslateTransform(-solid.Bounds.X, -solid.Bounds.Y);
                }
            }

            if (complex.Clip)
            {
                graphics.Clip = current;
            }
        }
Exemple #2
0
 protected virtual void ComplexDraw(Graphics graphics, ComplexShape shape)
 {
     foreach (var s in shape.Shapes)
     {
         Draw(graphics, s);
     }
 }
        TextShape CreateCustomTextualMarker(ComplexShape markerShape)
        {
            RectangleF2D box = new RectangleF2D(-15, -15, 30, 30);

            EllipseShape eShape = new EllipseShape(box);
            TextShape    txt    = new TextShape();

            eShape.BeginUpdate();
            eShape.Name = "bg";
            eShape.Appearance.ContentBrush = new SolidBrushObject(Color.White);
            eShape.Appearance.BorderBrush  = new SolidBrushObject(Color.Black);
            eShape.Appearance.BorderWidth  = 2;
            eShape.EndUpdate();

            txt.BeginUpdate();
            txt.Name = "marketText";
            txt.Text = "Test";
            txt.Box  = box;
            txt.AppearanceText.TextBrush = new SolidBrushObject(Color.Black);
            txt.AppearanceText.Font      = new Font("Tahoma", 8f);
            txt.ShadingFlags             = ShadingFlags.NoShading;
            txt.EndUpdate();

            markerShape.AddRange(new BaseShape[] { eShape, txt });
            return(txt);
        }
        public PanelGeneratorService(ShapeFactory shapeFactory)
        {
            _buildZone = shapeFactory.CreateBuildZone();

            _blockedZones = new List <ComplexShape>()
            {
                shapeFactory.CreateBlockedZone()
            };
        }
Exemple #5
0
        public void TestRaycastComplex()
        {
            // lines
            Vector2[][] lines =
            {
                new[] { new Vector2(5.01675f, 21.14647f), new Vector2(9.35574f,  23.23984f) },
                new[] { new Vector2(9.35574f, 23.23984f), new Vector2(5.01675f,  21.14647f) },
                new[] { new Vector2(4.6742f,  12.27819f), new Vector2(18.37627f, 18.32993f) }
            };
            Vector2[] intrDot =
            {
                new Vector2(7.66f, 22.42f),
                new Vector2(7.66f, 22.42f),
                new Vector2(7.16f, 13.38f)
            };

            // Polygon points
            Vector2[] rect =
            {
                new Vector2(6.0f, 8.0f), new Vector2(4.0f, 12.0f)
            };
            Vector2[] polPoints =
            {
                new Vector2(8.0f,  6.0f), new Vector2(14.0f, 6.0f),
                new Vector2(14.0f, 2.0f), new Vector2(8.0f, 2.0f)
            };
            //Create Rectangles
            RectangleShape rectShape = new RectangleShape(rect[0], rect[1].X, rect[1].Y);
            //Create Polygons
            PolygonShape polyShape = new PolygonShape(polPoints);

            //Create Complex obj
            IShape[]     shapes    = { rectShape, polyShape };
            ComplexShape compShape = new ComplexShape(shapes);

            Collision.Transform compTranform =
                new Collision.Transform(new Vector2(5.0456f, 8.1234543f), 23.023f * Mathf.Deg2Rad);
            Console.WriteLine(23.023f * Mathf.Deg2Rad);

            // True fraction data
            float[] trueFraction = { 0.6090305f, 0.3909697f, 0.1815236f };

            for (var obj = 0; obj < lines.Length; obj++)
            {
                float   fraction;
                Vector2 normal;
                bool    rayCast = compShape.RayCast(compTranform, lines[obj][0], lines[obj][1], out fraction,
                                                    out normal);
                Assert.That(rayCast, "RayCast to Complex test({0}) failed.", obj);
                Vector2 point = lines[obj][0] + (lines[obj][1] - lines[obj][0]) * fraction;
                string  err   = String.Format(
                    "Intersect RayCast to Complex test({0}) failed; Intersect: trueFraction {1} (testFraction: {2}), intrPoint({3}), testPoint {4}, normal {5}",
                    obj, trueFraction[obj], fraction, intrDot[obj], point, normal);
                Assert.That(Mathf.FloatEquals(fraction, trueFraction[obj], 0.005f), err);
            }
        }
Exemple #6
0
        private void CreateArcNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            ArcShape shape = new ArcShape(new RectangleF2D(new PointF(-10, 0), new SizeF(20, 10)), 180, -60);

            shape.Appearance.ContentBrush = new SolidBrushObject(Color.White);
            shape.Name = "arcNeedle";
            needleShape.Add(shape);
        }
Exemple #7
0
        private void CreateSectorShape(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            SectorShape shape = new SectorShape(new RectangleF2D(new PointF(0, 30), new SizeF(80, 10)), 40, 270);

            shape.Appearance.ContentBrush = new SolidBrushObject(Color.Red);
            shape.Name = "sectorShape";
            needleShape.Add(shape);
        }
Exemple #8
0
        private void CreateBoxNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            BoxShape shape = new BoxShape(new RectangleF2D(new PointF(-10, 0), new SizeF(100, 10)));

            shape.Appearance.ContentBrush = new SolidBrushObject(Color.Gray);
            shape.Name = "boxNeedle";
            needleShape.Add(shape);
        }
Exemple #9
0
        private void CreateTextShape(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            TextShape shape = new TextShape();

            shape.Box  = new RectangleF2D(new PointF(-10, 0), new SizeF(100, 10));
            shape.Text = "    > > > > > ";
            shape.AppearanceText.TextBrush = new SolidBrushObject(Color.Salmon);
            needleShape.Add(shape);
        }
Exemple #10
0
        public override void WriteElement(SvgDocument document, Element element)
        {
            base.WriteElement(document, element);

            XmlNode node = Node;

            ComplexShape complex = (ComplexShape)element;

            //Add a group for the complex shape
            XmlElement newElement = null;

            StringBuilder builder = new StringBuilder();

            builder.Append("translate(");
            builder.Append(XmlConvert.ToString(complex.X));
            builder.Append(",");
            builder.Append(XmlConvert.ToString(complex.Y));
            builder.Append(")");

            newElement = document.CreateElement("g");
            newElement.SetAttribute("id", complex.Key + "Children");
            newElement.SetAttribute("transform", builder.ToString());

            document.ContainerNode.AppendChild(newElement);

            //Set the element as the temporary container node
            XmlNode temp    = document.ContainerNode;
            string  tempKey = document.ContainerKey;

            document.ContainerNode = newElement;
            document.ContainerKey  = complex.Key;

            //Add each child as an element
            foreach (Solid solid in complex.Children.Values)
            {
                document.AddElement(solid);
            }

            document.ContainerNode = temp;
            document.ContainerKey  = tempKey;

            //Write the ports

            //Restore the XmlElement
            SetNode(node);

            //Set the xml element for the group
            _groupElement = newElement;
        }
Exemple #11
0
        private void CreateEllipseNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            EllipseShape shape = new EllipseShape(new RectangleF2D(new PointF(-10, 0), new SizeF(100, 10)));
            LinearGradientBrushObject brush = new LinearGradientBrushObject(new PointF2D(2, 0), new PointF2D(0, 2));

            brush.StartColor = Color.Yellow;
            brush.EndColor   = Color.Magenta;
            shape.Appearance.ContentBrush = brush;
            shape.Name = "ellipseNeedle";
            needleShape.Add(shape);
        }
        public void setComplexShape(string newShape)
        {
            // exiting a complex shape
            if (newShape != null && (newShape.Equals("") || newShape.ToLower().Equals("None")))
            {
                if (shape is ComplexShape)
                {
                    shape = ((ComplexShape)this.shape).getBaseShape();
                    return;
                }
                //else shape = new Circle();
            }

            Shape bShape = ShapeHelper.getShape(newShape);

            if (bShape is ComplexShape)
            {
                ComplexShape complex = (ComplexShape)bShape;
                if (shape is ComplexShape)
                {
                    Shape baseShape = ((ComplexShape)shape).getBaseShape();
                    complex.setBaseShape(baseShape);
                    shape = complex;
                }
                else
                {
                    /* if(shape.getName().Equals("Plus") ||
                     *       shape.getName().Equals("PlusCorner") ||
                     *       shape.getName().Equals("HCurve") ||
                     *       shape.getName().Equals("HCurveFig8") ||
                     *       shape.getName().Equals("HLine") ||
                     *       shape.getName().Equals("HLineFig8") ||
                     *       shape.getName().Equals("HCircle") ||
                     *       shape.getName().Equals("HCircleFig8") ||
                     *       shape.getName().Equals("PlusHalf") ||
                     *       shape.getName().Equals("PlusHalfCap") ){
                     *   // TODO refactor this to allow for correct selection behaviour
                     *   shape = new Circle();
                     *   complex.setBaseShape(this.shape);
                     *   shape = complex;
                     * }
                     * else { /**/
                    complex.setBaseShape(this.shape);
                    shape = complex;
                    // }
                }
            }
        }
        /// <summary>
        /// Unity version of Shape from Sprite... this only works in editor but is faster than runtime implementation
        /// </summary>
        public static ComplexShape ShapeFromSprite(Sprite p_sprite, float p_detail = 1, float p_alphaTolerance = 0f, bool p_holeDetection = true)
        {
            if (p_sprite != null)
            {
                var         v_method = typeof(UnityEditor.Sprites.SpriteUtility).GetMethod("GenerateOutlineFromSprite", BindingFlags.Static | BindingFlags.NonPublic);
                Vector2[][] v_paths  = null;
                var         v_args   = new object[] { p_sprite, p_detail, (byte)(p_alphaTolerance * 255), p_holeDetection, v_paths };
                v_method.Invoke(null, v_args);
                v_paths = v_args[4] as Vector2[][];

                var v_shape = new ComplexShape(v_paths);
                v_shape.TransformPosition(Rect.MinMaxRect(p_sprite.bounds.min.x, p_sprite.bounds.min.y, p_sprite.bounds.max.x, p_sprite.bounds.max.y), new Rect(0, 0, 1, 1));
                return(v_shape);
            }
            return(null);
        }
Exemple #14
0
        public static ComplexShape ToTrianglesLegacy(this ComplexShape p_polygon)
        {
            ComplexShape v_trianglesShape = new ComplexShape();

            if (p_polygon != null)
            {
                foreach (var v_shape in p_polygon.Shapes)
                {
                    if (v_shape != null)
                    {
                        v_trianglesShape.AddShape(v_shape.ToTrianglesLegacy(), false);
                    }
                }
            }
            return(v_trianglesShape);
        }
        public void TestPointComplexCollision()
        {
            // true results
            bool[] trueResults = { false, true, true, false };
            // Points coordinates
            Vector2[] points =
            {
                new Vector2(3.07563f,  25.33322f),
                new Vector2(6.80563f,  18.67249f),
                new Vector2(13.35218f, 16.38881f),
                new Vector2(17.34862f, 12.54462f)
            };
            float[] pointTurn = { 234.12f, 12.234f, 11.11f, 66.66f, 111.111f };
            // Polygon points
            Vector2[] rect =
            {
                new Vector2(6.0f, 8.0f), new Vector2(4.0f, 12.0f)
            };
            Vector2[] polPoints =
            {
                new Vector2(8.0f,  6.0f), new Vector2(14.0f, 6.0f),
                new Vector2(14.0f, 2.0f), new Vector2(8.0f, 2.0f)
            };
            //Create Rectangle
            RectangleShape rectShape = new RectangleShape(rect[0], rect[1].X, rect[1].Y);
            //Create Polygon
            PolygonShape polShape = new PolygonShape(polPoints);

            //Create Complex obj
            IShape[]     shapes    = { rectShape, polShape };
            ComplexShape compShape = new ComplexShape(shapes);

            Collision.Transform compTranform =
                new Collision.Transform(new Vector2(5.0456f, 8.1234543f), 23.023f * Mathf.Deg2Rad);

            //Create points and check collisions
            for (var obj = 0; obj < trueResults.Length; obj++)
            {
                CollisionResult     result;
                PointShape          pointShape    = new PointShape(Vector2.Zero);
                Collision.Transform pointTranform =
                    new Collision.Transform(points[obj], pointTurn[obj] * Mathf.Deg2Rad);
                var    testResult = compShape.IntersectsWith(compTranform, pointShape, pointTranform, out result);
                string err        = String.Format("Point to Complex test({0}) failed for Point({1})", obj, points[obj]);
                Assert.That(trueResults[obj] == testResult, err);
            }
        }
        public void TestCircleComplexCollision()
        {
            // true results
            bool[] trueResults = { false, true, true, true };
            // Circles params: center coordiantes x,y ; radius, turn
            Vector2[][] circles =
            {
                new[] { new Vector2(-5.10756f, 25.02873f), new Vector2(3.234f,      34.098f) },
                new[] { new Vector2(4.14134f,  25.21903f), new Vector2(3.00123f,   324.081f) },
                new[] { new Vector2(10.11697f, 15.05666f), new Vector2(1.892340f,  7.00098f) },
                new[] { new Vector2(20.05097f, 18.25381f), new Vector2(4.1101f,   104.3398f) }
            };
            // Polygon points
            Vector2[] rect =
            {
                new Vector2(6.0f, 8.0f), new Vector2(4.0f, 12.0f)
            };
            Vector2[] polPoints =
            {
                new Vector2(8.0f,  6.0f), new Vector2(14.0f, 6.0f),
                new Vector2(14.0f, 2.0f), new Vector2(8.0f, 2.0f)
            };
            //Create Rectangle
            RectangleShape rectShape = new RectangleShape(rect[0], rect[1].X, rect[1].Y);
            //Create Polygon
            PolygonShape polShape = new PolygonShape(polPoints);

            //Create Complex obj
            IShape[]     shapes    = { rectShape, polShape };
            ComplexShape compShape = new ComplexShape(shapes);

            Collision.Transform compTranform =
                new Collision.Transform(new Vector2(5.0456f, 8.1234543f), 23.023f * Mathf.Deg2Rad);

            //Create circles and check collisions
            for (var obj = 0; obj < trueResults.Length; obj++)
            {
                CollisionResult     result;
                CircleShape         circleShape     = new CircleShape(Vector2.Zero, circles[obj][1].X);
                Collision.Transform circleTransform =
                    new Collision.Transform(circles[obj][0], circles[obj][1].Y * Mathf.Deg2Rad);
                var    testResult = compShape.IntersectsWith(compTranform, circleShape, circleTransform, out result);
                string err        = String.Format("Point to Complex test({0}) failed.", obj);
                Assert.That(trueResults[obj] == testResult, err);
            }
        }
        void CreateCustomIndicator(ComplexShape rootShape)
        {
            rootShape.Collection.Clear();                                          //remove old shapes
            EllipseShape el  = new EllipseShape(new RectangleF2D(0, 0, 100, 100)); //ellipse
            BoxShape     box = new BoxShape(new RectangleF2D(20, 40, 60, 20));     //horz box

            box.BeginUpdate();
            box.Appearance.ContentBrush = new SolidBrushObject(Color.White);
            box.Name = "horz";
            box.EndUpdate();

            el.BeginUpdate();
            el.Name = "el";
            el.Appearance.ContentBrush = new SolidBrushObject(Color.Red);
            el.EndUpdate();

            rootShape.AddRange(new BaseShape[] { el, box });
        }
Exemple #18
0
        static void Main(string[] args)
        {
            //var engine = new ShapeEngine();
            //var complex = new ComplexShape();

            //complex.Shapes = new List<BaseObjectDTO>();
            //var effect = new ComplexShapeEffect();
            //effect.Id = 80;
            //complex.Effects.Add(effect);

            //var point = new PointDTO();
            //point.Id = 1;
            //point.PositionX = 10;
            //point.PositionY = 20;
            //point.Effect.Id = 23;


            //var square = new SquareDTO();
            //square.Id = 1;
            //square.PositionX = 10;
            //square.PositionY = 20;
            //square.Effect.Id = 25;
            //square.Width = 90;

            //complex.Shapes.Add(point);
            //complex.Shapes.Add(square);


            //engine.CreateComplexShape(complex);


            //var obj = engine.GetComplexShape();


            var json = "{\"Shapes\":[{\"Id\":1,\"PositionX\":10,\"PositionY\":20,\"Effect\":{\"Id\":23}},{\"Width\":90,\"Id\":1,\"PositionX\":10,\"PositionY\":20,\"Effect\":{\"Id\":25}}],\"Effects\":[{\"Id\":80}]}";

            var shape = new ComplexShape();

            shape.Content = json;
            shape.Name    = "Ali test";
            //var repo = RepositoryFactory.GetRepository<ComplexShape>();

            //repo.Insert(shape);
        }
Exemple #19
0
        private void buttonEdit_Click(object sender, EventArgs e)
        {
            if (checkedListBox.SelectedItem != null)
            {
                checkedListBox.SetItemChecked(checkedListBox.Items.IndexOf(checkedListBox.SelectedItem), false);
                checkedListBox.ClearSelected();
            }
            if (checkedListBoxComplex.SelectedItem != null)
            {
                checkedListBoxComplex.SetItemChecked(checkedListBoxComplex.Items.IndexOf(checkedListBoxComplex.SelectedItem), false);
                checkedListBoxComplex.ClearSelected();
            }
            string nameOfType = selectedShape.CurrentFigure.GetType().ToString();

            if (nameOfType.Contains("ComplexShape"))
            {
                ComplexShape       complexShape = (ComplexShape)selectedShape.CurrentFigure;
                CreateComplexShape factory      = new CreateComplexShape(complexShape.Shapes, complexShape.InitWidth, complexShape.InitHeight);
                fabric = factory;
            }
            else
            {
                nameOfType = nameOfType.Substring(nameOfType.LastIndexOf('.') + 1);
                MethodInfo factoryCreator = null;
                foreach (Type type in factoryTypesList)
                {
                    if (type.ToString().Contains(nameOfType))
                    {
                        factoryCreator = type.GetMethod("getInstance");
                        break;
                    }
                }
                fabric = (CreateShape)factoryCreator.Invoke(null, new object[] { });
            }

            shapeList.Remove(selectedShape);
            RedrawShapes();
            pen                    = new Pen(selectedShape.Color, selectedShape.Width);
            selectedShape          = null;
            textBoxPenWidth.Text   = pen.Width.ToString();
            buttonColor.ForeColor  = pen.Color;
            buttonEdit.Enabled     = false;
            buttonRelocate.Enabled = false;
        }
Exemple #20
0
        public void TestComplexComplexCollision()
        {
            // Import data
            var comp    = Complexes.Comp;
            var results = CompCompTest.CompCompResults;

            for (int obj = 0; obj < results.Length; obj++)
            {
                IShape[] firstComplex  = new IShape[comp[results[obj].FirstShape].PolPoints.Length];
                IShape[] secondComplex = new IShape[comp[results[obj].SecondShape].PolPoints.Length];

                for (int pol = 0; pol < comp[results[obj].FirstShape].PolPoints.Length; pol++)
                {
                    firstComplex[pol] = new PolygonShape(comp[results[obj].FirstShape].PolPoints[pol]);
                }

                for (int pol = 0; pol < comp[results[obj].SecondShape].PolPoints.Length; pol++)
                {
                    secondComplex[pol] = new PolygonShape(comp[results[obj].SecondShape].PolPoints[pol]);
                }
                // Create complex objects
                ComplexShape firstComp  = new ComplexShape(firstComplex);
                ComplexShape secondComp = new ComplexShape(secondComplex);
                // Transform complex objects
                Collision.Transform firstCompTranform =
                    new Collision.Transform(comp[results[obj].FirstShape].Trans,
                                            comp[results[obj].FirstShape].Rotate);
                Collision.Transform secondCompTranform =
                    new Collision.Transform(comp[results[obj].SecondShape].Trans,
                                            comp[results[obj].SecondShape].Rotate);


                CollisionResult result;
                var             testResult = firstComp.IntersectsWith(firstCompTranform, secondComp, secondCompTranform,
                                                                      out result);
                string err = String.Format(
                    "Complex to Compex test({0}) failed; Complex({1}), Complex({2}) {3} {4}",
                    obj, results[obj].FirstShape, results[obj].SecondShape, comp[results[obj].FirstShape].Trans,
                    comp[results[obj].SecondShape].Rotate);

                Assert.That(results[obj].Result == testResult, err);
            }
        }
Exemple #21
0
        public void TestComplex()
        {
            var complex = new ComplexShape();

            complex.Add(new Rectangle());
            complex.Add(new Rectangle());
            complex.Add(new Rectangle());
            complex.Add(new Rectangle());

            double expectedArea = 4.0;
            double actualArea   = complex.Area();

            Assert.AreEqual(expectedArea, actualArea);

            double expectedPerimeter = 16.0;
            double actualPerimeter   = complex.Perimeter();

            Assert.AreEqual(expectedPerimeter, actualPerimeter);
        }
Exemple #22
0
        public static List <Mesh> BakeMeshs(this ComplexShape p_polygon, List <Rect> v_rectUvPerShape, TriangulationOptionEnum p_triangulationOption = TriangulationOptionEnum.Default)
        {
            List <Mesh> v_meshs = new List <Mesh>();

            for (int i = 0; i < p_polygon.Shapes.Count; i++)
            {
                var v_shape = p_polygon.Shapes[i];
                if (v_shape != null)
                {
                    var v_rectUv = v_rectUvPerShape != null && v_rectUvPerShape.Count > i ? v_rectUvPerShape[i] : v_shape.RectBounds;
                    var v_mesh   = v_shape.BakeMesh(v_rectUv, p_triangulationOption);
                    if (v_mesh != null)
                    {
                        v_meshs.Add(v_mesh);
                    }
                }
            }
            return(v_meshs);
        }
Exemple #23
0
        private void CreatePolylineNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            PolylineShape shape = new PolylineShape();

            shape.Points = new PointF[] {
                new PointF(0, 20), new PointF(-40, 25),
                new PointF(20, 5), new PointF(100, 0),
                new PointF(20, -5), new PointF(-40, -25),
                new PointF(0, -20)
            };

            shape.Appearance.ContentBrush = new SolidBrushObject(Color.Yellow);
            shape.Name = "polylineNeedle";
            needleShape.Add(shape);
        }
        protected override void ComplexDraw(Graphics graphics, ComplexShape shape)
        {
            if (shape != _lastShape)
            {
                _lastShape = shape;
                InitializeDictionary(shape);
            }
            foreach (var s in shape.Shapes)
            {
                if (!s.IsVisible)
                {
                    continue;
                }
                var colors = new Color[s.Points.Length];
                for (int i = 0; i < colors.Length; i++)
                {
                    var normals = _dictionary[s.Points[i]]
                                  .Where(sh => sh.IsVisible)
                                  .Select(k => k.Normal).ToArray();
                    var    aggregatedNormal = normals.Aggregate((sh, sum) => sh + sum) / normals.Length;
                    double x          = aggregatedNormal.X * 128 + 127;
                    double y          = aggregatedNormal.Y * 128 + 127;
                    float  brightness = Floats[(int)x, (int)y];
                    colors[i] = Color.FromArgb((int)(Pen.Color.R * brightness),
                                               (int)(Pen.Color.G * brightness),
                                               (int)(Pen.Color.B * brightness));
                }

                PointF[] ptsF = s.Points.CastToPointF();
                var      pBrush = new PathGradientBrush(ptsF);
                int      r = 0, g = 0, b = 0;
                foreach (var color in colors)
                {
                    r += color.R;
                    g += color.G;
                    b += color.B;
                }
                pBrush.SurroundColors = colors;
                pBrush.CenterColor    = Color.FromArgb(r / colors.Length, g / colors.Length, b / colors.Length);
                graphics.FillPolygon(pBrush, ptsF);
            }
        }
 private void InitializeDictionary(ComplexShape shape)
 {
     _dictionary = new Dictionary <Vector, List <Shape> >(shape.Points.Length, new VectorComparer());
     foreach (var sh in shape.Shapes)
     {
         foreach (var vector in sh.Points)
         {
             if (_dictionary.ContainsKey(vector))
             {
                 _dictionary[vector].Add(sh);
             }
             else
             {
                 _dictionary.Add(vector, new List <Shape> {
                     sh
                 });
             }
         }
     }
 }
Exemple #26
0
        public void TestComplexAABB()
        {
            ComplexShape complexShape = new ComplexShape(new IShape[]
            {
                new CircleShape(new Vector2(0, 20.0f), 14.577379f),
                new RectangleShape(new Vector2(0, 20.0f), 49, 3)
            });

            Collision.Transform complexTransform = new Collision.Transform(new Vector2(-1709.34f, 402.0f), 1.2456f);

            Vector2 lb;
            Vector2 ub;

            complexShape.GetAABB(complexTransform, out lb, out ub);

            Console.WriteLine("Complex LB: " + lb);
            Assert.That(VectorEquals(lb, new Vector2(-1742.869f, 384.6948f)), "ComplexShape.GetAABB() lower bound is incorrect");
            Console.WriteLine("Complex UB: " + ub);
            Assert.That(VectorEquals(ub, new Vector2(-1713.714f, 432.0851f)), "ComplexShape.GetAABB() upper bound is incorrect");
        }
Exemple #27
0
        /// <summary>
        /// Updates image data
        /// </summary>
        /// <param name="image">Component</param>
        /// <returns>Last updated record Id</returns>
        public int Update(ComplexShape image)
        {
            if (image.Id > 0 && !string.IsNullOrWhiteSpace(image.Name))
            {
                JsonSerializerSettings settings = new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                };
                var json = JsonConvert.SerializeObject(image, settings);

                var repository = _RepositoryFactory.GetRepository <GeoPaint.Entities.ComplexShape>();
                var entity     = repository.Get(image.Id);
                entity.Content = json;

                repository.Update(entity);
                return(entity.Id);
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
Exemple #28
0
        public void TestComplexRectangleCollision()
        {
            // Import data
            var comp    = Complexes.Comp;
            var rect    = Rects.Rect;
            var results = CompRectTest.CompRectResults;

            for (int obj = 0; obj < results.Length; obj++)
            {
                IShape[] polygons = new IShape[comp[results[obj].FirstShape].PolPoints.Length];
                for (int pol = 0; pol < comp[results[obj].FirstShape].PolPoints.Length; pol++)
                {
                    polygons[pol] = new PolygonShape(comp[results[obj].FirstShape].PolPoints[pol]);
                }

                // Create complex objects
                ComplexShape compShape = new ComplexShape(polygons);
                // Transform complex objects
                Collision.Transform firstCompTranform =
                    new Collision.Transform(comp[results[obj].FirstShape].Trans,
                                            comp[results[obj].FirstShape].Rotate);

                // Create Rectangle object
                RectangleShape rectShape =
                    new RectangleShape(rect[results[obj].SecondShape].Center, rect[results[obj].SecondShape].Width,
                                       rect[results[obj].SecondShape].Height);
                // Transform Rectangle object
                Collision.Transform rectTransform =
                    new Collision.Transform(rect[results[obj].SecondShape].Trans,
                                            rect[results[obj].SecondShape].Rotate);


                CollisionResult result;
                var             testResult = compShape.IntersectsWith(firstCompTranform, rectShape, rectTransform,
                                                                      out result);
                string err = String.Format("Complex to Rectangle test({0}) failed; Complex({1}), Rectangle({2})",
                                           obj, results[obj].FirstShape, results[obj].SecondShape);
                Assert.That(results[obj].Result == testResult, err);
            }
        }
Exemple #29
0
        public void TestComplexPolygonCollision()
        {
            // Import data
            var comp    = Complexes.Comp;
            var poly    = Polygons.Poly;
            var results = CompPolyTest.CompPolyResults;

            for (int obj = 0; obj < results.Length; obj++)
            {
                IShape[] polygons = new IShape[comp[results[obj].FirstShape].PolPoints.Length];

                for (int pol = 0; pol < comp[results[obj].FirstShape].PolPoints.Length; pol++)
                {
                    polygons[pol] = new PolygonShape(comp[results[obj].FirstShape].PolPoints[pol]);
                }

                // Create complex objects
                ComplexShape compShape = new ComplexShape(polygons);
                // Transform complex objects
                Collision.Transform firstCompTranform =
                    new Collision.Transform(comp[results[obj].FirstShape].Trans,
                                            comp[results[obj].FirstShape].Rotate);

                // Create polygon objects
                PolygonShape polShape = new PolygonShape(poly[results[obj].SecondShape].Points);
                // Transform polygon object
                Collision.Transform polTransform =
                    new Collision.Transform(poly[results[obj].SecondShape].Trans,
                                            poly[results[obj].SecondShape].Rotate);


                CollisionResult result;
                var             testResult = compShape.IntersectsWith(firstCompTranform, polShape, polTransform,
                                                                      out result);
                string err = String.Format("Complex to Polygon test({0}) failed; Complex({1}), Polygon({2})",
                                           obj, results[obj].FirstShape, results[obj].SecondShape);
                Assert.That(results[obj].Result == testResult, err);
            }
        }
Exemple #30
0
        private void CreatePolygonNeedle(INeedle needle)
        {
            ComplexShape needleShape = (ComplexShape)needle.Shape;

            needleShape.Collection.Clear();

            PolygonShape shape = new PolygonShape();

            shape.Points = new PointF[] {
                new PointF(0, 10),
                new PointF(75, 10),
                new PointF(70, -5),
                new PointF(100, 0),
                new PointF(65, -10),
                new PointF(70, 5),
                new PointF(0, -10)
            };

            shape.Appearance.ContentBrush = new SolidBrushObject(Color.AliceBlue);
            shape.Name = "polygonNeedle";
            needleShape.Add(shape);
        }
 public static void Composite()
 {
     IShape line = new Line(0, 0, 1, 1);
     Console.WriteLine("Rendering Line");
     line.RenderShape();
     Console.WriteLine("Rendering Rectangle");
     IShape Rectangle = new Rectangle();
     Rectangle.RenderShape();
     IShape complexShape = new ComplexShape();
     ((ComplexShape)complexShape).AddShape(new Line(0, 1, 1, 1));
     ((ComplexShape)complexShape).AddShape(new Line(0, 1, 1, 1));
     ((ComplexShape)complexShape).AddShape(new Line(0, 1, 1, 1));
     ((ComplexShape)complexShape).AddShape(new Line(0, 1, 1, 1));
     ((ComplexShape)complexShape).AddShape(new Line(0, 1, 1, 1));
     Console.WriteLine("Rendering Complex Shape");
     complexShape.RenderShape();
 }