-
Notifications
You must be signed in to change notification settings - Fork 3
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
GH-34 Allow more flexible slicing #35
Conversation
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
Signed-off-by: Henrik Panhans <[email protected]>
This reverts commit 052763b. Signed-off-by: Henrik Panhans <[email protected]>
Negative sizes are not possible anymore Signed-off-by: Henrik Panhans <[email protected]>
@@ -55,8 +57,8 @@ struct Render: ParsableCommand { | |||
verbose: verbose, | |||
shouldValidateManually: manualValidation, | |||
shouldOutputWholeImage: outputWholeImage, | |||
shouldClearDirectories: !noClearDirectories, | |||
shouldColorOutput: !noColorOutput | |||
shouldClearDirectories: clearDirectories, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes so much more sense now that I'm seeing this :D
guard numberOfSlices > 0 else { | ||
throw NSError( | ||
description: "Invalid numberOfSlices value", | ||
expectation: "numberOfSlices value should be >= 1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this means the same as the actual condition, but to me it would make sense to have the condition and the expectation's textual description be the exact same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this follows the pattern of NSError
, it has localizedFailureReason
, localizedDescription
and localizedRecoverySuggestion
which this kind of mimics a bit 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is that I find it odd that the condition is numberOfSlices > 0
but then the textual description is numberOfSlices value should be >= 1
instead of it being numberOfSlices value should be > 0
:D
} | ||
|
||
if let templateImage { | ||
_ = try SliceSizeCalculator.calculateSliceSize( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we do the above check for numberOfSlices > 0
when we do the same again in SliceSizeCalculator.calculateSliceSize
? I'd suggest extracting the validation conditions into another static method e.g. validateSliceSizeCalculationInput(templateImageSize: CGSize, numberOfSlices: Int, gapWidth: Int?) -> Result
which we could then call from here and from inside SliceSizeCalculator.calculateSliceSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Result
could e.g. be an enum such as
enum Result {
case valid
case invalid(error: NSError)
}
¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or well, now looking at the method itself, the calculation logic would be almost the same as the method itself so idk 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I see where you're coming from though, I wasn't super happy about this either 😅 using a static value would have to be a bit more complex though as there can be multiple DeviceData
in a single configuration file
@@ -1,24 +1,15 @@ | |||
import Foundation | |||
|
|||
extension Array where Element == URL { | |||
extension [URL] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
@@ -110,14 +99,17 @@ public class ConfigProcessor: VerbosePrintable { | |||
|
|||
try deviceData.screenshotsGroupedByLocale.forEach { locale, imageDict in | |||
group.enter() | |||
defer { group.leave() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait what this works 🤯 I always thought one can only do this for a method, not a loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
defer
statement is used for executing code just before transferring program control outside of the scope that the statement appears in.
Honestly I didn't think about it when I wrote it, the compiler didn't complain 😄 but I verified that it's not accidentally using method-scope but the for-loop-scope with this code:
func deferTest() {
let values = [1, 2, 3, 4]
for value in values {
defer { print(value) }
print("Loop")
}
}
prints:
Loop
1
Loop
2
Loop
3
Loop
4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯 the more you know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codewise looks good and the tests instructed in the PR description are all looking good. Kind of tempted to test this with our screenshot pipeline but it feels like a bit too much of effort. We'll find out once we merge this to master anyways 😅
Signed-off-by: Henrik Panhans <[email protected]>
Background
This PR changes the process of slicing the final canvas into slices to not rely on the size of the supplied screenshots anymore but rather the user specifying a desired number of slices.
It also fixes a couple of other things, like remove a bunch of dead code and QOL updates
Changes
Changes relevant to #34
numberOfSlices
toDeviceData
SliceSizeCalculator
type and tests for itvalidate()
method inDeviceData
to verify a couple thingsOther changes
swift-argument-parser
to 1.3.0inversion: .prefixedNo
to two flags that had an inverted name, this makes it easier to reason about them without doing the mental inversion based on the nameNSRegularExpression
to modernRegex
clearDirectories
andoutputWholeImage
keys from parsingbenchmark.py
script to not rely on any third-party librariesHow to Test
swift run swiftframe render Example/example.yaml --verbose --manual-validation
Number of slices
and also that theOutput slice size
is displayedCloses #34