mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fix rule ordering
This commit is contained in:
@@ -428,12 +428,12 @@ public extension Mesh {
|
||||
)
|
||||
let v2 = Vertex(unchecked:
|
||||
Vector(cos0 * v1.position.x, v1.position.y, sin0 * -v1.position.x),
|
||||
Vector(cos0 * v1.normal.x, v1.normal.y, sin0 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t0, v1.texcoord.y, 0))
|
||||
Vector(cos0 * v1.normal.x, v1.normal.y, sin0 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t0, v1.texcoord.y, 0))
|
||||
let v3 = Vertex(unchecked:
|
||||
Vector(cos1 * v1.position.x, v1.position.y, sin1 * -v1.position.x),
|
||||
Vector(cos1 * v1.normal.x, v1.normal.y, sin1 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t1, v1.texcoord.y, 0))
|
||||
Vector(cos1 * v1.normal.x, v1.normal.y, sin1 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t1, v1.texcoord.y, 0))
|
||||
polygons.append(Polygon(unchecked: [v0, v2, v3], isConvex: true, material: material))
|
||||
}
|
||||
} else if v1.position.x == 0 {
|
||||
@@ -445,31 +445,31 @@ public extension Mesh {
|
||||
)
|
||||
let v2 = Vertex(unchecked:
|
||||
Vector(cos1 * v0.position.x, v0.position.y, sin1 * -v0.position.x),
|
||||
Vector(cos1 * v0.normal.x, v0.normal.y, sin1 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t1, v0.texcoord.y, 0))
|
||||
Vector(cos1 * v0.normal.x, v0.normal.y, sin1 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t1, v0.texcoord.y, 0))
|
||||
let v3 = Vertex(unchecked:
|
||||
Vector(cos0 * v0.position.x, v0.position.y, sin0 * -v0.position.x),
|
||||
Vector(cos0 * v0.normal.x, v0.normal.y, sin0 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t0, v0.texcoord.y, 0))
|
||||
Vector(cos0 * v0.normal.x, v0.normal.y, sin0 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t0, v0.texcoord.y, 0))
|
||||
polygons.append(Polygon(unchecked: [v2, v3, v1], isConvex: true, material: material))
|
||||
} else {
|
||||
// quad face
|
||||
let v2 = Vertex(unchecked:
|
||||
Vector(cos1 * v0.position.x, v0.position.y, sin1 * -v0.position.x),
|
||||
Vector(cos1 * v0.normal.x, v0.normal.y, sin1 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t1, v0.texcoord.y, 0))
|
||||
Vector(cos1 * v0.normal.x, v0.normal.y, sin1 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t1, v0.texcoord.y, 0))
|
||||
let v3 = Vertex(unchecked:
|
||||
Vector(cos0 * v0.position.x, v0.position.y, sin0 * -v0.position.x),
|
||||
Vector(cos0 * v0.normal.x, v0.normal.y, sin0 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t0, v0.texcoord.y, 0))
|
||||
Vector(cos0 * v0.normal.x, v0.normal.y, sin0 * -v0.normal.x),
|
||||
Vector(v0.texcoord.x + t0, v0.texcoord.y, 0))
|
||||
let v4 = Vertex(unchecked:
|
||||
Vector(cos0 * v1.position.x, v1.position.y, sin0 * -v1.position.x),
|
||||
Vector(cos0 * v1.normal.x, v1.normal.y, sin0 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t0, v1.texcoord.y, 0))
|
||||
Vector(cos0 * v1.normal.x, v1.normal.y, sin0 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t0, v1.texcoord.y, 0))
|
||||
let v5 = Vertex(unchecked:
|
||||
Vector(cos1 * v1.position.x, v1.position.y, sin1 * -v1.position.x),
|
||||
Vector(cos1 * v1.normal.x, v1.normal.y, sin1 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t1, v1.texcoord.y, 0))
|
||||
Vector(cos1 * v1.normal.x, v1.normal.y, sin1 * -v1.normal.x),
|
||||
Vector(v1.texcoord.x + t1, v1.texcoord.y, 0))
|
||||
let vertices = [v2, v3, v4, v5]
|
||||
if !verticesAreDegenerate(vertices) {
|
||||
polygons.append(Polygon(unchecked: vertices, isConvex: true, material: material))
|
||||
|
||||
+22
-5
@@ -34,6 +34,7 @@ import Foundation
|
||||
public final class FormatRule: Equatable, Comparable {
|
||||
private let fn: (Formatter) -> Void
|
||||
fileprivate(set) var name = ""
|
||||
fileprivate(set) var index = 0
|
||||
let help: String
|
||||
let orderAfter: [String]
|
||||
let options: [String]
|
||||
@@ -70,10 +71,7 @@ public final class FormatRule: Equatable, Comparable {
|
||||
}
|
||||
|
||||
public static func < (lhs: FormatRule, rhs: FormatRule) -> Bool {
|
||||
if lhs.orderAfter.contains(rhs.name) {
|
||||
return false
|
||||
}
|
||||
return rhs.orderAfter.contains(lhs.name) || lhs.name < rhs.name
|
||||
return lhs.index < rhs.index
|
||||
}
|
||||
|
||||
static let deprecatedMessage = [
|
||||
@@ -92,6 +90,25 @@ private let rulesByName: [String: FormatRule] = {
|
||||
rule.name = name
|
||||
rules[name] = rule
|
||||
}
|
||||
let values = rules.values.sorted(by: { $0.name < $1.name })
|
||||
for (index, value) in values.enumerated() {
|
||||
value.index = index * 10
|
||||
}
|
||||
var changedOrder = true
|
||||
while changedOrder {
|
||||
changedOrder = false
|
||||
for value in values {
|
||||
value.orderAfter.forEach { name in
|
||||
guard let rule = rules[name] else {
|
||||
preconditionFailure(name)
|
||||
}
|
||||
if rule.index >= value.index {
|
||||
value.index = rule.index + 1
|
||||
changedOrder = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rules
|
||||
}()
|
||||
|
||||
@@ -892,7 +909,7 @@ public struct _FormatRules {
|
||||
/// indenting can be configured with the `options` parameter of the formatter.
|
||||
public let indent = FormatRule(
|
||||
help: "Indent code in accordance with the scope level.",
|
||||
orderAfter: ["trailingSpace", "wrap", "wrapArguments"],
|
||||
orderAfter: ["trailingSpace", "wrap", "wrapArguments", "wrapMultilineStatementBraces"],
|
||||
options: ["indent", "tabwidth", "indentcase", "ifdef", "xcodeindentation"],
|
||||
sharedOptions: ["trimwhitespace", "closingparen"]
|
||||
) { formatter in
|
||||
|
||||
Reference in New Issue
Block a user