1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-08-15 08:00:31 +03:00

Fix polyline and polygon points parsing

Handling of numbers in scientific notation in `parsePoints` used to be
incorrect, because a number could be broken by an exponent minus sign,
resulting in incorrect values.

E.g. '2.5e-1' -> '2.5e', '-1'.
This commit is contained in:
Petrov Anatoly 2020-04-29 15:45:26 +07:00
parent b3b8f321bf
commit bd5e868dac

View File

@ -986,15 +986,14 @@ open class SVGParser {
fileprivate func parsePoints(_ pointsString: String) -> [Double] {
var resultPoints: [Double] = []
let pointPairs = pointsString.replacingOccurrences(of: "-", with: " -").components(separatedBy: " ")
pointPairs.forEach { pointPair in
let points = pointPair.components(separatedBy: ",")
points.forEach { point in
if let resultPoint = Double(point) {
resultPoints.append(resultPoint)
}
let scanner = Scanner(string: pointsString)
while !scanner.isAtEnd {
var resultPoint: Double = 0
if scanner.scanDouble(&resultPoint) {
resultPoints.append(resultPoint)
}
_ = scanner.scanCharacters(from: [","], into: nil)
}
if resultPoints.count % 2 == 1 {