//----------------------------------------------------------------------- void parsePath(ref MultiShape @out, XmlNode pPathNode) { //if (pPathNode->first_attribute("d")) if (pPathNode.Attributes["d"] != null) { string temp = xtrim(pPathNode.Attributes["d"].Value, " .-0123456789mMlLhHvVcCsSqQtTaAzZ"); std_vector <string> parts = split(temp, " "); for (int i = 0; i < parts.size(); i++) { if (parts[i].Length > 1 && !(parts[i][0] == '-' || ('0' <= parts[i][0] && parts[i][0] <= '9'))) { parts.insert(parts.begin() + i + 1, parts[i] + 1); //parts[i].erase(1, parts[i].size()); parts[i] = parts[i].Remove(1); } } SvgLoaderPath sp = new SvgLoaderPath(parts, mNumSeg); if (!sp.isValid()) { return; } Shape ss = sp.getSvgShape(); Vector2 line = ss.getPoint(1) - ss.getPoint(0); //Real deg = line.angleBetween(ss.getPoint(2) - ss.getPoint(0)).valueDegrees(); float deg = Utils.angleBetween(line, ss.getPoint(2) - ss.getPoint(0)).ValueDegrees; if ((0 <= deg && deg <= 180.0f) || (-180.0f <= deg && deg <= 0)) { ss.setOutSide(Side.SIDE_LEFT); } else { ss.setOutSide(Side.SIDE_RIGHT); } //if(pPathNode->first_attribute("id")) // ss.id = pPathNode->first_attribute("id")->value(); ss.translate(getAttribTranslate(pPathNode)); @out.addShape(ss); } }
//void Triangulator::_recursiveTriangulatePolygon(const DelaunaySegment& cuttingSeg, std::vector<int> inputPoints, DelaunayTriangleBuffer& tbuffer, const PointList& pointList) const void _recursiveTriangulatePolygon(DelaunaySegment cuttingSeg, std_vector <int> inputPoints, DelaunayTriangleBuffer tbuffer, PointList pointList) { if (inputPoints.size() == 0) { return; } if (inputPoints.size() == 1) { Triangle t2 = new Triangle(pointList); //t.setVertices(cuttingSeg.i1, cuttingSeg.i2, inputPoints.begin()); t2.setVertices(cuttingSeg.i1, cuttingSeg.i2, inputPoints.front()); t2.makeDirectIfNeeded(); tbuffer.push_back(t2); return; } // Find a point which, when associated with seg.i1 and seg.i2, builds a Delaunay triangle //std::vector<int>::iterator currentPoint = inputPoints.begin(); int currentPoint_pos = inputPoints.begin(); int currentPoint = inputPoints.front(); bool found = false; while (!found) { bool isDelaunay = true; //Circle c=new Circle(pointList[*currentPoint], pointList[cuttingSeg.i1], pointList[cuttingSeg.i2]); Circle c = new Circle(pointList[currentPoint], pointList[cuttingSeg.i1], pointList[cuttingSeg.i2]); //for (std::vector<int>::iterator it = inputPoints.begin(); it!=inputPoints.end(); ++it) int idx = -1; foreach (var it in inputPoints) { idx++; //if (c.isPointInside(pointList[*it]) && (*it != *currentPoint)) if (c.isPointInside(pointList[it]) && (it != currentPoint)) { isDelaunay = false; currentPoint = it; currentPoint_pos = idx; break; } } if (isDelaunay) { found = true; } } // Insert current triangle Triangle t = new Triangle(pointList); //t.setVertices(*currentPoint, cuttingSeg.i1, cuttingSeg.i2); t.setVertices(currentPoint, cuttingSeg.i1, cuttingSeg.i2); t.makeDirectIfNeeded(); tbuffer.push_back(t); // Recurse //DelaunaySegment newCut1=new DelaunaySegment(cuttingSeg.i1, *currentPoint); //DelaunaySegment newCut2=new DelaunaySegment(cuttingSeg.i2, *currentPoint); DelaunaySegment newCut1 = new DelaunaySegment(cuttingSeg.i1, currentPoint); DelaunaySegment newCut2 = new DelaunaySegment(cuttingSeg.i2, currentPoint); //std_vector<int> set1=new std_vector<int>(inputPoints.begin(), currentPoint); //std_vector<int> set2=new std_vector<int>(currentPoint+1, inputPoints.end()); std_vector <int> set1 = new std_vector <int>(); set1.assign(inputPoints.ToArray(), inputPoints.begin(), currentPoint_pos); std_vector <int> set2 = new std_vector <int>(); set2.assign(inputPoints.ToArray(), currentPoint_pos + 1, inputPoints.end()); if (!set1.empty()) { _recursiveTriangulatePolygon(newCut1, set1, tbuffer, pointList); } if (!set2.empty()) { _recursiveTriangulatePolygon(newCut2, set2, tbuffer, pointList); } }