-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update: Added a position option and removed undocumented unequal offs…
…et detection
- Loading branch information
1 parent
4151d70
commit db78cab
Showing
11 changed files
with
95 additions
and
86 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
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
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
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Point } from '@imagemagick/magick-wasm'; | ||
|
||
import BadgeGravity from '../types/BadgeGravity'; | ||
import BadgePosition from '../types/BadgePosition'; | ||
import Rectangle from '../types/Rectangle'; | ||
import getRotatedBadgeInfo from './getRotatedBadgeInfo'; | ||
|
||
function determinePoint( | ||
container: Rectangle, | ||
badge: Rectangle, | ||
position: number, | ||
gravity: BadgeGravity, | ||
): Point { | ||
switch (gravity) { | ||
case BadgeGravity.North: | ||
return new Point( | ||
(container.width - badge.width) / 2, | ||
(container.height - badge.height) * (position / 100), | ||
); | ||
case BadgeGravity.Northeast: | ||
return new Point( | ||
(container.width - badge.width) * (1 - position / 100), | ||
(container.height - badge.height) * (position / 100), | ||
); | ||
case BadgeGravity.Northwest: | ||
return new Point( | ||
(container.width - badge.width) * (position / 100), | ||
(container.height - badge.height) * (position / 100), | ||
); | ||
case BadgeGravity.South: | ||
return new Point( | ||
(container.width - badge.width) / 2, | ||
(container.height - badge.height) * (1 - position / 100), | ||
); | ||
case BadgeGravity.Southeast: | ||
return new Point( | ||
(container.width - badge.width) * (1 - position / 100), | ||
(container.height - badge.height) * (1 - position / 100), | ||
); | ||
case BadgeGravity.Southwest: | ||
return new Point( | ||
(container.width - badge.width) * (position / 100), | ||
(container.height - badge.height) * (1 - position / 100), | ||
); | ||
} | ||
} | ||
|
||
export default function calculateManualBadgePosition( | ||
container: Rectangle, | ||
badge: Rectangle, | ||
position: number, | ||
gravity: BadgeGravity, | ||
): BadgePosition { | ||
const { rotation, rotatedWidth, rotatedHeight } = getRotatedBadgeInfo( | ||
badge, | ||
gravity, | ||
); | ||
|
||
const rotatedBadge: Rectangle = { | ||
width: rotatedWidth, | ||
height: rotatedHeight, | ||
}; | ||
|
||
return { | ||
point: determinePoint(container, rotatedBadge, position, gravity), | ||
rotation, | ||
}; | ||
} |
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 was deleted.
Oops, something went wrong.
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