Ejemplo n.º 1
0
        public void Plane_GetIntersectionFromPlaneAndCheckResultProperties_Expected(string planeCoordinate, string secondPlaneCoordinate, string expectedCoordinate)
        {
            // 1. Prepare
            ParametricLine        expected       = new ParametricLine(expectedCoordinate);
            Cartesian3dCoordinate expectedVector = expected.Vector.Normalize();
            Plane p1 = new Plane(planeCoordinate);
            Plane p2 = new Plane(secondPlaneCoordinate);

            // 2. Execute
            ParametricLine        l      = p1.GetIntersection(p2);
            Cartesian3dCoordinate vector = l.Vector.Normalize();

            // Warning ! thoses tests are dependent of other methods, in case of errors, checks the UnitsTests for those methods used for validation.
            bool isOnP1          = p1.IsOnPlane(l.Point);
            bool isOnP2          = p2.IsOnPlane(l.Point);
            bool isFurtherOnP1   = p1.IsOnPlane(l.Point + l.Vector);
            bool isFurtherOnP2   = p2.IsOnPlane(l.Point + l.Vector);
            bool isParrallelToP1 = new ParametricLine(l.Vector).IsParallelTo(p1);
            bool isParrallelToP2 = new ParametricLine(l.Vector).IsParallelTo(p2);

            // 3. Verify
            Assert.True(isOnP1);
            Assert.True(isOnP2);
            Assert.True(isFurtherOnP1);
            Assert.True(isFurtherOnP2);
            Assert.True(isParrallelToP1);
            Assert.True(isParrallelToP2);
            Assert.Equal(expected.X, l.X, PRECISION_DOUBLE);
            Assert.Equal(expected.Y, l.Y, PRECISION_DOUBLE);
            Assert.Equal(expected.Z, l.Z, PRECISION_DOUBLE);
            Assert.Equal(expectedVector.X, vector.X, PRECISION_DOUBLE);
            Assert.Equal(expectedVector.Y, vector.Y, PRECISION_DOUBLE);
            Assert.Equal(expectedVector.Z, vector.Z, PRECISION_DOUBLE);
        }
Ejemplo n.º 2
0
        public void ParametricLine_IsParallelToPlane_BeExpected(string planeCoordinates, string ccCoordinate1, string ccCoordinate2, bool result)
        {
            // 1. Prepare
            Plane p = new Plane(planeCoordinates);
            Cartesian3dCoordinate p1   = new Cartesian3dCoordinate(ccCoordinate1);
            Cartesian3dCoordinate p2   = new Cartesian3dCoordinate(ccCoordinate2);
            ParametricLine        line = ParametricLine.FromTwoPoints(p1, p2);

            // 2. Execute
            bool b = line.IsParallelTo(p);

            // 3. Verify
            Assert.Equal(result, b);
        }
Ejemplo n.º 3
0
        public void Plane_GetIntersectionFromLine_Expected(string planeCoordinate, string lineCoordinate, string expectedCoordinate)
        {
            // 1. Prepare
            Cartesian3dCoordinate expected = new Cartesian3dCoordinate(expectedCoordinate);
            ParametricLine        line     = new ParametricLine(lineCoordinate);
            Plane p = new Plane(planeCoordinate);

            // 2. Execute
            Cartesian3dCoordinate r = p.GetIntersection(line);

            // 3. Verify
            Assert.Equal(expected.X, r.X, PRECISION_DOUBLE);
            Assert.Equal(expected.Y, r.Y, PRECISION_DOUBLE);
            Assert.Equal(expected.Z, r.Z, PRECISION_DOUBLE);
        }
Ejemplo n.º 4
0
        public void ParametricLine_CreateFromTwoPoints_BeExpected(Cartesian3dCoordinate p1, Cartesian3dCoordinate p2, double x, double xt, double y, double yt, double z, double zt)
        {
            // 1. Prepare
            // Nothing to prepare.

            // 2. Execute
            ParametricLine o = ParametricLine.FromTwoPoints(p1, p2);

            // 3. Verify
            Assert.Equal(x, o.X, PRECISION_DOUBLE);
            Assert.Equal(xt, o.A, PRECISION_DOUBLE);
            Assert.Equal(y, o.Y, PRECISION_DOUBLE);
            Assert.Equal(yt, o.B, PRECISION_DOUBLE);
            Assert.Equal(z, o.Z, PRECISION_DOUBLE);
            Assert.Equal(zt, o.C, PRECISION_DOUBLE);
        }
Ejemplo n.º 5
0
        public void ParametricLine_CreateFromString_BeExpected(string coordinates, double x, double xt, double y, double yt, double z, double zt)
        {
            // 1. Prepare
            // Nothing to prepare.

            // 2. Execute
            ParametricLine o = new ParametricLine(coordinates);

            // 3. Verify
            Assert.Equal(x, o.X, PRECISION_DOUBLE);
            Assert.Equal(xt, o.A, PRECISION_DOUBLE);
            Assert.Equal(y, o.Y, PRECISION_DOUBLE);
            Assert.Equal(yt, o.B, PRECISION_DOUBLE);
            Assert.Equal(z, o.Z, PRECISION_DOUBLE);
            Assert.Equal(zt, o.C, PRECISION_DOUBLE);
        }
Ejemplo n.º 6
0
        public void Plane_GetPerpendicular_Expected(string planeCoordinate, string Cartesian3dCoordinate, string expectedCoordinate)
        {
            // 1. Prepare
            ParametricLine        expected = new ParametricLine(expectedCoordinate);
            Cartesian3dCoordinate cc       = new Cartesian3dCoordinate(Cartesian3dCoordinate);
            Plane p = new Plane(planeCoordinate);

            // 2. Execute
            ParametricLine l = p.GetPerpendicular(cc);

            // 3. Verify
            Assert.Equal(expected.X, l.X, PRECISION_DOUBLE);
            Assert.Equal(expected.Y, l.Y, PRECISION_DOUBLE);
            Assert.Equal(expected.Z, l.Z, PRECISION_DOUBLE);
            Assert.Equal(expected.A, l.A, PRECISION_DOUBLE);
            Assert.Equal(expected.B, l.B, PRECISION_DOUBLE);
            Assert.Equal(expected.C, l.C, PRECISION_DOUBLE);
        }
Ejemplo n.º 7
0
		public Present Evaluate(Present[] paramList)
		{
			D.Assert(paramList.Length == 1);
			IBoundsProvider boundsProvider = (IBoundsProvider)paramList[0];
			RenderRegion renderRegion = boundsProvider.GetRenderRegion();
			IPointTransformer robustPointTransform = this.imageTransformer.getSourceToDestLatLonTransformer();
			double num = 0.05;
			List<LatLon> asLatLonList = renderRegion.GetAsLatLonList();
			List<LatLon> list = new List<LatLon>();
			for (int i = 0; i < asLatLonList.Count; i++)
			{
				int index = (i + 1) % asLatLonList.Count;
				LatLon source = asLatLonList[i];
				LatLon dest = asLatLonList[index];
				ParametricLine parametricLine = new ParametricLine(source, dest);
				int numSteps = (int)Math.Max(1.0, parametricLine.Length() / num);
				List<LatLon> list2 = parametricLine.Interpolate(numSteps);
				list.AddRange(list2.ConvertAll<LatLon>((LatLon inp) => robustPointTransform.getTransformedPoint(inp)));
			}
			RenderRegion renderRegion2 = new RenderRegion(list, new DirtyEvent());
			return new BoundsPresent(renderRegion2);
		}
Ejemplo n.º 8
0
        public Present Evaluate(Present[] paramList)
        {
            D.Assert(paramList.Length == 1);
            IBoundsProvider boundsProvider = (IBoundsProvider)paramList[0];
            RenderRegion renderRegion = boundsProvider.GetRenderRegion();
            IPointTransformer robustPointTransform = imageTransformer.getSourceToDestLatLonTransformer();
            double num = 0.05;
            List<LatLon> asLatLonList = renderRegion.GetAsLatLonList();
            List<LatLon> list = new List<LatLon>();
            for (int i = 0; i < asLatLonList.Count; i++)
            {
                int index = (i + 1) % asLatLonList.Count;
                LatLon source = asLatLonList[i];
                LatLon dest = asLatLonList[index];
                ParametricLine parametricLine = new ParametricLine(source, dest);
                int numSteps = (int)Math.Max(1.0, parametricLine.Length() / num);
                List<LatLon> list2 = parametricLine.Interpolate(numSteps);
                list.AddRange(list2.ConvertAll<LatLon>((LatLon inp) => robustPointTransform.getTransformedPoint(inp)));
            }

            RenderRegion renderRegion2 = new RenderRegion(list, new DirtyEvent());
            return new BoundsPresent(renderRegion2);
        }
Ejemplo n.º 9
0
        // https://stackoverflow.com/a/49886367
        private void TryPickUpRock()
        {
            List <(int index, int x, int y, float roation, float scale)> rocksToRemove = new List <(int index, int x, int y, float roation, float scale)>()
            {
            };

            foreach (var rock in rocks.rockTypesAndLocations)
            {
                // Old code, couldn't handle rotation of rocks
                //bool matchX = false;
                //bool matchY = false;
                //if (x > (rock.x - (rocks.GetTexture(rock.index).width*rock.scale)))
                //if (x < rock.x)
                // matchX = true;
                //if (y+40 > (rock.y - (rocks.GetTexture(rock.index).height*rock.scale)))
                //if (y+40 < rock.y)
                //matchY = true;
                //if (matchX && matchY)
                //rocksToRemove.Add(rock);

                System.Drawing.RectangleF clientRectangle = new System.Drawing.RectangleF(rock.x, rock.y, (rocks.GetTexture(rock.index).width *rock.scale), (rocks.GetTexture(rock.index).height *rock.scale));

                // Create Matrix and rotate points.
                // Note: requires libgdiplus
                Matrix matrix = new Matrix();
                var    p      = new System.Drawing.PointF[] {
                    clientRectangle.Location,
                    new System.Drawing.PointF(clientRectangle.Right, clientRectangle.Top),
                    new System.Drawing.PointF(clientRectangle.Right, clientRectangle.Bottom),
                    new System.Drawing.PointF(clientRectangle.Left, clientRectangle.Bottom)
                };
                matrix.RotateAt(rock.rotation, new System.Drawing.PointF(clientRectangle.X, clientRectangle.Top));
                matrix.TransformPoints(p);

                var astronautRectangle = new Raylib_cs.Rectangle(x + 50, y + 10, 50, 110);

                // Detect if we're touching the corners of the rocks.
                if (Raylib.CheckCollisionPointRec(new Vector2(p[0].X, p[0].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[1].X, p[1].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[2].X, p[2].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(p[3].X, p[3].Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }

                var sideOneMidpoint   = new ParametricLine(p[0], p[1]);
                var sideTwoMidpoint   = new ParametricLine(p[1], p[2]);
                var sideThreeMidpoint = new ParametricLine(p[2], p[3]);
                var sideFourMidpoint  = new ParametricLine(p[3], p[0]);

                // Detect if touching midpoint of rock edge.
                if (Raylib.CheckCollisionPointRec(new Vector2(sideOneMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideTwoMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideThreeMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
                if (Raylib.CheckCollisionPointRec(new Vector2(sideFourMidpoint.Fraction(1.0f / 2.0f).X, sideOneMidpoint.Fraction(1.0f / 2.0f).Y), astronautRectangle))
                {
                    rocksToRemove.Add(rock);
                }
            }
            foreach (var rock in rocksToRemove)
            {
                collectRocks.rocksCollected++;
                rocks.rockTypesAndLocations.Remove(rock);
            }
            if (rocksToRemove.Count == 0)
            {
                IsMoving = false;
            }
        }