/// Appends another path at the end of this one
 public Path appendPath(Path other) {
     //mPoints.insert(mPoints.end(), other.mPoints.begin(), other.mPoints.end());
     mPoints.AddRange(other.mPoints.ToArray());
     return this;
 }
        /// Converts the shape to a path, with Y=0
        //-----------------------------------------------------------------------
        //
        //ORIGINAL LINE: Path convertToPath() const
        public Path convertToPath() {
            Path p = new Path();
            //for (List<Vector2>.Enumerator it = mPoints.GetEnumerator(); it.MoveNext(); ++it)
            foreach (var it in mPoints) {
                p.addPoint(it.x, 0, it.y);
            }
            if (mClosed)
                p.close();

            return p;
        }
 public MultiPath addPath(Path path) {
     mPaths.push_back(path);
     return this;
 }
 public void buildFromSegmentSoup(std_vector<Segment3D> segList, ref std_vector<Path> @out)
 {
     //typedef std::multimap<Vector3, Vector3, Vector3Comparator> Vec3MultiMap;
     //Vec3MultiMap segs;
    std_multimap<Vector3,Vector3>segs=new std_multimap<Vector3,Vector3>(new Vector3Comparator());
    // for (std::vector<Segment3D>::const_iterator it = segList.begin(); it != segList.end(); ++it)
    foreach(var it in segList)
    {
         //segs.insert(std::pair<Vector3, Vector3 > (it->mA, it->mB));
         //segs.insert(std::pair<Vector3, Vector3 > (it->mB, it->mA));
        segs.insert(it.mA,it.mB);
        segs.insert(it.mB,it.mA);
     }
     while (!segs.empty())
     {
        Vector3 headFirst = segs.get(0).first;//segs.begin()->first;
         Vector3 headSecond = segs.get(0).second[0];//segs.begin()->second;
         Path p=new Path();
         p.addPoint(headFirst).addPoint(headSecond);
         //Vec3MultiMap::iterator firstSeg = segs.begin();
         int firstSeg_pos=segs.begin();
         Vector3 firstSeg=segs.get(0).first;
         //std::pair<Vec3MultiMap::iterator, Vec3MultiMap::iterator> correspondants2 = segs.equal_range(headSecond);
        std_pair<std_pair<Vector3,List<Vector3>>,std_pair<Vector3,List<Vector3>>>  correspondants2 = segs.equal_range(headSecond);
         //for (Vec3MultiMap::iterator it = correspondants2.first; it != correspondants2.second;)
         for(int i=correspondants2.first.second.Count-1;i>=0;i--)
         {
            // Vec3MultiMap::iterator removeIt = it++;
             Vector3 removeIt=correspondants2.first.second[i];
             //if ((removeIt->second - firstSeg->first).squaredLength() < 1e-8)
             if((removeIt-firstSeg).SquaredLength<1e-8)
                 segs.erase(removeIt);
         }
         segs.erase(firstSeg);
         bool foundSomething = true;
         while (!segs.empty() && foundSomething)
         {
             foundSomething = false;
             //Vec3MultiMap::iterator next = segs.find(headSecond);
             int next_pos = segs.find(headSecond);
             //if (next != segs.end())
             if(next_pos!=-1)
             {
                 std_pair<Vector3,List<Vector3>>next=segs.get((uint)next_pos);
                 foundSomething = true;
                 headSecond = next.second[0];
                 p.addPoint(headSecond);
                 //std::pair<Vec3MultiMap::iterator, Vec3MultiMap::iterator> correspondants = segs.equal_range(headSecond);
                 std_pair<std_pair<Vector3,List<Vector3>>,std_pair<Vector3,List<Vector3>>>correspondants = segs.equal_range(headSecond);
                 //for (Vec3MultiMap::iterator it = correspondants.first; it != correspondants.second;)
                 for (int i = correspondants.first.second.Count - 1; i >= 0;i-- ) {
                     //Vec3MultiMap::iterator removeIt = it++;
                     Vector3 removeIt = correspondants.first.second[i];
                     //if ((removeIt->second - next->first).squaredLength() < 1e-8)
                     if ((removeIt - next.first).SquaredLength < 1e-8)
                         segs.erase(removeIt);
                 }
                 //segs.erase(next);
                 segs.erase(next.first);
             }
             //Vec3MultiMap::iterator previous = segs.find(headFirst);
             int previous_pos=segs.find(headFirst);
             //if (previous != segs.end())
             if(previous_pos!=-1)
             {
                 std_pair<Vector3, List<Vector3>> previous = segs.get((uint)previous_pos);
                 foundSomething = true;
                 //p.insertPoint(0, previous.second);
                 p.insertPoint(0, previous.second[0]);//???
                 headFirst = previous.second[0];
                 //std::pair<Vec3MultiMap::iterator, Vec3MultiMap::iterator> correspondants = segs.equal_range(headFirst);
                 std_pair<std_pair<Vector3,List<Vector3>>,std_pair<Vector3,List<Vector3>>>correspondants = segs.equal_range(headFirst);
                 //for (Vec3MultiMap::iterator it = correspondants.first; it != correspondants.second;)
                 for(int i=correspondants.first.second.Count-1;i>=0;i--)
                 {
                     //Vec3MultiMap::iterator removeIt = it++;
                     Vector3 removeIt=correspondants.first.second[i];
                     //if ((removeIt->second - previous->first).squaredLength() < 1e-8)
                     if((removeIt-previous.first).SquaredLength<1e-8) 
                     segs.erase(removeIt);
                 }
                 //segs.erase(previous);
                 segs.erase(previous.first);
             }
         }
         if ((p.getPoint(0)-p.getPoint(p.getSegCount() + 1)).SquaredLength < 1e-6)
         {
             p.getPointsReference().pop_back();
             p.close();
         }
         @out.push_back(p);
     }
 }
 /// Extracts a part of the shape as a new path
 /// @param first first index to be in the new path
 /// @param last last index to be in the new path
 public Path extractSubPath(int first, int last) {//提取 抽出 抽取 
     Path p = new Path();
     for (int i = first; i < last; i++) {
         p.addPoint(mPoints[i]);
     }
     if (mClosed) {
         p.close();
     }
     return p;
 }
        /// Creates a path with the keys of this path and extra keys coming from a track
        //
        //ORIGINAL LINE: Path mergeKeysWithTrack(const Track& track) const
        public Path mergeKeysWithTrack(Track track) {
            if (!track.isInsertPoint() || track.getAddressingMode() == Track.AddressingMode.AM_POINT)
                return this;
            float totalLength = getTotalLength();

            float lineicPos = 0;
            float pathLineicPos = 0;
            Path outputPath = new Path();
            outputPath.addPoint(getPoint(0));
            for (int i = 1; i < mPoints.size(); ) {
                float nextLineicPos = pathLineicPos + (mPoints[i] - mPoints[i - 1]).Length;

                std_pair<float, float> it = track._getKeyValueAfter(lineicPos, lineicPos / totalLength, (uint)(i - 1));

                float nextTrackPos = it.first;
                if (track.getAddressingMode() == Track.AddressingMode.AM_RELATIVE_LINEIC)
                    nextTrackPos *= totalLength;

                // Adds the closest point to the curve, being either from the path or the track
                if (nextLineicPos <= nextTrackPos || lineicPos >= nextTrackPos) {
                    outputPath.addPoint(mPoints[i]);
                    i++;
                    lineicPos = nextLineicPos;
                    pathLineicPos = nextLineicPos;
                }
                else {
                    outputPath.addPoint(getPosition(i - 1, (nextTrackPos - pathLineicPos) / (nextLineicPos - pathLineicPos)));
                    lineicPos = nextTrackPos;
                }
            }
            return outputPath;
        }
 ///<summary>
 /// Appends another path at the end of this one, relative to the last point of this path
 ///</summary>
 public Path appendPathRel(Path other) {
     if (mPoints.empty())
         appendPath(other);
     else {
         Vector3 refVector = mPoints[mPoints.Count - 1]; //*(mPoints.end()-1);
         Vector3[] pointList = (other.mPoints.ToArray());
         //for (List<Vector3>.Enumerator it = pointList.GetEnumerator(); it.MoveNext(); ++it)
         //	it.Current += refVector;
         for (int i = 0; i < pointList.Length; i++) {
             pointList[i] += refVector;
         }
         //mPoints.insert(mPoints.end(), pointList.begin(), pointList.end());
         mPoints.AddRange(pointList);
     }
     return this;
 }