どこかを含むアセットに .svg ファイルがあるとします。
<polygon id="collide" fill="none" points="45,14 0,79 3,87 18,92 87,90 98,84 96,66 59,14"/>
この多角形を見つけて、その点を解析して Points[] 配列にする最良の方法は何だと思いますか?
ありがとう!
上記のコメントで述べたように、XML と XPath を使用すると、簡単に実行できます (例外チェックなし)。
public static Point[] getPoints(String xml) throws Exception {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xml)));
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("//polygon[@id='collide']/@points");
String[] pointsAttr = ((String) expr.evaluate(doc, XPathConstants.STRING)).split("\\p{Space}");
Point[] points = new Point[pointsAttr.length];
for (int i = 0; i < pointsAttr.length; ++i) {
String[] coordinates = pointsAttr[i].split(",");
points[i] = new Point(Integer.valueOf(coordinates[0]), Integer.valueOf(coordinates[1]));
}
return points;
}
Androidで何を自由に使えるかわかりません。