Skip to content

Commit

Permalink
Merge pull request #41 from valeriyvan/addprecondition
Browse files Browse the repository at this point in the history
Move ShapeAcceptancePreconditionFunction into separate file
  • Loading branch information
valeriyvan authored Aug 19, 2023
2 parents e3e2ab7 + 05bab90 commit b2d810b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
35 changes: 0 additions & 35 deletions Sources/geometrize/Model.swift
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
import Foundation

/// Type alias for a function that is used to decide whether or not to finally add a shape to the image.
/// - Parameters:
/// - lastScore The image similarity score prior to adding the shape.
/// - newScore What the image similarity score would be after adding the shape.
/// - shape The shape that this function shall decide whether to add.
/// - lines The scanlines for the pixels in the shape.
/// - color The colour of the shape.
/// - before The image prior to adding the shape.
/// - after The image as it would be after adding the shape
/// - target The image that we are trying to replicate.
/// - Returns: True to add the shape to the image, false not to.
public typealias ShapeAcceptancePreconditionFunction = (
_ lastScore: Double,
_ newScore: Double,
_ shape: any Shape,
_ lines: [Scanline],
_ color: Rgba,
_ before: Bitmap,
_ after: Bitmap,
_ target: Bitmap
) -> Bool

public func defaultAddShapePrecondition( // swiftlint:disable:this function_parameter_count
lastScore: Double,
newScore: Double,
shape: any Shape,
lines: [Scanline],
color: Rgba,
_: Bitmap,
_: Bitmap,
_: Bitmap
) -> Bool {
newScore < lastScore; // Adds the shape if the score improved (that is: the difference decreased)
}

/// The Model class is the model for the core optimization/fitting algorithm.
struct Model {

Expand Down
36 changes: 36 additions & 0 deletions Sources/geometrize/ShapeAcceptancePrecondition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Foundation

/// Type alias for a function that is used to decide whether or not to finally add a shape to the image.
/// - Parameters:
/// - lastScore The image similarity score prior to adding the shape.
/// - newScore What the image similarity score would be after adding the shape.
/// - shape The shape that this function shall decide whether to add.
/// - lines The scanlines for the pixels in the shape.
/// - color The colour of the shape.
/// - before The image prior to adding the shape.
/// - after The image as it would be after adding the shape
/// - target The image that we are trying to replicate.
/// - Returns: True to add the shape to the image, false not to.
public typealias ShapeAcceptancePreconditionFunction = (
_ lastScore: Double,
_ newScore: Double,
_ shape: any Shape,
_ lines: [Scanline],
_ color: Rgba,
_ before: Bitmap,
_ after: Bitmap,
_ target: Bitmap
) -> Bool

public func defaultAddShapePrecondition( // swiftlint:disable:this function_parameter_count
lastScore: Double,
newScore: Double,
shape: any Shape,
lines: [Scanline],
color: Rgba,
_: Bitmap,
_: Bitmap,
_: Bitmap
) -> Bool {
newScore < lastScore; // Adds the shape if the score improved (that is: the difference decreased)
}

0 comments on commit b2d810b

Please sign in to comment.