示例#1
0
文件: TLine.cs 项目: Airahc/hack_ssjj
 /// <summary>
 /// 是否与...平行
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public bool IsParallel(TLine line)
 {
     if (b == 0 && line.b == 0 ||
         b != 0 && line.b != 0 && k == line.k)
     {
         return(true);
     }
     return(false);
 }
示例#2
0
文件: TLine.cs 项目: Airahc/hack_ssjj
        public Vector2 CrossWith(TLine line)
        {
            if (IsParallel(line))
            {
                return(new Vector2(float.NaN, float.NaN));
            }
            float   d          = line.a;
            float   e          = line.b;
            float   f          = line.c;
            float   x          = (b * f - c * e) / (a * e - b * d);
            float   y          = (c * d - a * f) / (a * e - b * d);
            Vector2 crossPoint = new Vector2(x, y);

            return(crossPoint);
        }
示例#3
0
文件: TRect.cs 项目: Airahc/hack_ssjj
        /// 如果超出边界,按照Pos到Center线段与矩形边框交叉点,作为返回值
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public Vector2 LimitInside(Vector2 pos)
        {
            TLine centerToPos = new TLine(center, pos);

            if (pos.x < left)
            {
                TLine   line = new TLine(new Vector2(left, top), new Vector2(left, bottom));
                Vector2 crsp = line.CrossWith(centerToPos);
                if (crsp.y <= top && crsp.y >= bottom)
                {
                    pos.x = left;
                    pos.y = crsp.y;
                }
            }
            else if (pos.x > right)
            {
                TLine   line = new TLine(new Vector2(right, top), new Vector2(right, bottom));
                Vector2 crsp = line.CrossWith(centerToPos);
                if (crsp.y <= top && crsp.y >= bottom)
                {
                    pos.x = right;
                    pos.y = crsp.y;
                }
            }
            if (pos.y < bottom)
            {
                TLine   line = new TLine(new Vector2(left, bottom), new Vector2(right, bottom));
                Vector2 crsp = line.CrossWith(centerToPos);
                if (crsp.x <= right && crsp.x >= left)
                {
                    pos.x = crsp.x;
                    pos.y = bottom;
                }
            }
            else if (pos.y > top)
            {
                TLine   line = new TLine(new Vector2(left, top), new Vector2(right, top));
                Vector2 crsp = line.CrossWith(centerToPos);
                if (crsp.x <= right && crsp.x >= left)
                {
                    pos.x = crsp.x;
                    pos.y = top;
                }
            }
            return(pos);
        }
示例#4
0
文件: Esp.cs 项目: Airahc/hack_ssjj
 private void D_L(TLine l, Color color)
 {
     GizmosPro.DrawLine(l.from, l.to, color);
 }