refactor(project): 清理闲置展示链路与重复采样状态

This commit is contained in:
2026-11-09 00:41:09 +08:00
parent 7b3abe37c5
commit b73d51c953
57 changed files with 210 additions and 2822 deletions
+4 -19
View File
@@ -13,8 +13,6 @@ import QuartzCore
window.contentView = root
let plot = NativePanelCurve.PlotView(); plot.frame = NSRect(x: 0, y: 0, width: 280, height: 60)
root.addSubview(plot)
let ring = NativeMetricRing.RingView(); ring.frame = NSRect(x: 0, y: 70, width: 28, height: 28)
root.addSubview(ring)
window.orderFrontRegardless()
try? await Task.sleep(for: .milliseconds(100))
let dates = (0..<4).map { Date(timeIntervalSinceReferenceDate: Double($0 * 2)) }
@@ -55,13 +53,6 @@ import QuartzCore
precondition(redPixels(bitmap(plot)) > 0)
plot.appearance = NSAppearance(named: .darkAqua)
precondition(redPixels(bitmap(plot)) > 0)
ring.configure(NativeMetricRing.Input(value: 0, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
precondition(redPixels(bitmap(ring), opaque: true) == 0, "Zero ring must not draw a colored arc")
ring.configure(NativeMetricRing.Input(value: 0.25, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
let quarter = redPixels(bitmap(ring), opaque: true)
ring.configure(NativeMetricRing.Input(value: 1, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
let full = redPixels(bitmap(ring), opaque: true)
precondition(quarter > 0 && full > quarter * 2, "Ring fraction must change the rendered arc")
// Sampling updates are final immediately, and hover keeps cached curve geometry.
let nextDates = dates + [Date(timeIntervalSinceReferenceDate: 8)]
let next = NativePanelCurve.Input(frame: PanelCurveFrame(dates: nextDates,
@@ -86,20 +77,14 @@ import QuartzCore
series: [Array(repeating: 0.8, count: 59) + [0.5]], intervals: fullFrame.intervals, boundaryDates: [])
plot.configure(.init(frame: appended, colors: [.red], scales: [1], maximumGap: 5))
precondition(plot.input?.frame.dates.count == 60, "Static history must not retain an outgoing animation point")
ring.configure(.init(value: 0.25, color: .red, lineWidth: 3, trackOpacity: 0.17, inset: 2))
precondition(ring.arc.strokeEnd == 0.25, "The arc must immediately show the new value")
let updated = bitmap(ring)
try? await Task.sleep(for: .milliseconds(180))
precondition(pixels(updated) == pixels(bitmap(ring)), "A sampled ring must not interpolate later")
// Adding a series with an unchanged palette must color the new layer too.
plot.configure(.init(frame: PanelCurveFrame(dates: dates, series: [[nil,nil,nil,nil], [0.5,0.5,0.5,0.5]],
intervals: [2,2,2,2], boundaryDates: []), colors: [.red], scales: [1], maximumGap: 5))
precondition(redPixels(bitmap(plot), from: 0.4, to: 0.6) > 10)
assertStatic(plot.layer!)
assertStatic(ring.layer!)
plot.removeFromSuperview(); ring.removeFromSuperview()
plot.removeFromSuperview()
window.orderOut(nil); window.close()
print("PASS: static curve/ring pixels, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount")
print("PASS: static curve pixels, immediate stable updates, no animation/material/gradient layers, real gaps, hover cache, palette growth, appearance, full history and unmount")
fflush(stdout); NSApp.terminate(nil)
}
NSApp.run()
@@ -125,12 +110,12 @@ import QuartzCore
view.layer!.render(in: context)
return result
}
private static func redPixels(_ image: NSBitmapImageRep, from: Double = 0, to: Double = 1, opaque: Bool = false) -> Int {
private static func redPixels(_ image: NSBitmapImageRep, from: Double = 0, to: Double = 1) -> Int {
var count = 0
for x in Int(Double(image.pixelsWide) * from)..<Int(Double(image.pixelsWide) * to) {
for y in 0..<image.pixelsHigh {
guard let color = image.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB) else { continue }
if color.redComponent > color.greenComponent + 0.15 && color.redComponent > color.blueComponent + 0.15 && color.alphaComponent > (opaque ? 0.8 : 0.01) { count += 1 }
if color.redComponent > color.greenComponent + 0.15 && color.redComponent > color.blueComponent + 0.15 && color.alphaComponent > 0.01 { count += 1 }
}
}
return count