Created
April 1, 2018 14:02
-
-
Save Bobsans/c7c09ad1b6105168d474940d3ce98a4f to your computer and use it in GitHub Desktop.
Translate svg path
This file contains hidden or 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
| def translate(path, mx, my): | |
| out = [] | |
| parts = path.split(' ') | |
| for part in parts: | |
| if ',' in part: | |
| nums = part.split(',') | |
| prex = nums[0][0] if nums[0][0] in ('M', 'C', 'L') else '' | |
| numx = float(nums[0][1:]) if nums[0][0] in ('M', 'C', 'L') else float(nums[0]) | |
| prey = nums[1][0] if nums[1][0] in ('M', 'C', 'L') else '' | |
| numy = float(nums[1][1:]) if nums[1][0] in ('M', 'C', 'L') else float(nums[1]) | |
| out.append(f'{prex}{numx - mx:.5f},{numy - my:.5f}') | |
| else: | |
| out.append(part) | |
| return ' '.join(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment