Exemplo n.º 1
0
        public void CreateFacePairs_WhenGivenAPolygon_CreateFacePairs()
        {
            var polygon = new[]
            {
                new Vector2(-5, 5),
                new Vector2(5, 5),
                new Vector2(5, -5),
                new Vector2(-5, -5)
            };

            var pairs = helper.CreateFacePairs(polygon);

            Assert.AreEqual(pairs.Length, polygon.Length);

            for (int i = 0; i < polygon.Length; i++)
            {
                Assert.AreEqual(2, pairs[i].Length);

                if (i == polygon.Length - 1)
                {
                    Assert.AreEqual(pairs[i][0], polygon[i]);
                    Assert.AreEqual(pairs[i][1], polygon[0]);
                }
                else
                {
                    Assert.AreEqual(pairs[i][0], polygon[i]);
                    Assert.AreEqual(pairs[i][1], polygon[i + 1]);
                }
            }
        }
Exemplo n.º 2
0
        private void ResizeFace(IPlantCell aCell, IPlantCell bCell)
        {
            var aGeo  = aCell.Geometry;
            var aFace = aGeo.Face.Points;

            var bGeo  = bCell.Geometry;
            var bFace = bGeo.Face.Points;

            var pairs = geometryHelper.CreateFacePairs(bFace);

            for (int i = 0; i < aFace.Length; i++)
            {
                if (!geometryHelper.IsInsidePolygon(aFace[i], bFace))
                {
                    continue;
                }

                Vector2 nearest = FindNearestPoint(aFace[i], pairs);

                Vector2 direction = (aFace[i] - nearest) * aCell.Turgidity;

                aFace[i] = nearest;

                ChangeFace(aGeo, aFace[i], direction);
            }
        }
        public bool Colliding(IPlantCell a, IPlantCell b, bool allowOnLine)
        {
            if (!IsWithinHeight(a.Geometry, b.Geometry))
            {
                return(false);
            }

            var aFace = a.Geometry.Face.Points;
            var bFace = b.Geometry.Face.Points;

            var inside = IsInsidePolygon(aFace, bFace);

            if (inside && allowOnLine)
            {
                var isOnLine = IsOnPolygonLine(aFace, helper.CreateFacePairs(bFace));

                return(!isOnLine);
            }

            return(inside);
        }