Skip to content

Commit

Permalink
Merge pull request #8 from lorentey/decore-graphics
Browse files Browse the repository at this point in the history
Stop using CG types outside renderers
  • Loading branch information
lorentey committed Apr 16, 2021
2 parents 7012b2d + faa1b2c commit 665cbb1
Show file tree
Hide file tree
Showing 32 changed files with 1,290 additions and 303 deletions.
22 changes: 22 additions & 0 deletions Sources/CollectionsBenchmark/Basics/Measurement.swift
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

/// A point in the document coordinate system, i.e., a pair of size and
/// time values.
public struct Measurement: Hashable, Codable {
public let size: Size
public let time: Time

public init(size: Size, time: Time) {
self.size = size
self.time = time
}
}
6 changes: 3 additions & 3 deletions Sources/CollectionsBenchmark/Basics/TaskResults.swift
Expand Up @@ -167,14 +167,14 @@ extension TaskResults {
for statistic: Sample.Statistic,
percentile: Double,
amortizedTime: Bool
) -> Curve<BenchmarkResults.Point> {
var curve = Curve<BenchmarkResults.Point>()
) -> Curve<Measurement> {
var curve = Curve<Measurement>()
for (size, sample) in _samples {
let sample = sample.discardingPercentile(above: percentile)
guard let time = sample[statistic] ?? sample[.mean] else { continue }

let t = amortizedTime ? time.amortized(over: size) : time
curve.points.append(BenchmarkResults.Point(size: size, time: t))
curve.points.append(Measurement(size: size, time: t))
}
return curve
}
Expand Down
Expand Up @@ -115,7 +115,7 @@ extension _BenchmarkCLI.Library {
let data = try renderer.render(
graphics,
format: format.rawValue,
bitmapScale: CGFloat(options.scale))
bitmapScale: options.scale)
try data.write(to: url)
count += 1
}
Expand Down
Expand Up @@ -9,7 +9,6 @@
//
//===----------------------------------------------------------------------===//

import Foundation // CGRect
import ArgumentParser

extension _BenchmarkCLI.Render {
Expand Down Expand Up @@ -85,8 +84,8 @@ extension _BenchmarkCLI.Render {
return options
}

var _bounds: CGRect {
CGRect(x: 0, y: 0, width: width, height: height)
var _bounds: Rectangle {
Rectangle(x: 0, y: 0, width: width, height: height)
}
}
}
Expand Up @@ -56,13 +56,13 @@ extension _BenchmarkCLI {
in: results,
options: try options.chartOptions())
let graphics = chart.draw(
bounds: CGRect(x: 0, y: 0, width: options.width, height: options.height),
bounds: Rectangle(x: 0, y: 0, width: options.width, height: options.height),
theme: theme,
renderer: renderer)
let data = try renderer.render(
graphics,
format: output.pathExtension,
bitmapScale: CGFloat(options.scale))
bitmapScale: options.scale)
try data.write(to: output, options: .atomic)
}
}
Expand Down
Expand Up @@ -194,7 +194,7 @@ extension _BenchmarkCLI.Results {
let data = try renderer.render(
graphics,
format: format.rawValue,
bitmapScale: CGFloat(chartOptions.scale))
bitmapScale: chartOptions.scale)
let filename = self.filename(title: title, index: i, format: format)
let url = dir.appendingPathComponent(filename)
try data.write(to: url, options: .atomic)
Expand Down
2 changes: 1 addition & 1 deletion Sources/CollectionsBenchmark/Charts/Band.swift
Expand Up @@ -90,7 +90,7 @@ extension Band {
}
}

extension Band where Element == Curve<BenchmarkResults.Point> {
extension Band where Element == Curve<Measurement> {
var sizeRange: ClosedRange<Size>? {
_union(bottom.sizeRange, _union(center.sizeRange, top.sizeRange))
}
Expand Down

0 comments on commit 665cbb1

Please sign in to comment.