Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove not needed any/some #180

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/geometrize/GeometrizeModelBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GeometrizeModelBase {
/// - shape: The shape to draw.
/// - color: The color (including alpha) of the shape.
/// - Returns: Data about the shape drawn on the model.
func draw(shape: any Shape, color: Rgba) -> ShapeResult {
func draw(shape: Shape, color: Rgba) -> ShapeResult {
let lines: [Scanline] = shape.rasterize(x: 0...width - 1, y: 0...height - 1)
let before: Bitmap = currentBitmap
currentBitmap.draw(lines: lines, color: color)
Expand Down
6 changes: 3 additions & 3 deletions Sources/geometrize/SVGExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct SVGExporter {
/// - color: The color of the shape
/// - shape: The shape to convert to SVG data
/// - Returns: The SVG shape data for the given shape
func singleShapeData(color: Rgba, shape: any Shape) -> String {
func singleShapeData(color: Rgba, shape: Shape) -> String {
var shapeData: String = shapeData(shape: shape)

var styles: String = ""
Expand Down Expand Up @@ -45,7 +45,7 @@ public struct SVGExporter {
/// - Returns: A string representing the SVG image.
func exportSingleShape( // swiftlint:disable:this function_parameter_count
color: Rgba,
shape: any Shape,
shape: Shape,
width: Int,
height: Int,
originWidth: Int,
Expand Down Expand Up @@ -142,7 +142,7 @@ public struct SVGExporter {
"<path d=\"M\(Int(q.x1)) \(Int(q.y1)) Q\(Int(q.cx)) \(Int(q.cy)) \(Int(q.x2)) \(Int(q.y2))\" \(svg_style_hook)/>"
}

private func shapeData(shape: any Shape) -> String {
private func shapeData(shape: Shape) -> String {
switch shape {
case let rectangle as Rectangle:
return shapeData(rectangle: rectangle)
Expand Down
4 changes: 2 additions & 2 deletions Sources/geometrize/ShapeAcceptancePrecondition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Foundation
public typealias ShapeAcceptancePreconditionFunction = @Sendable (
_ lastScore: Double,
_ newScore: Double,
_ shape: any Shape,
_ shape: Shape,
_ lines: [Scanline],
_ color: Rgba,
_ before: Bitmap,
Expand All @@ -25,7 +25,7 @@ public typealias ShapeAcceptancePreconditionFunction = @Sendable (
@Sendable public func defaultAddShapePrecondition( // swiftlint:disable:this function_parameter_count
lastScore: Double,
newScore: Double,
shape: any Shape,
shape: Shape,
lines: [Scanline],
color: Rgba,
_: Bitmap,
Expand Down
2 changes: 1 addition & 1 deletion Sources/geometrize/ShapeCreator.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public typealias ShapeCreator = @Sendable (inout SplitMix64) -> any Shape
public typealias ShapeCreator = @Sendable (inout SplitMix64) -> Shape

/// Creates a function for creating instances of Shape. Returned instances should be set up!
/// - Parameters:
Expand Down
4 changes: 2 additions & 2 deletions Sources/geometrize/ShapeResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Foundation
public struct ShapeResult {
public let score: Double
public let color: Rgba
public let shape: any Shape
public let shape: Shape

public init(score: Double, color: Rgba, shape: any Shape) {
public init(score: Double, color: Rgba, shape: Shape) {
self.score = score
self.color = color
self.shape = shape
Expand Down
6 changes: 3 additions & 3 deletions Sources/geometrize/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

struct State: Sendable {

init(score: Double, alpha: UInt8, shape: some Shape) {
init(score: Double, alpha: UInt8, shape: Shape) {
self.score = score
self.alpha = alpha
self.shape = shape
Expand All @@ -15,15 +15,15 @@ struct State: Sendable {
let alpha: UInt8

/// The geometric primitive owned by the state.
let shape: any Shape
let shape: Shape

/// Modifies the current state in a random fashion.
/// - Returns: new mutated state.
mutating func mutate(
x xRange: ClosedRange<Int>, // TODO: rename
y yRange: ClosedRange<Int>, // TODO: rename
using generator: inout SplitMix64,
score: ((any Shape) -> Double)
score: ((Shape) -> Double)
) -> State {
let mutatedShape = shape.mutate(x: xRange, y: yRange, using: &generator)
return State(score: score(mutatedShape), alpha: alpha, shape: mutatedShape)
Expand Down
2 changes: 1 addition & 1 deletion Tests/geometrizeTests/hillClimbTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class HillClimbTests: XCTestCase {

}

func == (lhs: any Shape, rhs: any Shape) -> Bool {
func == (lhs: Shape, rhs: Shape) -> Bool {
switch (lhs, rhs) {
case (let lhs as Circle, let rhs as Circle): return lhs == rhs
case (let lhs as Ellipse, let rhs as Ellipse): return lhs == rhs
Expand Down