示例#1
0
        public LDLine toLine(LDPointList form)
        {
            Debug.Assert(form.length() > m_index1);
            Debug.Assert(form.length() > m_index2);

            return(new LDLine(form.at(m_index1), form.at(m_index2)));
        }
示例#2
0
        public void replacePointList(LDPointList form)
        {
            Debug.Assert(m_points.length() == form.length());

            for (int i = 0; i < form.length(); ++i)
            {
                m_points.replace(i, form[i]);
            }
        }
示例#3
0
        public LDPolygon toPolygon(LDPointList points)
        {
            Debug.Assert((points.length() > m_index1));
            Debug.Assert(points.length() > m_index2);
            Debug.Assert(points.length() > m_index3);

            LDPolygon v = new LDPolygon();

            v.Add(new LDPoint(points.at(m_index1)));
            v.Add(new LDPoint(points.at(m_index2)));
            v.Add(new LDPoint(points.at(m_index3)));
            return(v);
        }
示例#4
0
 public static bool fuzzyCompare(LDPointList a, LDPointList b, float fuzz)
 {
     if (a.length() != b.length())
     {
         return(false);
     }
     for (int i = 0; i < a.length(); ++i)
     {
         if (Math.Abs(a[i].x() - b[i].x()) > fuzz)
         {
             return(false);
         }
         if (Math.Abs(a[i].y() - b[i].y()) > fuzz)
         {
             return(false);
         }
     }
     return(true);
 }
示例#5
0
        public void setClockWise(LDPointList form, ClockWise clockWise)
        {
            Debug.Assert(form.length() > m_index1);
            Debug.Assert(form.length() > m_index2);
            Debug.Assert(form.length() > m_index3);

            LDPoint v0 = form.at(m_index1);
            LDPoint v1 = form.at(m_index2);
            LDPoint v2 = form.at(m_index3);

            //行列式で時計回りか判定
            //行列式の計算。 QMatrix3x3にはないので手動で作成。

            double[,] m = new double[3, 3] {
                { v0.x(), v0.y(), 1 },
                { v1.x(), v1.y(), 1 },
                { v2.x(), v2.y(), 1 }
            };

            double determinant = m[0, 0] * m[1, 1] * m[2, 2]
                                 + m[0, 1] * m[1, 2] * m[2, 0]
                                 + m[0, 2] * m[1, 0] * m[2, 1]
                                 - m[0, 2] * m[1, 1] * m[2, 0]
                                 - m[0, 0] * m[1, 2] * m[2, 1]
                                 - m[0, 1] * m[1, 0] * m[2, 2];
            ClockWise current;

            if (determinant < 0) //CW
            {
                current = ClockWise.CW;
            }
            else            //CCWまたは3点が一直線上など
            {
                current = ClockWise.CCW;
            }

            if (clockWise != current) //設定した順番と異なる場合 Indexを入れ替える
            {
                var p = m_index1;
                m_index1 = m_index2;
                m_index2 = p;
            }
        }
示例#6
0
        public LDPointList inverseTransform(LDPointList points, bool clip = false)
        {
            LDPointList result = new LDPointList();
            int         length = points.length();

            for (int i = 0; i < length; i++)
            {
                result.Add(inverseTransform(points[i], clip));
            }
            return(result);
        }
示例#7
0
        public void setForm(LDPointList value)
        {
            Debug.Assert(getPointCount() == value.length());
            for (int i = 0; i < getRow() + 1; ++i)
            {
                for (int j = 0; j < getColumn() + 1; ++j)
                {
                    m_gridPoints[i][j] = value[i * (getColumn() + 1) + j];
                }
            }

            clearBoundsCache();
        }
示例#8
0
        //外周の頂点インデックスを取得。yが一番小さい点から時計周りで取得。
        public List <int> getOutlinePointIndices(LDPointList points)
        {
            List <int> result = new List <int>();

            // 外周をたどる。始点に戻ったら終了。
            int startIndex = math.PointUtil.findMinYPointIndex(points);

            Debug.Assert(startIndex >= 0);

            result.Add(startIndex);

            int lastIndex    = -1;
            int currentIndex = startIndex;

            for (int i = 0; i < points.length(); ++i)
            {
                //現在の頂点と接続される点一覧を取得し、その中から進行方向に対してもっとも左側に位置するものを取得
                List <int> related = getRelatedPointIndices(currentIndex);

                LDPoint lastPoint;
                LDPoint currentPoint = points[currentIndex];
                if (lastIndex == -1)
                {
                    lastPoint = currentPoint - new LDPoint(0, 1);
                }
                else
                {
                    lastPoint = points[lastIndex];
                }


                int    nextIndex = -1;
                double minAngle  = 360;
                foreach (var targetIndex in related)
                {
                    LDPoint targetPoint = points[targetIndex];
                    if (targetIndex == lastIndex)
                    {
                        continue;
                    }
                    LDVector2 v1 = new LDVector2(lastPoint - currentPoint);
                    LDVector2 v2 = new LDVector2(targetPoint - currentPoint);

                    double angle = LDMathUtil.getAngle(v2, v1);
                    if (angle < minAngle)
                    {
                        minAngle  = angle;
                        nextIndex = targetIndex;
                    }
                }

                if (nextIndex == startIndex)
                {
                    //一周した
                    break;
                }
                result.Add(nextIndex);

                lastIndex    = currentIndex;
                currentIndex = nextIndex;
            }

            return(result);
        }