private static void ShiftPoints(float irregularity)
        {
            for (var i = 0; i < pointCount; i++)
            {
                var point  = points[i];
                var delta  = Random.insideUnitCircle.normalized * FindMaxMovement(point.X, point.Y) * irregularity;
                var deltaX = Mathf.RoundToInt(delta.x);
                var deltaY = Mathf.RoundToInt(delta.y);

                if (point.X <= xMin || point.X >= xMax)
                {
                    deltaX = 0;
                }
                if (point.Y <= yMin || point.Y >= yMax)
                {
                    deltaY = 0;
                }

                if (deltaX != 0 || deltaY != 0)
                {
                    var newPoint = new DestroyableVector2Operator(point.X + deltaX, point.Y + deltaY);

                    MovePoints(point, newPoint);

                    points[i] = newPoint;
                }
            }
        }
 private static void TryMovePoint(ref DestroyableVector2Operator point, DestroyableVector2Operator oldPoint, DestroyableVector2Operator newPoint)
 {
     if (point.X == oldPoint.X && point.Y == oldPoint.Y)
     {
         point.X = newPoint.X;
         point.Y = newPoint.Y;
     }
 }
        private static void MovePoints(DestroyableVector2Operator oldPoint, DestroyableVector2Operator newPoint)
        {
            for (var i = 0; i < quadCount; i++)
            {
                var quad = quads[i];

                TryMovePoint(ref quad.BL, oldPoint, newPoint);
                TryMovePoint(ref quad.BR, oldPoint, newPoint);
                TryMovePoint(ref quad.TL, oldPoint, newPoint);
                TryMovePoint(ref quad.TR, oldPoint, newPoint);

                quads[i] = quad;
            }
        }
Example #4
0
        public void AddTriangle(DestroyableVector2Operator a, DestroyableVector2Operator b, DestroyableVector2Operator c)
        {
            if (a.Y != b.Y || a.Y != c.Y)
            {
                //var z = (a.V + b.V + c.V) / 3.0f;
                //var z1 = Vector3.MoveTowards(a.V, z, 1.0f);
                //var z2 = Vector3.MoveTowards(b.V, z, 1.0f);
                //var z3 = Vector3.MoveTowards(c.V, z, 1.0f);

                //Debug.DrawLine(z1, z2, Color.red, 10.0f);
                //Debug.DrawLine(z2, z3, Color.red, 10.0f);
                //Debug.DrawLine(z3, z1, Color.red, 10.0f);


                if (b.Y > a.Y)
                {
                    DestroyableHelper.Swap(ref a, ref b);
                }
                if (c.Y > a.Y)
                {
                    DestroyableHelper.Swap(ref c, ref a);
                }
                if (c.Y > b.Y)
                {
                    DestroyableHelper.Swap(ref b, ref c);
                }

                var fth = a.Y - c.Y;
                var tth = a.Y - b.Y;
                var bth = b.Y - c.Y;

                var inx = c.X + (a.X - c.X) * DestroyableHelper.Divide(bth, fth);
                var d   = new DestroyableVector2Operator((int)inx, b.Y);

                var abs = DestroyableHelper.Divide(a.X - b.X, tth);
                var ads = DestroyableHelper.Divide(a.X - d.X, tth);

                AddTriangle(b.X, d.X, abs, ads, b.Y, 1, tth);

                var cbs = DestroyableHelper.Divide(c.X - b.X, bth);
                var cds = DestroyableHelper.Divide(c.X - d.X, bth);

                AddTriangle(b.X, d.X, cbs, cds, b.Y, -1, bth);
            }
        }
        private static void TryAddPoint(DestroyableVector2Operator newPoint)
        {
            for (var i = 0; i < pointCount; i++)
            {
                var point = points[i];

                if (point.X == newPoint.X && point.Y == newPoint.Y)
                {
                    return;
                }
            }

            if (points.Count > pointCount)
            {
                points[pointCount] = newPoint;
            }
            else
            {
                points.Add(newPoint);
            }

            pointCount += 1;
        }