-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent having negative values for rotationQuarterTurns
- Loading branch information
Showing
3 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
import 'dart:ui'; | ||
|
||
extension SizeExtension on Size { | ||
Size rotateByQuarterTurns(int quarterTurns) => switch (quarterTurns % 4) { | ||
0 || 2 => this, | ||
1 || 3 => Size(height, width), | ||
_ => throw ArgumentError('Invalid quarterTurns $quarterTurns'), | ||
}; | ||
Size rotateByQuarterTurns(int quarterTurns) { | ||
if (quarterTurns < 0) { | ||
throw ArgumentError('quarterTurns must be greater than or equal to 0.'); | ||
} | ||
return switch (quarterTurns % 4) { | ||
0 || 2 => this, | ||
_ /*2 || 3*/ => Size(height, width), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters