예제 #1
0
    /**一条折线*/
    private bool oneCorner(LPoint a, LPoint b)
    {
        pointList.Clear();
        LPoint c = new LPoint(b.x, a.y);
        LPoint d = new LPoint(a.x, b.y);

        //判断C点是否有元素
        if (itemList[c.x][c.y].hasItem == 0)
        {
            bool path1 = horizon(b, c) && vertical(a, c);
            if (path1)
            {
                pointList.Add(a);
                pointList.Add(c);
                pointList.Add(b);
            }
            return(path1);
        }
        //判断D点是否有元素
        if (itemList[d.x][d.y].hasItem == 0)
        {
            bool path2 = horizon(a, d) && vertical(b, d);
            if (path2)
            {
                pointList.Add(a);
                pointList.Add(d);
                pointList.Add(b);
            }
            return(path2);
        }
        else
        {
            return(false);
        }
    }
예제 #2
0
        public Node GetNode(LPoint iPos)
        {
            Node retVal = null;

            m_nodes.TryGetValue(iPos, out retVal);
            return(retVal);
        }
예제 #3
0
 public Node SetNode(LPoint iPos, bool?iWalkable = null)
 {
     if (iWalkable.HasValue)
     {
         if (iWalkable.Value == true)
         {
             Node retVal = null;
             if (m_nodes.TryGetValue(iPos, out retVal))
             {
                 return(retVal);
             }
             Node newNode = new Node(iPos.x, iPos.y, iWalkable);
             m_nodes.Add(iPos, newNode);
             return(newNode);
         }
         else
         {
             removeNode(iPos);
         }
     }
     else
     {
         Node newNode = new Node(iPos.x, iPos.y, true);
         m_nodes.Add(iPos, newNode);
         return(newNode);
     }
     return(null);
 }
예제 #4
0
        public override bool SetWalkableAt(int iX, int iY, bool iWalkable)
        {
            LPoint pos = new LPoint(iX, iY);

            m_nodePool.SetNode(pos, iWalkable);
            if (iWalkable)
            {
                if (iX < m_gridRect.minX || m_notSet)
                {
                    m_gridRect.minX = iX;
                }
                if (iX > m_gridRect.maxX || m_notSet)
                {
                    m_gridRect.maxX = iX;
                }
                if (iY < m_gridRect.minY || m_notSet)
                {
                    m_gridRect.minY = iY;
                }
                if (iY > m_gridRect.maxY || m_notSet)
                {
                    m_gridRect.maxY = iY;
                }
                m_notSet = false;
            }
            else
            {
                if (iX == m_gridRect.minX || iX == m_gridRect.maxX || iY == m_gridRect.minY || iY == m_gridRect.maxY)
                {
                    m_notSet = true;
                }
            }
            return(true);
        }
예제 #5
0
 protected void removeNode(LPoint iPos)
 {
     if (m_nodes.ContainsKey(iPos))
     {
         m_nodes.Remove(iPos);
     }
 }
예제 #6
0
        public static List <LPoint> FindAngularSeamByRegions(List <LPoint> data, int countOfRegions = 10)
        {
            LPoint result = new LPoint()
            {
                X = 0, Z = 0
            };
            List <LPoint> tempResult = new List <LPoint>();

            int pointsInRegion = data.Count / countOfRegions;

            for (int t = 0; t < countOfRegions; t++)
            {
                double min       = Double.MaxValue;
                LPoint tempPoint = new LPoint();
                for (int i = t * pointsInRegion; i < (t + 1) * pointsInRegion; i++)
                {
                    if (data[i].Z < min)
                    {
                        min       = data[i].Z;
                        tempPoint = data[i];
                    }
                }
                tempResult.Add(tempPoint);
            }
            result = tempResult[5];

            return(tempResult);
        }
예제 #7
0
        public static List <LPoint> AveragingVertical(List <LPoint> data, double _verticalStep = 1, double _horizontalStep = 100, int _pointsInStep = 2)
        {
            List <LPoint> res       = data;
            int           current   = 0;
            int           dataCount = data.Count;

            while (current + _pointsInStep < dataCount)
            {
                if (Math.Abs(data[current].Z - data[current + _pointsInStep].Z) <= _verticalStep && Math.Abs(data[current].X - data[current + _pointsInStep].X) <= _horizontalStep)
                {
                    double tempZ = (data[current].Z + data[current + _pointsInStep].Z) / 2;
                    for (int i = current + 1; i < current + _pointsInStep; i++)
                    {
                        data[i] = new LPoint()
                        {
                            Z = tempZ,
                            X = data[i].X
                        };
                    }
                }
                current += _pointsInStep - 1;
                //current++;
            }
            return(res);
        }
예제 #8
0
        public LPoint Point_X(LPoint a1, LPoint a2, LPoint a3, LPoint a4, double TangDiff = 0.7)
        {
            LPoint res;
            double x1 = a1.X;
            double y1 = a1.Z;
            double x2 = a2.X;
            double y2 = a2.Z;
            double x3 = a3.X;
            double y3 = a3.Z;
            double x4 = a4.X;
            double y4 = a4.Z;

            double x = ((x1 * y2 - x2 * y1) * (x4 - x3) - (x3 * y4 - x4 * y3) * (x2 - x1)) / ((y1 - y2) * (x4 - x3) - (y3 - y4) * (x2 - x1));
            double y = ((y3 - y4) * x - (x3 * y4 - x4 * y3)) / (x4 - x3);

            res = new LPoint(-x, y);
            double k1 = (x2 - x1) / (y2 - y1);
            double k2 = (x4 - x3) / (y4 - y3);

            if (Math.Abs(k2 - k1) < TangDiff)
            {
                return(new LPoint(0, 0));
            }
            res = new LPoint(-x, y);
            //Console.WriteLine($"k1 = {k1}  ||  k2 = {k2}");
            return(res);
        }
예제 #9
0
        public override bool Collision(LPoint pt)
        {
            if (Points.Count < 2)
            {
                return(base.Collision(pt));
            }
            LPoint    p1              = Points[0];
            LPoint    p2              = Points[1];
            float     dx              = p2.X - p1.X;
            float     dy              = p2.Y - p1.Y;
            float     angle           = (float)Math.Atan2(dy, dx);
            float     distance        = (float)Math.Sqrt(dx * dx + dy * dy);
            Matrix3x3 normalizeMatrix = Matrix3x3.Translation(-p1.X, -p1.Y);

            normalizeMatrix.TransformRotate(angle);
            normalizeMatrix.TransformScale(1 / distance);

            float thickness = Points[0].Rad * 2;
            float ptx = pt.X, pty = pt.Y;

            normalizeMatrix.Transform(ref ptx, ref pty);
            if (ptx < 0 || ptx > 1)
            {
                return(false);
            }
            if (pty > thickness / distance || pty < -thickness / distance)
            {
                return(false);
            }
            return(true);
        }
예제 #10
0
        public override void Reset()
        {
            int rectCount = (m_gridRect.maxX - m_gridRect.minX) * (m_gridRect.maxY - m_gridRect.minY);

            if (m_nodePool.Nodes.Count > rectCount)
            {
                LPoint travPos = new LPoint(0, 0);
                for (int xTrav = m_gridRect.minX; xTrav <= m_gridRect.maxX; xTrav++)
                {
                    travPos.x = xTrav;
                    for (int yTrav = m_gridRect.minY; yTrav <= m_gridRect.maxY; yTrav++)
                    {
                        travPos.y = yTrav;
                        Node curNode = m_nodePool.GetNode(travPos);
                        if (curNode != null)
                        {
                            curNode.Reset();
                        }
                    }
                }
            }
            else
            {
                foreach (KeyValuePair <LPoint, Node> keyValue in m_nodePool.Nodes)
                {
                    keyValue.Value.Reset();
                }
            }
        }
예제 #11
0
        public static LPoint Type3_1point(List <LPoint> data, double decrease = 0)
        {
            LPoint left = new LPoint(0, 0), right = new LPoint(0, 0);

            (left, right) = Type3_2point(data);

            return(new LPoint((left.X + right.X) / 2, (left.Z + right.Z) / 2 - decrease));
        }
예제 #12
0
 public override Node GetNodeAt(LPoint iPos)
 {
     if (!IsInside(iPos))
     {
         return(null);
     }
     return(m_nodePool.GetNode(iPos));
 }
예제 #13
0
 public override Node GetNodeAt(LPoint iPos)
 {
     if (m_nodes.ContainsKey(iPos))
     {
         return(m_nodes[iPos]);
     }
     return(null);
 }
예제 #14
0
파일: Arc.cs 프로젝트: 2max968/Kritzelv2
        public override bool Collision(LPoint pt)
        {
            float dist = pt.Dist(Points[0]);
            float rad  = Points[0].Dist(Points[1]);

            return(dist > rad - Points[0].Rad &&
                   dist < rad + Points[0].Rad);
        }
예제 #15
0
 public override bool IsWalkableAt(LPoint iPos)
 {
     if (!IsInside(iPos))
     {
         return(false);
     }
     return(m_nodePool.Nodes.ContainsKey(iPos));
 }
예제 #16
0
        public static LPoint FindOnePoint(List <LPoint> data)
        {
            LPoint result = new LPoint()
            {
                X = 0, Z = 0
            };

            //TODO
            return(result);
        }
예제 #17
0
파일: Arc.cs 프로젝트: 2max968/Kritzelv2
 public override void Render(Renderer.BaseRenderer g, float quality = 1, int start = 0, bool simple = false)
 {
     if (Points.Count > 1)
     {
         LPoint     center = Points[0];
         float      rad    = center.Dist(Points[1]);
         RectangleF r      = new RectangleF(center.X - rad, center.Y - rad, rad * 2, rad * 2);
         g.DrawEllipse(Brush, Points[0].Rad * 2, r);
     }
 }
예제 #18
0
        public override bool SetWalkableAt(int iX, int iY, bool iWalkable)
        {
            if (!IsInside(iX, iY))
            {
                return(false);
            }
            LPoint pos = new LPoint(iX, iY);

            m_nodePool.SetNode(pos, iWalkable);
            return(true);
        }
예제 #19
0
        public static (LPoint left, LPoint right) Type3_2point(List <LPoint> data)
        {
            LPoint left = new LPoint(0, 0), right = new LPoint(0, 0);
            Dictionary <int, double> diffs = new Dictionary <int, double>();

            for (int i = 0; i < data.Count - 1; i++)
            {
                diffs.Add(i, calculate_ratio(data[i], data[i + 1]));
            }

            //int count = (int)(data.Count * percent);
            var tempResult = diffs.OrderByDescending(pair => pair.Value).Take(2).ToDictionary(pair => pair.Key, pair => pair.Value);

            List <LPoint> result           = new List <LPoint>();

            foreach (var item in tempResult)
            {
                if (data[item.Key + 1].Z > data[item.Key].Z)
                {
                    result.Add(data[item.Key + 1]);
                }
                else
                {
                    result.Add(data[item.Key]);
                }
            }

            if (tempResult.Count > 1)
            {
                if (result[0].X < result[1].X)
                {
                    left  = result[0];
                    right = result[1];
                }
                else
                {
                    left  = result[1];
                    right = result[0];
                }
            }



            return(left, right);

            double calculate_ratio(LPoint p1, LPoint p2)
            {
                double xDiff = Math.Abs(p1.X - p2.X);
                double zDiff = Math.Abs(p1.Z - p2.Z);

                return(zDiff / xDiff);
            }
        }
예제 #20
0
        public static LPoint Type1_1point(List <LPoint> data, double lifting = 0)
        {
            LPoint result = new LPoint()
            {
                X = 0, Z = 0
            };

            if (data.Count != 0)
            {
                result = data.OrderBy(item => item.Z).ToList()[0];
            }
            return(new LPoint(result.X, result.Z + lifting));
        }
예제 #21
0
        private static double distanceBetweenTwoPoints(LPoint p1, LPoint p2)
        {
            double result = 0;
            double x1     = p1.X;
            double y1     = p1.Z;
            double x2     = p2.X;
            double y2     = p2.Z;

            result = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
            result = Math.Sqrt(result);

            return(result);
        }
예제 #22
0
        public double DistanceBetweenPoint(LPoint p1, LPoint p2)
        {
            double result = 0;
            double x1     = p1.X;
            double y1     = p1.Z;
            double x2     = p2.X;
            double y2     = p2.Z;


            result = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

            return(result);
        }
예제 #23
0
 public override bool Equals(object obj)
 {
     if (obj == null)
     {
         return(false);
     }
     if (obj is LPoint)
     {
         LPoint a = (LPoint)obj;
         return(x == a.x && y == a.y);
     }
     return(false);
 }
예제 #24
0
 public override void AddPoint(float x, float y, float pressure)
 {
     if(Points.Count == 0)
     {
         startPoint = new LPoint(x, y, 1);
     }
     else
     {
         Points[0].X = (startPoint.X + x) / 2;
         Points[0].Y = (startPoint.Y + y) / 2;
     }
     base.AddPoint(x, y, pressure);
 }
예제 #25
0
        public static LPoint FindAngularSeamSimple(List <LPoint> data)
        {
            LPoint result = new LPoint()
            {
                X = 0, Z = 0
            };

            if (data.Count != 0)
            {
                result = data.OrderBy(item => item.Z).ToList()[0];
            }
            return(result);
        }
예제 #26
0
        public static (LPoint left, LPoint right) FindTwoPoints(List <LPoint> data)
        {
            LPoint Lres = new LPoint()
            {
                X = 0, Z = 0
            };
            LPoint Rres = new LPoint()
            {
                X = 0, Z = 0
            };

            //TODO
            return(Lres, Rres);
        }
예제 #27
0
        public static List <LPoint> AveragingVerticalPro(List <LPoint> data, double _verticalStep = 1, double _horizontalStep = 100,
                                                         int _pointsInStep = 2, bool _everyPoint = false)
        {
            List <LPoint> res       = data;
            int           current   = 0;
            int           dataCount = data.Count;

            while (current + _pointsInStep < dataCount)
            {
                if (Math.Abs(data[current].Z - data[current + _pointsInStep].Z) <= _verticalStep && Math.Abs(data[current].X - data[current + _pointsInStep].X) <= _horizontalStep)
                {
                    for (int i = current + 1; i < current + _pointsInStep; i++)
                    {
                        data[i] = new LPoint()
                        {
                            Z = _calcTempZ(data[current], data[current + _pointsInStep], data[i].X),
                            X = data[i].X
                        };
                    }
                }
                if (_everyPoint)
                {
                    current++;
                }
                else
                {
                    current += _pointsInStep - 1;
                }
            }
            return(res);

            double _calcTempZ(LPoint p1, LPoint p2, double difX)
            {
                double x1 = Math.Min(p1.X, p2.X);
                double x2 = Math.Max(p1.X, p2.X);
                double x  = difX;


                double z1 = p1.X == x1 ? p1.Z : p2.Z;
                double z2 = p1.X == x2 ? p1.Z : p2.Z;

                double zRes = (((x - x1) * (z2 - z1)) / (x2 - x1)) + z1;


                return(zRes);
            }
        }
예제 #28
0
        public override bool SetWalkableAt(int iX, int iY, bool iWalkable)
        {
            LPoint pos = new LPoint(iX, iY);

            if (iWalkable)
            {
                if (m_nodes.ContainsKey(pos))
                {
                    // this.m_nodes[pos].walkable = iWalkable;
                    return(true);
                }
                else
                {
                    if (iX < m_gridRect.minX || m_notSet)
                    {
                        m_gridRect.minX = iX;
                    }
                    if (iX > m_gridRect.maxX || m_notSet)
                    {
                        m_gridRect.maxX = iX;
                    }
                    if (iY < m_gridRect.minY || m_notSet)
                    {
                        m_gridRect.minY = iY;
                    }
                    if (iY > m_gridRect.maxY || m_notSet)
                    {
                        m_gridRect.maxY = iY;
                    }
                    m_nodes.Add(new LPoint(pos.x, pos.y), new Node(pos.x, pos.y, iWalkable));
                    m_notSet = false;
                }
            }
            else
            {
                if (m_nodes.ContainsKey(pos))
                {
                    m_nodes.Remove(pos);
                    if (iX == m_gridRect.minX || iX == m_gridRect.maxX || iY == m_gridRect.minY || iY == m_gridRect.maxY)
                    {
                        m_notSet = true;
                    }
                }
            }
            return(true);
        }
예제 #29
0
        public static double pointOnLine(LPoint left, LPoint right, LPoint cur)
        {
            double x  = cur.X;
            double y  = cur.Z;
            double x1 = left.X;
            double y1 = left.Z;
            double x2 = right.X;
            double y2 = right.Z;



            double tx = (x - x1) * (y2 - y1);
            double ty = (y - y1) * (x2 - x1);

            // Console.WriteLine(tx - ty);
            return(Math.Abs(tx - ty));
        }
예제 #30
0
    /**纵向*/
    private bool vertical(LPoint a, LPoint b)
    {
        if (a.x == b.x && a.y == b.y)
        {
            return(false);
        }
        int y_start = a.x < b.x ? a.x : b.x;
        int y_end   = a.x < b.x ? b.x : a.x;

        for (int i = y_start + 1; i < y_end; i++)
        {
            if (itemList[i][a.y].hasItem == 1)
            {
                return(false);
            }
        }
        return(true);
    }