doFill(UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2, bool)

Here are the examples of the csharp api doFill(UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2, UnityEngine.Vector2, bool) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : IsohedralTiling.cs
License : MIT License
Project Creator : IxxyXR

public IEnumerable<IEnumerable<IEnumerable<Thing>>> fillRegionQuad(Vector2 A, Vector2 B, Vector2 C, Vector2 D)
    {
        
        Vector2 bc(double[] M, Vector2 p)
        {
            return new Vector2(
                (float)(M[0] * p.x + M[1] * p.y),
                (float)(M[2] * p.x + M[3] * p.y)
            );
        };

        Vector2 sampleAtHeight(Vector2 P, Vector2 Q, float y)
        {
            float t = (y - P.y) / (Q.y - P.y);
            return new Vector2((1.0f - t) * P.x + t * Q.x, y);
        }

        IEnumerable<Thing> doFill(Vector2 AA, Vector2 BB, Vector2 CC, Vector2 DD, bool do_top)
        {
            float x1 = AA.x;
            float dx1 = (DD.x - AA.x) / (DD.y - AA.y);
            float x2 = BB.x;
            float dx2 = (CC.x - BB.x) / (CC.y - BB.y);
            float ymin = AA.y;
            float ymax = CC.y;

            if (do_top)
            {
                ymax = ymax + 1.0f;
            }

            double y = Math.Floor(ymin);
            while (y < ymax)
            {
                float yi = Mathf.Floor((float)y);
                var xx = Math.Floor(x1);
                while (xx < x2 + 1e-7)
                {
                    
                    float xi = Mathf.Floor((float)xx);

                    for (int asp = 0; asp < ttd.num_aspects; ++asp)
                    {
                        double[] M = new double[aspects[asp].Length];
                        aspects[asp].CopyTo(M, 0);
                        M[2] += xi * t1.x + yi * t2.x;
                        M[5] += xi * t1.y + yi * t2.y;

                        yield return new Thing(
                            T: M.Select(x=>(float)x).ToArray(),
                            t1: xi,
                            t2: yi,
                            aspect: asp
                        );
                    }

                    xx += 1.0;
                }
                x1 += dx1;
                x2 += dx2;
                y += 1.0;
            }
        }

        IEnumerable<IEnumerable<Thing>> fillFixX(Vector2 AA, Vector2 BB, Vector2 CC, Vector2 DD, bool do_top)
        {
            if (AA.x > BB.x)
            {
                yield return doFill(BB, AA, DD, CC, do_top);
            }
            else
            {
                yield return doFill(AA, BB, CC, DD, do_top);
            }
        }

        IEnumerable<IEnumerable<Thing>> fillFixY(Vector2 AA, Vector2 BB, Vector2 CC, Vector2 DD, bool do_top)
        {
            if (AA.y > CC.y)
            {
                yield return doFill(CC, DD, AA, BB, do_top);
            }
            else
            {
                yield return doFill(AA, BB, CC, DD, do_top);
            }
        }

        var det = 1.0 / (t1.x * t2.y - t2.x * t1.y);
        var Mbc = new[]{t2.y * det, -t2.x * det, -t1.y * det, t1.x * det};
        var pts = new[]{bc(Mbc, A), bc(Mbc, B), bc(Mbc, C), bc(Mbc, D)};

        if (det < 0.0)
        {
            var tmp = pts[1];
            pts[1] = pts[3];
            pts[3] = tmp;
        }

        if (Math.Abs(pts[0].y - pts[1].y) < 1e-7)
        {
            yield return fillFixY(pts[0], pts[1], pts[2], pts[3], true);
        }
        else if (Math.Abs(pts[1].y - pts[2].y) < 1e-7)
        {
            yield return fillFixY(pts[1], pts[2], pts[3], pts[0], true);
        }
        else
        {
            int lowest = 0;
            for (int idx = 1; idx < 4; ++idx) {
                if (pts[idx].y < pts[lowest].y) {
                    lowest = idx;
                }
            }

            var bottom = pts[lowest];
            var left = pts[(lowest + 1) % 4];
            var top = pts[(lowest + 2) % 4];
            var right = pts[(lowest + 3) % 4];

            if (left.x > right.x)
            {
                var tmp = left;
                left = right;
                right = tmp;
            }

            if (left.y < right.y)
            {
                var r1 = sampleAtHeight(bottom, right, left.y);
                var l2 = sampleAtHeight(left, top, right.y);
                yield return fillFixX(bottom, bottom, r1, left, false);
                yield return fillFixX(left, r1, right, l2, false);
                yield return fillFixX(l2, right, top, top, true);
            }
            else
            {
                var l1 = sampleAtHeight(bottom, left, right.y);
                var r2 = sampleAtHeight(right, top, left.y);
                yield return fillFixX(bottom, bottom, right, l1, false);
                yield return fillFixX(l1, right, r2, left, false);
                yield return fillFixX(left, r2, top, top, true);
            }
        }
    }