Example #1
0
        private void AddItemToRow(ISolid item)
        {
            _currentRow.Items.Add(item);
            _remainingItems.RemoveFirst();

            if (item.Height < _currentRow.ShortestItemHeight)
            {
                _currentRow.ShortestItemHeight = item.Height;
            }
            if (item.Height > _currentRow.TallestItemHeight)
            {
                _currentRow.TallestItemHeight = item.Height;
            }

            _currentRow.WidthWithoutSpacing += item.Width;
            _currentRow.Width += item.Width;

            var canAccomodateSpace = _remainingSpaceAfterAddingItem >= ItemSpacing;

            if (canAccomodateSpace)
            {
                _currentRow.Width += ItemSpacing;
                _remainingSpace    = _width - _currentRow.Width;
            }
            else
            {
                NewRow();
            }
        }
Example #2
0
        public static bool TestCollide(ISolid obj1, ISolid obj2, PointF p1 = new PointF(), PointF p2 = new PointF())
        {
            CollideZone c1 = obj1.Shape.GetCollideZone();
            CollideZone c2 = obj1.Shape.GetCollideZone();

            PointF pos1 = p1 == new PointF(0, 0) ?
                          (obj1 as AbstrUnit).Pos : p1;

            PointF pos2 = p2 == new PointF(0, 0) ?
                          (obj2 as AbstrUnit).Pos : p2;



            if (!(obj1.Shape.IsActive & obj2.Shape.IsActive) ||
                (PointOp.lenght(PointOp.Sub(pos1, pos2)) > c1.R + c2.R))
            {
                return(false);
            }



            if ((obj1.Shape is SquareShape) && (obj1.Shape is SquareShape))
            {
                float edge1 = (obj1.Shape as SquareShape).Edge;
                float edge2 = (obj2.Shape as SquareShape).Edge;

                if (Math.Abs(pos1.X - pos2.X) <= (edge1 / 2 + edge2 / 2) &&
                    Math.Abs(pos1.Y - pos2.Y) <= (edge1 / 2 + edge2 / 2))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #3
0
        protected void PathConstruction(ISolid end)
        {
            End = end;
            BuildLine();

            PNode.TransformChanged += PathChanged;

            //react to position-changes of the pins node
            //which apparently is Parent.Parent for nodes and the PNode itself for Inlets/Outlets
            if (StartSolid is Rectangle)
            {
                StartSolid.PNode.TransformChanged += new PPropertyEventHandler(PinBoundsChanged);
            }
            else
            {
                StartSolid.PNode.Parent.Parent.TransformChanged += new PPropertyEventHandler(PinBoundsChanged);
            }

            if (EndSolid is Rectangle)
            {
                EndSolid.PNode.TransformChanged += new PPropertyEventHandler(PinBoundsChanged);
            }
            else
            {
                EndSolid.PNode.Parent.Parent.TransformChanged += new PPropertyEventHandler(PinBoundsChanged);
            }
        }
        public void UpdateSolidPosition(ISolid solid)
        {
            var newList = SolidPositions.Where(x => x.Id != solid.Id).ToList();

            newList.Add(solid);
            SolidPositions = newList;
        }
 public static dynamic GetTSObject(ISolid dynObject)
 {
     if (dynObject is null)
     {
         return(null);
     }
     return(dynObject.teklaObject);
 }
Example #6
0
        public static bool TestMoveCollide(IMovable obj1, ISolid obj2)
        {
            if (!(obj1 is ISolid))
            {
                return(false);
            }

            PointF test_pos = PointOp.Sum(
                (obj1 as AbstrUnit).Pos,
                PointOp.Mul(obj1.Direction, obj1.Speed));

            return(TestCollide(obj1 as ISolid, obj2, test_pos));
        }
Example #7
0
        public TempPath(IGraphElementHost host, ISolid start)
            : base(host)
        {
            Points = new List <PointF>();
            Start  = start;

            PNode.Brush = null;

            //start point
            Points.Add(Start.GlobalMiddle);

            //end point
            Points.Add(Start.GlobalMiddle);
        }
Example #8
0
        //create a path between two solids
        public IPath CreatePath(IPathHost host, ISolid start, ISolid end)
        {
            var p = new LinkPath(host, start, end);

            if (p.Start.IsConnectable)
            {
                p.Start.Connectable.ConnectTo(p.End.Connectable, host);
            }
            if (p.End.IsConnectable)
            {
                p.End.Connectable.ConnectTo(p.Start.Connectable, host);
            }
            LinkRoot.Add(p);
            return(p);
        }
Example #9
0
        public static ModelInstance ModelInstance(string categoryName, ISolid location)
        {
            if (string.IsNullOrWhiteSpace(categoryName) || location == null)
            {
                return(null);
            }

            InstanceProperties instanceProperties = new InstanceProperties();

            instanceProperties.CategoryName = categoryName;

            ModelInstance modelInstance = new ModelInstance()
            {
                Properties = instanceProperties,
                Name       = "Solid",
                Location   = location
            };

            return(modelInstance);
        }
Example #10
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine($"{Environment.NewLine}Please enter a watertank solid shape : cube, cuboid or cylinder");
                string tank = Console.ReadLine();

                if (tank == "cube")
                {
                    Console.WriteLine("Please enter the side of the cube:");
                    int side = Convert.ToInt32(Console.ReadLine());
                    _solid = new Solid(new Rectangle(side, side), side);
                }
                else if (tank == "cuboid")
                {
                    Console.WriteLine("Please enter the length of the cuboid:");
                    int lenght = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Please enter the breath of the cuboid:");
                    int breadth = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Please enter the height of the cuboid:");
                    int height = Convert.ToInt32(Console.ReadLine());
                    _solid = new Solid(new Rectangle(lenght, breadth), height);
                }
                else if (tank == "cylinder")
                {
                    Console.WriteLine("Please enter the radius of the cylinder:");
                    int radius = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Please enter the height of the cylinder:");
                    int height = Convert.ToInt32(Console.ReadLine());
                    _solid = new Solid(new Circle(radius), height);
                }
                else
                {
                    Console.WriteLine("Please enter a valid option");
                }

                Console.WriteLine($"The volume of the watertank is:{_volumeService.Volume(_solid)}");
            }
        }
Example #11
0
        public bool AddEntity(ISolid entity)
        {
            // If we're not the root node and this node doesn't contain the given entity, we can't add it.
            // If it just intersects, and doesn't contain, it will end up adding it to the parent node.
            if (this.root != null && !bounds.Contains(entity.BoundingBox))
            {
                return(false);
            }

            numItems++;

            if (!this.HasSplit && this.CanSplit && numItems > MaxItems)
            {
                this.Split();
            }

            // Add to the children nodes
            // If they all return false for AddEntity, add it to this node and not a child.
            // It's on a border.
            if (this.HasSplit)
            {
                foreach (var child in this.children)
                {
                    if (child.AddEntity(entity))
                    {
                        return(true);
                    }
                }
            }

            // If this node hasn't split or the entity was on a border of the split,
            // add it directly to this node's items list.
            this.items.Add(entity);

            return(true);
        }
Example #12
0
        internal static global::Topologic.Cell CellBySolid(ISolid bhomSolid, double tolerance)
        {
            BoundaryRepresentation bhomBoundaryRepresentation = bhomSolid as BoundaryRepresentation;

            if (bhomBoundaryRepresentation != null)
            {
                return(CellByBoundaryRepresentation(bhomBoundaryRepresentation, tolerance));
            }

            Cuboid bhomCuboid = bhomSolid as Cuboid;

            if (bhomCuboid != null)
            {
                return(CellByCuboid(bhomCuboid));
            }

            Sphere bhomSphere = bhomSolid as Sphere;

            if (bhomSphere != null)
            {
                return(CellBySphere(bhomSphere));
            }
            throw new NotImplementedException("This type of Solid is not yet supported.");
        }
Example #13
0
 /// <summary>
 /// Возвращает точку пересечения луча с объектом.
 /// </summary>
 /// <param name="angle"></param>
 /// <param name="koef"></param>
 /// <param name="shooter"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 private Vector2 GetHitPosition(Vector2 direction, Character shooter, ISolid target)
 {
     Vector2 hitPosition = new Vector2(-1);
     Vector2 p0 = shooter.Position;
     float minX = float.PositiveInfinity;
     float minY = float.PositiveInfinity;
     // пересечение с отрезками полигона
     Vector2[] vertices = target.Vertices;
     Vector2 prevV = vertices[vertices.Length - 1];
     for (int i = 0; i < vertices.Length; i++)
     {
         Vector2 curV = vertices[i];
         Vector2 intr = GetIntersectionPosition(shooter.Position, direction, curV, curV - prevV);
         float x = intr.X;
         float y = intr.Y;
         // точка пересечения прямых в пределах отрезка
         if (((x >= prevV.X) && (x < curV.X)) ||
             ((x >= curV.X) && (x < prevV.X)) ||
             ((y >= prevV.Y) && (y < curV.Y)) ||
             ((y >= curV.Y) && (y < prevV.Y)))
         {
             // точка пересечения в направлении стрельбы
             Vector2 delta = new Vector2(x - p0.X, y - p0.Y);
             if (((delta.X >= 0 && direction.X >= 0) || (delta.X < 0 && direction.X < 0)) &&
                 ((delta.Y >= 0 && direction.Y >= 0) || (delta.Y < 0 && direction.Y < 0)))
             {
                 if (delta.X != 0)
                 {
                     float positiveDeltaX = Math.Abs(delta.X);
                     if (positiveDeltaX < minX)
                     {
                         minX = positiveDeltaX;
                         hitPosition = new Vector2((float)x, (float)y);
                     }
                 }
                 else
                 {
                     float positiveDeltaY = Math.Abs(delta.Y);
                     if (positiveDeltaY < minY)
                     {
                         minY = positiveDeltaY;
                         hitPosition = new Vector2((float)x, (float)y);
                     }
                 }
             }
         }
         prevV = curV;
     }
     return hitPosition;
 }
Example #14
0
 public Intersection( ISolid s )
 {
     Solid = s;
 }
Example #15
0
        /***************************************************/

        public static ISurface ITransform(this ISolid geometry, TransformMatrix transform)
        {
            return(Transform(geometry as dynamic, transform));
        }
Example #16
0
        public static Level FromFile(string path)
        {
            Level level = new Level();

            string scriptPath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + ".csx");

            if (File.Exists(scriptPath))
            {
                // get GameTime's assembly (MonoGame.Framework) to load that assembly, because we need it for almost everything
                ScriptOptions scriptOptions = ScriptOptions.Default.AddReferences(typeof(GameTime).Assembly);
                level.Script = CSharpScript.Create(
                    File.ReadAllText(scriptPath),
                    globalsType: typeof(Level),
                    options: scriptOptions);

                level.Script.Compile();
            }

            XElement rootEle = XElement.Load(path);

            level.TextureDirectory  = Path.Combine(Path.GetDirectoryName(path), rootEle.Element("TextureDirectory").Value);
            level.TextureDictionary = new LazyLoadingMaterialDictionary(level.TextureDirectory);

            if (rootEle.Element("BackgroundColor") != null)
            {
                level.BackgroundColor = new Color().FromXml(rootEle.Element("BackgroundColor"));
            }

            // loop through all solids, find their type with reflection, create a new instance of that type
            // and let it initialize itself with the provided xml.
            foreach (XElement xEle in rootEle.Element("Solids").Elements())
            {
                Type solidType = Type.GetType("PeridotEngine.Engine.World.WorldObjects.Solids." + xEle.Name.LocalName);

                // if solid is not implemented by engine check if it's implemented by the game
                if (solidType == null)
                {
                    solidType = Type.GetType("PeridotEngine.Game.World.WorldObjects.Solids." + xEle.Name.LocalName);
                }

                ISolid solid = (ISolid)solidType.GetMethod("FromXml").Invoke(null, new object[] { xEle, level.TextureDictionary });

                level.WorldObjects.Add(solid);
            }

            // do the same for entities
            foreach (XElement xEle in rootEle.Element("Entities").Elements())
            {
                Type entityType = Type.GetType("PeridotEngine.Engine.World.WorldObjects.Entities." + xEle.Name.LocalName);

                // if entity is not implemented by engine check if it's implemented by the game
                if (entityType == null)
                {
                    entityType = Type.GetType("PeridotEngine.Game.World.WorldObjects.Entities." + xEle.Name.LocalName);
                }

                IEntity entity = (IEntity)entityType.GetMethod("FromXml").Invoke(null, new object[] { xEle, level.TextureDictionary });

                level.WorldObjects.Add(entity);
            }

            // do the same for colliders
            foreach (XElement xEle in rootEle.Element("Colliders").Elements())
            {
                Type colliderType = Type.GetType("PeridotEngine.Engine.World.Physics.Colliders." + xEle.Name.LocalName);

                // if collider is not implemented by engine check if it's implemented by the game
                if (colliderType == null)
                {
                    colliderType = Type.GetType("PeridotEngine.Game.World.Physics.Colliders." + xEle.Name.LocalName);
                }

                ICollider collider = (ICollider)colliderType.GetMethod("FromXml").Invoke(null, new object[] { xEle });

                level.Colliders.Add(collider);
            }

            return(level);
        }
Example #17
0
 public Intersection(ISolid s)
 {
     Solid = s;
 }
Example #18
0
 public LinkPath(IGraphElementHost host, ITempPath temppath, ISolid end)
     : base(host, temppath.Start)
 {
     Points = temppath.Points;
     PathConstruction(end);
 }
Example #19
0
 public int Volume(ISolid solid)
 {
     return(solid.Volume());
 }
 public void AddSolidPosition(ISolid solid)
 {
     SolidPositions.Add(solid);
 }
Example #21
0
        /***************************************************/
        /**** Private Fallback Methods                  ****/
        /***************************************************/

        private static double Volume(this ISolid solid)
        {
            Reflection.Compute.RecordError($"Volume is not implemented for ISolids of type: {solid.GetType().Name}.");
            return(double.NaN);
        }
Example #22
0
        public bool AddEntity(ISolid entity)
        {
            // If we're not the root node and this node doesn't contain the given entity, we can't add it.
            // If it just intersects, and doesn't contain, it will end up adding it to the parent node.
            if (this.root != null && !bounds.Contains(entity.BoundingBox))
                return false;

            numItems++;

            if (!this.HasSplit && this.CanSplit && numItems > MaxItems)
                this.Split();

            // Add to the children nodes
            // If they all return false for AddEntity, add it to this node and not a child.
            // It's on a border.
            if (this.HasSplit)
                foreach (var child in this.children)
                    if (child.AddEntity(entity))
                        return true;

            // If this node hasn't split or the entity was on a border of the split,
            // add it directly to this node's items list.
            this.items.Add(entity);

            return true;
        }
Example #23
0
 public static double IVolume(this ISolid solid)
 {
     return(Volume(solid as dynamic));
 }
Example #24
0
 public LinkPath(IGraphElementHost host, ISolid start, ISolid end)
     : base(host, start)
 {
     PathConstruction(end);
 }