Example #1
0
        public void Execute(int index)
        {
            if (Excluded[index] == 1)
            {
                return;
            }

            Vector2 position = new Vector2(Position[index].x, Position[index].z);

            if (LineSegment2D.DistanceToPoint(position) < Width / 2f)
            {
                VegetationMaskScale[index]   = math.max(VegetationMaskScale[index], Scale);
                VegetationMaskDensity[index] =
                    math.max(VegetationMaskDensity[index], Denisty);
            }
        }
Example #2
0
        public void Execute(int index)
        {
            if (Excluded[index] == 1)
            {
                return;
            }

            Vector2 position = new Vector2(Position[index].x, Position[index].z);

            float perlin = noise.snoise(new float2(position.x / NoiseScale, position.y / NoiseScale));

            perlin += 1f;
            perlin /= 2f;
            perlin  = math.clamp(perlin, 0, 1);

            float additionalWidth = math.lerp(AdditionalWidth, AdditionalWidthMax, perlin);

            if (LineSegment2D.DistanceToPoint(position) < (additionalWidth + Width / 2f))
            {
                Excluded[index] = 1;
            }
        }
Example #3
0
        public void DistToPoint_Test()
        {
            var a11  = new Vector2D(-10, 0);
            var a12  = new Vector2D(10, 0);
            var seg1 = new LineSegment2D(a11, a12);

            var a21  = new Vector2D(0, -10);
            var a22  = new Vector2D(0, 10);
            var seg2 = new LineSegment2D(a21, a22);

            for (int x = -10; x < 10; x++)
            {
                for (int y = -20; y < 20; y++)
                {
                    var p = new Vector2D(x, y);

                    var dist1 = seg1.DistanceToPoint(p);
                    Assert.AreEqual(System.Math.Abs(y), dist1, "dist1 = " + dist1 + " y = " + System.Math.Abs(y));

                    var dist2 = seg2.DistanceToPoint(p);
                    Assert.AreEqual(System.Math.Abs(x), dist2, "dist2 = " + dist2 + " x = " + System.Math.Abs(x));

                    Vector2D projPoint;

                    if (seg1.ProjectPointToLine(p, out projPoint))
                    {
                        var dist = projPoint.Distance(p);
                        Assert.AreEqual(dist1, dist, "dist1 = " + dist1 + " dist = " + dist);
                    }

                    if (seg2.ProjectPointToLine(p, out projPoint))
                    {
                        var dist = projPoint.Distance(p);
                        Assert.AreEqual(dist2, dist, "dist2 = " + dist1 + " dist = " + dist);
                    }
                }
            }
        }
Example #4
0
        public void ProjectPointToLine_Test()
        {
            var a11  = new Vector2D(-10, 0);
            var a12  = new Vector2D(10, 0);
            var seg1 = new LineSegment2D(a11, a12);

            for (int x = -20; x < 20; x++)
            {
                var p = new Vector2D(x, 10);

                var dist1 = seg1.DistanceToPoint(p);
                Assert.AreEqual(10, dist1);

                Vector2D projPoint;

                var res = seg1.ProjectPointToLine(p, out projPoint);


                if (x >= a11.X && x <= a12.X)
                {
                    Assert.IsTrue(res);
                    var dist = projPoint.Distance(p);
                    Assert.AreEqual(dist1, dist, "dist1 = " + dist1 + " dist = " + dist);
                    var contains = seg1.Bounds.Contains(projPoint);
                    Assert.IsTrue(contains);
                }
                else
                {
                    Assert.IsFalse(res);
                    var contains = seg1.Bounds.Contains(projPoint);
                    Assert.IsFalse(contains);
                }
            }

            var a21  = new Vector2D(0, -10);
            var a22  = new Vector2D(0, 10);
            var seg2 = new LineSegment2D(a21, a22);

            for (int y = -20; y < 20; y++)
            {
                var p = new Vector2D(10, y);

                var dist2 = seg2.DistanceToPoint(p);
                Assert.AreEqual(10, dist2);

                Vector2D projPoint;

                var res = seg2.ProjectPointToLine(p, out projPoint);


                if (y >= a21.Y && y <= a22.Y)
                {
                    Assert.IsTrue(res);
                    var dist = projPoint.Distance(p);
                    Assert.AreEqual(dist2, dist, "dist2 = " + dist2 + " dist = " + dist);
                    var contains = seg2.Bounds.Contains(projPoint);
                    Assert.IsTrue(contains);
                }
                else
                {
                    Assert.IsFalse(res);
                    var contains = seg2.Bounds.Contains(projPoint);
                    Assert.IsFalse(contains);
                }
            }



            //for (int y = -20; y < 20; y++)
            //{

            //}
        }