Beispiel #1
0
        public bool Intersects(Line2D line, out float t0, out float t1, out float t2, out float t3)
        {
            List <LineSegment2D> segs = LineSegment2D.FromBounds(this);

            t0 = t1 = t2 = t3 = 0f;


            float unused;
            // horizontal
            float h0, h1;
            bool  intersects = segs[0].line.Intersects(line, out unused, out h0);

            if (!intersects)
            {
                return(false);
            }
            intersects = segs[1].line.Intersects(line, out unused, out h1);
            if (!intersects)
            {
                return(false);
            }

            // vertical
            float v0, v1;

            intersects = segs[2].line.Intersects(line, out unused, out v0);
            if (!intersects)
            {
                return(false);
            }
            intersects = segs[3].line.Intersects(line, out unused, out v1);
            if (!intersects)
            {
                return(false);
            }

            float hh0 = Mathf.Min(h0, h1);
            float hh1 = Mathf.Max(h0, h1);
            float vv0 = Mathf.Min(v0, v1);
            float vv1 = Mathf.Max(v0, v1);

            if (MUtils.LessOrEqual(hh0, vv0))
            {
                // hit h0 first
                t0 = hh0;
                t1 = vv0;
                t2 = Mathf.Min(hh1, vv1);
                t3 = Mathf.Max(hh1, vv1);
                return(MUtils.LessOrEqual(vv0, hh1));
            }
            else
            {
                // hit v0 first
                t0 = vv0;
                t1 = hh0;
                t2 = Mathf.Min(vv1, hh1);
                t3 = Mathf.Max(vv1, hh1);
                return(MUtils.LessOrEqual(hh0, vv1));
            }
        }
 public bool PointOnSegment(float t)
 {
     return(MUtils.LessOrEqual(d0, t) && MUtils.LessOrEqual(t, d1));
 }