コード例 #1
0
ファイル: HomeController.cs プロジェクト: jreyes15/DOne
        public JsonResult getGridBounds(string value)
        {
            GridBounds result = new GridBounds();

            result = value.ToGridBounds();
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public override IExplicitShape <GridPoint3> Transform(IExplicitShape <GridPoint3> input)
        {
            var offset1     = offset.GetGridPoint();
            var shape       = input.Translate(offset1);
            var storageRect = GridBounds.Translate(input.Bounds, offset1);

            return(shape.ToExplicit(storageRect));
        }
コード例 #3
0
        public void ConstructorTest(float size)
        {
            var gridBounds = new GridBounds(size);

            Assert.AreEqual(gridBounds.minX, gridBounds.minZ);
            Assert.AreEqual(gridBounds.maxX, gridBounds.maxZ);
            Assert.IsTrue(Mathf.Approximately(gridBounds.minX + gridBounds.maxX, 0));
            Assert.IsTrue(Mathf.Approximately(gridBounds.minZ + gridBounds.maxZ, 0));
        }
コード例 #4
0
        protected override IExplicitShape <GridPoint3> Generate()
        {
            var shapes        = baseShape.Select(g => g.GetShape());
            var boundingPlane = shapes.Select(s => (GridRect)s.Bounds).Aggregate(GridRect.UnionBoundingBox);
            var shape         = ImplicitShape.Layer(shapes.Select(p => (IImplicitShape <GridPoint2>)p));
            var boundingShape = new GridBounds(boundingPlane.Point.To3DXY(0), boundingPlane.Size.To3DXY(baseShape.Count));

            return(shape.ToExplicit(boundingShape));
        }
コード例 #5
0
        public IEnumerator SetSizeTest()
        {
            var gridBound = new GridBounds(1);
            var bounds    = new Bounds(new Vector3(1, 1, 1), new Vector3(5, 5, 5));

            gridBound.SetSize(bounds);

            Assert.IsTrue(gridBound.minX < -1);
            Assert.IsTrue(gridBound.maxX > 1);
            Assert.IsTrue(gridBound.minZ < -1);
            Assert.IsTrue(gridBound.maxZ > 1);

            return(null);
        }
コード例 #6
0
ファイル: Piece.cs プロジェクト: Lukasy14/game-Alliance
        protected bool InvalidTarget(float distance, float radiusSquared, Invader target, GsRectangle targetBounds)
        {
            // if the target isn't our specialty
            bool notOurSpecialty = !InvaderMatchesSpecialty(target);

            if (notOurSpecialty)
            {
                return(true);
            }

            // if we can't see the target, then return true
            bool cantSeeTarget = distance > radiusSquared;

            if (cantSeeTarget)
            {
                return(true);
            }

            // if the target reached the end, then return true
            bool targetReachedDestination = (target.TargetCell == null);

            if (targetReachedDestination)
            {
                return(true);
            }

            // if the target cell hasn't even started yet
            bool targetNotStartedYet = !GridBounds.Contains(targetBounds);

            if (targetNotStartedYet)
            {
                return(true);
            }

            // if the target is moving too fast, then return true
            bool targetMovingTooFast = Calculator.ComputeDirection(this, target) == GsVector.Zero;

            if (targetMovingTooFast)
            {
                return(true);
            }

            // return false if we get here
            return(false);
        }
コード例 #7
0
        public override List <IExplicitShape <GridPoint3> > Execute(IEnumerable <IExplicitShape <GridPoint3> > input)
        {
            var inputList = input.ToList();

            var shape1 = inputList[0];
            var shape2 = inputList[1];
            var scale  = scaleFactor.GetGridPoint();
            var shape  = shape1.Product(shape2, scale);

            var storageRect = new GridBounds(
                shape1.Bounds.Point.Mul(scale) - shape2.Bounds.Size,
                shape1.Bounds.Size.Mul(scale) + shape2.Bounds.Size * 2);

            return(new List <IExplicitShape <GridPoint3> >
            {
                shape.ToExplicit(storageRect)
            });
        }
コード例 #8
0
        protected override IExplicitShape <GridPoint3> Generate()
        {
            var shape1 = shape2Graph1.GetShape();
            var shape2 = shape2Graph2.GetShape();
            var shape3 = shape2Graph3.GetShape();

            var bounds12 = GridRect.UnionBoundingBox(shape1.Bounds, shape2.Bounds);
            var bounds13 = GridRect.UnionBoundingBox(shape1.Bounds, shape3.Bounds);
            var bounds23 = GridRect.UnionBoundingBox(shape2.Bounds, shape3.Bounds);

            var layer1 = shape1.Layer(bounds23.Size.Y);
            var layer2 = shape2.Layer(bounds13.Size.X);
            var layer3 = shape3.Layer(bounds12.Size.Y);

            layer2 = layer2.SwapToXZY();
            layer3 = layer3.SwapToZYX();

            var layer1Translation = new GridPoint3(0, 0, bounds23.Point.Y);
            var layer2Translation = new GridPoint3(0, 0, bounds13.Point.X);
            var layer3Translation = new GridPoint3(0, 0, bounds12.Point.Y);

            var bound1 = new GridBounds(layer1.Bounds.Point + layer1Translation, layer1.Bounds.Size);
            var bound2 = new GridBounds(layer2.Bounds.Point + layer2Translation, layer2.Bounds.Size);
            var bound3 = new GridBounds(layer3.Bounds.Point + layer3Translation, layer3.Bounds.Size);

            var fixedLayer1 = layer1.Translate(layer1Translation);
            var fixedLayer2 = layer2.Translate(layer2Translation);
            var fixedLayer3 = layer3.Translate(layer3Translation);

            var fixedLayer12  = ImplicitShape.Intersection(fixedLayer1, fixedLayer2);
            var fixedLayer123 = ImplicitShape.Intersection(fixedLayer12, fixedLayer3);

            var bound12  = GridBounds.Intersection(bound1, bound2);
            var bound123 = GridBounds.Intersection(bound12, bound3);

            return(fixedLayer123.ToExplicit(bound123));
        }
コード例 #9
0
ファイル: StringExtensions.cs プロジェクト: jreyes15/DOne
        /// <summary>
        /// To cast the string value to grid bounds model
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static GridBounds ToGridBounds(this string value)
        {
            //Declarations
            GridBounds g = new GridBounds();

            int           indexOfWhiteSpace = 0;
            List <string> values            = new List <string>();

            try
            {
                indexOfWhiteSpace = value.IndexOf <char>(c => !char.IsWhiteSpace(c));
                if (indexOfWhiteSpace > 0)
                {
                    //Split the string value by space
                    values = value.Split(' ', (char)StringSplitOptions.RemoveEmptyEntries).ToList();
                }
                else
                {
                    //Split the string value by chars
                    values = value.Split().ToList();
                }
                //If the total of values aren't equals to 2, thrown an error
                if (values.Count != 2)
                {
                    return(new GridBounds("Error: The typed values aren't a correct coordinate, please try again!"));
                }
                else
                {
                    g = new GridBounds(values[0].ToInteger(), values[1].ToInteger());
                }
            }
            catch (Exception ex)
            {
            }
            return(g);
        }
コード例 #10
0
ファイル: ObjectGrid.cs プロジェクト: sladen/openbve2
 // constructors
 internal GridUnpopulatedLeafNode(GridInternalNode parent, GridBounds rectangle)
 {
     this.Parent = parent;
     this.Rectangle = rectangle;
     this.BoundingRectangle = GridBounds.Uninitialized;
     this.VisibleLeafNodes = null;
 }
コード例 #11
0
ファイル: ObjectGrid.cs プロジェクト: sladen/openbve2
 // constructors
 internal GridPopulatedLeafNode(GridInternalNode parent, GridBounds rectangle, StaticOpaqueObject initialStaticOpaqueObject)
 {
     this.Parent = parent;
     this.Rectangle = rectangle;
     this.BoundingRectangle = GridBounds.Uninitialized;
     this.VisibleLeafNodes = null;
     if (initialStaticOpaqueObject != null) {
         this.StaticOpaqueObjects = new StaticOpaqueObject[] { initialStaticOpaqueObject };
         this.StaticOpaqueObjectCount = 1;
     } else {
         this.StaticOpaqueObjects = new StaticOpaqueObject[] { null };
         this.StaticOpaqueObjectCount = 0;
     }
     this.DisplayList = new DisplayList();
     this.TransparentFaces = new object[1];
     this.TransparentFaceCount = 0;
 }
コード例 #12
0
ファイル: ObjectGrid.cs プロジェクト: sladen/openbve2
 // constructors
 internal GridInternalNode(GridInternalNode parent, GridBounds rectangle, GridNode[] children)
 {
     this.Parent = parent;
     this.Rectangle = rectangle;
     this.BoundingRectangle = GridBounds.Uninitialized;
     this.Children = children;
 }
コード例 #13
0
ファイル: StringExtensions.cs プロジェクト: jreyes15/DOne
        /// <summary>
        /// Cast the string value to a Movement model, the movement coordinates are breadcrumbs
        /// </summary>
        /// <param name="value">string with the instructions</param>
        /// <param name="initialize">Starting coordinates, I mea, last coordinate of the rover</param>
        /// <param name="limits">Grid bounds</param>
        /// <returns></returns>
        private static Movement ToMovement(this string value, Coordinate initialize, GridBounds limits)
        {
            //Declarations
            Movement result    = new Movement(initialize.X, initialize.Y, initialize.Z);
            string   direction = initialize.Z;

            try
            {
                //This loop completes the rotation before the movement is made
                foreach (char v in value)
                {
                    switch (v)
                    {
                    case 'L':
                        direction = getLeftCardinalDirection(direction);
                        break;

                    case 'R':
                        direction = getRightCardinalDirection(direction);
                        break;
                    }
                }
                //This cases are in order to decide the correct direction of the movement and do it.
                //ASSUMPTION: The rovers can't go outside of the grid bounds, but the movements continue.
                //If the movement exceeds the grid bounds, the movement is not performed and the error message will be displayed.
                switch (direction)
                {
                case "N":
                    result.currentAxis       = "N";
                    result.currentValueXAxis = result.lastValueXAxis;
                    if ((result.lastValueYAxis + 1) > limits.Y)
                    {
                        result.currentValueXAxis = result.lastValueXAxis;
                        result.error             = "You cannot move the rover out of bounds because it can get lost.";
                        result.done = false;
                    }
                    else
                    {
                        result.currentValueYAxis = result.lastValueYAxis + 1;
                        result.done = true;
                    }
                    break;

                case "O":
                    result.currentAxis = "O";
                    if ((result.lastValueXAxis - 1) < 0)
                    {
                        result.currentValueYAxis = result.lastValueYAxis;
                        result.error             = "You cannot move the rover out of bounds because it can get lost.";
                        result.done = false;
                    }
                    else
                    {
                        result.currentValueXAxis = result.lastValueXAxis - 1;
                        result.done = true;
                    }
                    result.currentValueYAxis = result.lastValueYAxis;
                    break;

                case "S":
                    result.currentAxis       = "S";
                    result.currentValueXAxis = result.lastValueXAxis;
                    if ((result.lastValueYAxis - 1) < 0)
                    {
                        result.lastValueYAxis = result.lastValueYAxis;
                        result.error          = "You cannot move the rover out of bounds because it can get lost.";
                        result.done           = false;
                    }
                    else
                    {
                        result.currentValueYAxis = result.lastValueYAxis - 1;
                        result.done = true;
                    }
                    break;

                case "E":
                    result.currentAxis = "E";
                    if ((result.lastValueXAxis + 1) > limits.X)
                    {
                        result.currentValueXAxis = result.lastValueXAxis;
                        result.error             = "You cannot move the rover out of bounds because it can get lost.";
                        result.done = false;
                    }
                    else
                    {
                        result.currentValueXAxis = result.lastValueXAxis + 1;
                        result.done = true;
                    }
                    result.currentValueYAxis = result.lastValueYAxis;
                    break;
                }
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
コード例 #14
0
ファイル: StringExtensions.cs プロジェクト: jreyes15/DOne
        /// <summary>
        /// Get the list of movements from the instructions
        /// </summary>
        /// <param name="value">instructions text</param>
        /// <param name="initialize">information of the axis (X & Y) and the Cardinal Direction </param>
        /// <param name="limits">Limits of the axis (X & Y)</param>
        /// <returns></returns>
        public static List <Movement> ToMovements(this string value, Coordinate initialize, GridBounds limits)
        {
            //Declarations
            List <Movement> g = new List <Movement>();
            Coordinate      currentPosition = initialize;
            string          helper          = value;
            string          instructions    = "";
            int             indexOfM        = 0;

            try
            {
                //Do the action while the helper has text
                while (helper.Length > 0)
                {
                    indexOfM = helper.IndexOf('M');
                    //Get the movement instructions, I mean, get the rotation instructions (can be more than 1) and the movement instruction
                    instructions = helper.Substring(0, indexOfM);
                    //Split the text into instructions in order to do the movements requested
                    string[] directions = instructions.Trim().Split();
                    foreach (string direction in directions)
                    {
                        Movement result = direction.ToMovement(currentPosition, limits);
                        result.Input = instructions + "M";
                        g.Add(result);
                        //re-init the values of the last coordinate to re-use on the next movement
                        initialize.X = result.currentValueXAxis;
                        initialize.Y = result.currentValueYAxis;
                        initialize.Z = result.currentAxis;
                    }
                    helper = helper.Substring(indexOfM + 1, helper.Length - (indexOfM + 1));
                }
            }
            catch (Exception ex)
            {
            }
            return(g);
        }