Пример #1
0
        // 检查某坐标是否在多边形内部
        public bool Include(Vector2 pos)
        {
            if (!MBR.Include(pos))
            {
                return(false);
            }
            var checker = new LineSegment((GeomPoint)pos, new GeomPoint(MBR.XMax + 10, pos.Y));
            int crosses = 0;

            foreach (var seg in IterSegments(true))
            {
                var tmp = LineSegment.CheckCross(checker, seg);
                if (tmp == null) // 平行或共线
                {
                    if (seg.Item1.Y != pos.Y)
                    {
                        continue;
                    }
                    if (seg.Item1.X < pos.X != seg.Item2.X < pos.X)
                    {
                        crosses++;                                             // 重合线横跨待检查坐标两侧
                    }
                }
                if (0 < tmp.Item1 && tmp.Item1 < 1 && 0 <= tmp.Item2 && tmp.Item2 < 1)
                {
                    crosses++;                                                                    // Item2检查一端
                }
            }

            return(crosses % 2 == 1); // 射线交点为奇数
        }
Пример #2
0
        private static MBR getMBR(IEnumerable <GeoPoint> points)
        {
            MBR mbr = MBR.EMPTY;

            foreach (var point in points)
            {
                mbr.Include(point);
            }
            return(mbr);
        }
Пример #3
0
        private MBR getMBR(Trajectory trj)
        {
            MBR mbr   = MBR.EMPTY;
            int count = trj.Count;

            foreach (MotionVector mv in trj)
            {
                mbr.Include(mv.point);
            }
            return(mbr);
        }
Пример #4
0
        private void buildIndex()
        {
            //insert edges into the grid
            int count = trj.Count;

            for (int i = 0; i < count - 1; i++)
            {
                MBR mbr2 = MBR.EMPTY;
                mbr2.Include(trj[i].point);
                mbr2.Include(trj[i + 1].point);
                List <int> cids = getCells(mbr2);
                foreach (int cid in cids)
                {
                    List <int> list = null;
                    bool       got  = dict.TryGetValue(cid, out list);
                    if (!got)
                    {
                        list = new List <int>();
                        dict.Add(cid, list);
                    }
                    list.Add(i);
                }
            }
        }
Пример #5
0
        private void buildIndex()
        {
            //insert edges into the grid
            int threadCount = 4, partCount = (int)Math.Ceiling(trjs.Count * 1.0 / threadCount);

            Dictionary <int, List <long> >[] dicts = new Dictionary <int, List <long> > [threadCount];
            for (int i = 0; i < threadCount; ++i)
            {
                dicts[i] = new Dictionary <int, List <long> >();
            }
            ParallelOptions op = new ParallelOptions();

            op.MaxDegreeOfParallelism = threadCount;
            var tmpTrjs  = trjs.ToList();
            int trjCount = trjs.Count;

            //foreach (var item in trjs)
            Parallel.For(0, threadCount, j =>
            {
                for (int k = j * partCount; k < Math.Min((j + 1) * partCount, trjCount); ++k)
                {
                    var item    = tmpTrjs[k];
                    long moid   = item.Key;
                    var trj     = item.Value;
                    int count   = trj.Count;
                    var curDict = dicts[j];
                    for (int i = 0; i < count - 1; i++)
                    {
                        MBR mbr2 = MBR.EMPTY;
                        mbr2.Include(trj[i].point);
                        mbr2.Include(trj[i + 1].point);
                        List <int> cids = getCells(mbr2);
                        foreach (int cid in cids)
                        {
                            List <long> list = null;
                            bool got         = curDict.TryGetValue(cid, out list);
                            if (!got)
                            {
                                list = new List <long>();
                                curDict.Add(cid, list);
                            }
                            list.Add(moid << 16 | (uint)i);
                        }
                    }
                }
            });
            // merge
            trjDict = dicts[0];
            for (int i = 1; i < threadCount; ++i)
            {
                foreach (var item in dicts[i])
                {
                    List <long> list = null;
                    if (!trjDict.TryGetValue(item.Key, out list))
                    {
                        trjDict[item.Key] = new List <long>(item.Value);
                    }
                    else
                    {
                        list.AddRange(item.Value);
                    }
                }
            }
        }