mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Fix #395: improvements readSegments for A,a
This commit is contained in:
parent
8affa6f988
commit
0d5a5136da
@ -1610,7 +1610,7 @@ private class PathDataReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func read() -> [PathSegment] {
|
public func read() -> [PathSegment] {
|
||||||
_ = readNext()
|
readNext()
|
||||||
var segments = [PathSegment]()
|
var segments = [PathSegment]()
|
||||||
while let array = readSegments() {
|
while let array = readSegments() {
|
||||||
segments.append(contentsOf: array)
|
segments.append(contentsOf: array)
|
||||||
@ -1625,7 +1625,12 @@ private class PathDataReader {
|
|||||||
return [PathSegment(type: type)]
|
return [PathSegment(type: type)]
|
||||||
}
|
}
|
||||||
var result = [PathSegment]()
|
var result = [PathSegment]()
|
||||||
let data = readData(type: type)
|
let data: [Double]
|
||||||
|
if type == .a || type == .A {
|
||||||
|
data = readDataOfASegment()
|
||||||
|
} else {
|
||||||
|
data = readData()
|
||||||
|
}
|
||||||
var index = 0
|
var index = 0
|
||||||
var isFirstSegment = true
|
var isFirstSegment = true
|
||||||
while index < data.count {
|
while index < data.count {
|
||||||
@ -1651,11 +1656,11 @@ private class PathDataReader {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func readData(type: PathSegmentType) -> [Double] {
|
private func readData() -> [Double] {
|
||||||
var data = [Double]()
|
var data = [Double]()
|
||||||
while true {
|
while true {
|
||||||
skipSpaces()
|
skipSpaces()
|
||||||
if let value = readNum(type: type, index: data.count) {
|
if let value = readNum() {
|
||||||
data.append(value)
|
data.append(value)
|
||||||
} else {
|
} else {
|
||||||
return data
|
return data
|
||||||
@ -1663,6 +1668,28 @@ private class PathDataReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func readDataOfASegment() -> [Double] {
|
||||||
|
let argCount = getArgCount(segment: .A)
|
||||||
|
var data: [Double] = []
|
||||||
|
var index = 0
|
||||||
|
while true {
|
||||||
|
skipSpaces()
|
||||||
|
let value: Double?
|
||||||
|
let indexMod = index % argCount
|
||||||
|
if indexMod == 3 || indexMod == 4 {
|
||||||
|
value = readFlag()
|
||||||
|
} else {
|
||||||
|
value = readNum()
|
||||||
|
}
|
||||||
|
guard let doubleValue = value else {
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
data.append(doubleValue)
|
||||||
|
index += 1
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
private func skipSpaces() {
|
private func skipSpaces() {
|
||||||
var ch = current
|
var ch = current
|
||||||
while ch != nil && "\n\r\t ,".contains(String(ch!)) {
|
while ch != nil && "\n\r\t ,".contains(String(ch!)) {
|
||||||
@ -1670,7 +1697,22 @@ private class PathDataReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func readNum(type: PathSegmentType, index: Int) -> Double? {
|
private func readFlag() -> Double? {
|
||||||
|
guard let ch = current else {
|
||||||
|
return .none
|
||||||
|
}
|
||||||
|
readNext()
|
||||||
|
switch ch {
|
||||||
|
case "0":
|
||||||
|
return 0
|
||||||
|
case "1":
|
||||||
|
return 1
|
||||||
|
default:
|
||||||
|
return .none
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fileprivate func readNum() -> Double? {
|
||||||
guard let ch = current else {
|
guard let ch = current else {
|
||||||
return .none
|
return .none
|
||||||
}
|
}
|
||||||
@ -1681,9 +1723,7 @@ private class PathDataReader {
|
|||||||
|
|
||||||
var chars = [ch]
|
var chars = [ch]
|
||||||
var hasDot = ch == "."
|
var hasDot = ch == "."
|
||||||
let isFlag = (type == .a || type == .A) && (index == 3 || index == 4)
|
while let ch = readDigit(&hasDot) {
|
||||||
|
|
||||||
while let ch = readDigit(&hasDot), !isFlag {
|
|
||||||
chars.append(ch)
|
chars.append(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1692,12 +1732,6 @@ private class PathDataReader {
|
|||||||
guard let value = Double(buf) else {
|
guard let value = Double(buf) else {
|
||||||
return .none
|
return .none
|
||||||
}
|
}
|
||||||
guard isFlag else {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
guard value == 0 || value == 1 else {
|
|
||||||
return .none
|
|
||||||
}
|
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1728,6 +1762,7 @@ private class PathDataReader {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
private func readNext() -> UnicodeScalar? {
|
private func readNext() -> UnicodeScalar? {
|
||||||
previous = current
|
previous = current
|
||||||
current = iterator.next()
|
current = iterator.next()
|
||||||
@ -1744,7 +1779,7 @@ private class PathDataReader {
|
|||||||
private func readSegmentType() -> PathSegmentType? {
|
private func readSegmentType() -> PathSegmentType? {
|
||||||
while true {
|
while true {
|
||||||
if let type = getPathSegmentType() {
|
if let type = getPathSegmentType() {
|
||||||
_ = readNext()
|
readNext()
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
if readNext() == nil {
|
if readNext() == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user