Exemplo n.º 1
0
        /*
         * public void serializeTest()
         * {
         *  const char* name = "lineList";
         *  QSharedPointer<LDIndexLineList> src(new LDIndexLineList);
         *  src->push_back(LDIndexLine(0, 1));
         *
         *  //シリアライズ
         *  SerializeHelper::writeBoostXml(name, src);
         *
         *  //デシリアライズ
         *  auto dst = SerializeHelper::readBoostXml<LDIndexLineList>(name);
         *
         *  QVERIFY(*(dst.data()) == *(src.data()));
         * }
         */

        public void hitTest()
        {
            LDIndexLineList lines  = new LDIndexLineList();
            LDIndexLine     line_1 = new LDIndexLine(0, 1);
            LDIndexLine     line_2 = new LDIndexLine(1, 2);
            LDIndexLine     line_3 = new LDIndexLine(2, 3);
            LDIndexLine     line_4 = new LDIndexLine(3, 0);

            lines.add(line_1);
            lines.add(line_2);
            lines.add(line_3);
            lines.add(line_4);

            LDPointList points = new LDPointList();

            points.Add(new LDPoint(0, 0));
            points.Add(new LDPoint(100, 0));
            points.Add(new LDPoint(100, 100));
            points.Add(new LDPoint(0, 100));


            TestUtil.COMPARE(lines.isHit(points, new LDPoint(0, 0), 1), true);    //頂点上
            TestUtil.COMPARE(lines.isHit(points, new LDPoint(50, 0), 1), true);   //線上
            TestUtil.COMPARE(lines.isHit(points, new LDPoint(50, 1), 3), true);   //線からちょっと離れたところ
            TestUtil.COMPARE(lines.isHit(points, new LDPoint(50, 4), 3), false);  //線から範囲外に離れたところ
            TestUtil.COMPARE(lines.isHit(points, new LDPoint(200, 0), 3), false); //線の延長戦上に離れたところ
            TestUtil.COMPARE(lines.isHit(points, new LDPoint(200, 1), 3), false); //線の延長戦上に離れたところ
        }
Exemplo n.º 2
0
        public LDIndexLineList toIndexLineList()
        {
            //NOTE: もっと効率化できる気がするが、ボトルネックになったらやる
            LDIndexLineList lineList = new LDIndexLineList();

            for (int i = 0; i < this.size(); i++)
            {
                LDTriangle tri = this.at(i);

                LDIndexLine line1 = tri.getLine1();
                if (!lineList.hasIndexLine(line1))
                {
                    lineList.Add(line1);
                }

                LDIndexLine line2 = tri.getLine2();
                if (!lineList.hasIndexLine(line2))
                {
                    lineList.Add(line2);
                }

                LDIndexLine line3 = tri.getLine3();
                if (!lineList.hasIndexLine(line3))
                {
                    lineList.Add(line3);
                }
            }
            return(lineList);
        }
Exemplo n.º 3
0
 //すべての線分から三角形を再構成
 public void update(LDIndexLineList lines)
 {
     this.Clear();
     for (int i = 0; i < lines.size(); i++)
     {
         this.AddRange(create(i, lines));
     }
 }
Exemplo n.º 4
0
        //外周の周辺で判定
        public bool isHitOutline(LDPoint pt, float hitRange)
        {
            if (!isPreHit(pt, hitRange))
            {
                return(false);
            }
            LDIndexLineList outline = getIndexOutline();

            return(outline.isHit(toForm(), pt, hitRange));
        }
Exemplo n.º 5
0
        public void getRelatedLinesTest_simple()
        {
            LDTriangleList  triangles = simpleTriangle();
            LDIndexLineList compare   = new LDIndexLineList();

            compare.Add(new LDIndexLine(0, 1));
            compare.Add(new LDIndexLine(0, 2));

            LDIndexLineList result = triangles.getRelatedLines(0);

            TestUtil.COMPARE(result, compare);
        }
Exemplo n.º 6
0
        public LDLineList getInnerLines()
        {
            LDIndexLineList lines = getInnerIndexLines();

            LDLineList result = new LDLineList();

            foreach (var line in lines)
            {
                result.Add(getLine(line));
            }
            return(result);
        }
Exemplo n.º 7
0
        //その頂点を含む線分リストを取得
        public LDIndexLineList getRelatedLines(int pointIndex)
        {
            LDIndexLineList result = new LDIndexLineList();

            foreach (var t in this)
            {
                LDIndexLineList lines = t.getRelatedLines(pointIndex);

                foreach (var line in lines)
                {
                    result.Add(line);
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        public void toIndexLineListTest_simple()
        {
            LDTriangleList triangles = simpleTriangle();

            LDIndexLineList compare = new LDIndexLineList();
            LDIndexLine     line_1  = new LDIndexLine(0, 1);
            LDIndexLine     line_2  = new LDIndexLine(1, 2);
            LDIndexLine     line_3  = new LDIndexLine(2, 0);

            compare.Add(line_1);
            compare.Add(line_2);
            compare.Add(line_3);

            LDIndexLineList result = triangles.toIndexLineList();

            TestUtil.COMPARE(result, compare);
        }
Exemplo n.º 9
0
        public void constructTest()
        {
            List <int> int_list = new List <int>();

            int_list.Add(0);
            int_list.Add(1);
            int_list.Add(2);
            int_list.Add(3);
            //	int_list.push_back(0);
            LDIndexLineList list = new LDIndexLineList(int_list);

            LDIndexLineList compare = new LDIndexLineList();

            compare.Add(new LDIndexLine(0, 1));
            compare.Add(new LDIndexLine(1, 2));
            compare.Add(new LDIndexLine(2, 3));
            compare.Add(new LDIndexLine(3, 0));
            TestUtil.COMPARE(list, compare);
        }
Exemplo n.º 10
0
        public LDIndexLineList getRelatedLines(int pointIndex)
        {
            LDIndexLineList result = new LDIndexLineList();

            LDIndexLine line1 = getLine1();
            LDIndexLine line2 = getLine2();
            LDIndexLine line3 = getLine3();

            if (line1.hasIndex(pointIndex))
            {
                result.Add(line1);
            }
            if (line2.hasIndex(pointIndex))
            {
                result.Add(line2);
            }
            if (line3.hasIndex(pointIndex))
            {
                result.Add(line3);
            }

            return(result);
        }
Exemplo n.º 11
0
        //特定の線分から隣接する三角形を作成
        private List <LDTriangle> create(int index, LDIndexLineList lines)
        {
            Debug.Assert(lines.length() > index);

            List <LDTriangle> indexs = new List <LDTriangle>();
            int i_1 = lines.at(index).getIndex1();
            int i_2 = lines.at(index).getIndex2();


            for (int i = index; ; i++)
            {
                if (i > lines.size() - 1)
                {
                    break;
                }
                if (lines.at(i).getIndex1() != i_1)
                {
                    break;
                }
                int  i_3 = lines.at(i).getIndex2();
                bool hit = false;
                for (int j = i; j < lines.size(); j++)
                {
                    if (lines.at(j).getIndex1() == i_2 && lines.at(j).getIndex2() == i_3)
                    {
                        hit = true;
                        break;
                    }
                }
                if (hit)
                {
                    LDTriangle poly = new LDTriangle(i_1, i_2, i_3);
                    indexs.Add(poly);
                }
            }
            return(indexs);
        }
Exemplo n.º 12
0
        public LDIndexLineList getInnerIndexLines()
        {
            LDIndexLineList result = new LDIndexLineList();

            for (int row = 0; row < getRowArrayLength(); ++row)
            {
                if (row == 0 || row + 1 == getRowArrayLength())
                {
                    continue;
                }
                for (int col = 0; col < getColumnArrayLength(); ++col)
                {
                    if (col == 0 || col + 1 == getColumnArrayLength())
                    {
                        continue;
                    }
                    //その点から左と上
                    result.Add(getIndexLine(row, col - 1, row, col));
                    result.Add(getIndexLine(row - 1, col, row, col));

                    if (row + 2 == getRowArrayLength())
                    {
                        //最後だけ下も追加
                        result.Add(new LDIndexLine(getPointIndex(row, col), getPointIndex(row + 1, col)));
                    }

                    if (col + 2 == getColumnArrayLength())
                    {
                        //最後だけ右も追加
                        result.Add(new LDIndexLine(getPointIndex(row, col), getPointIndex(row, col + 1)));
                    }
                }
            }

            return(result);
        }
Exemplo n.º 13
0
        public LDIndexLineList getIndexOutline()
        {
            LDIndexLineList result = new LDIndexLineList(getOutlinePointIndices());

            return(result);
        }
Exemplo n.º 14
0
 public void setLines(LDIndexLineList value)
 {
     m_lines = value;
 }