Skip to content

Instantly share code, notes, and snippets.

@Nuhvi
Last active April 22, 2020 11:06
Show Gist options
  • Save Nuhvi/d553ab63c0d95aa99283b91cf07f6e5c to your computer and use it in GitHub Desktop.
Save Nuhvi/d553ab63c0d95aa99283b91cf07f6e5c to your computer and use it in GitHub Desktop.
A function I used to calculate the width and height of an object to fit in a parent element, during working on Single Stroke
export const scaleNeeded = (
src: { w: number; h: number },
trgt: { w: number; h: number },
): number => {
const wr = trgt.w / src.w;
const hr = trgt.h / src.h;
return Math.min(wr,hr);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment