Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- * Generates the svg path data for a rounded rectangle
- * Rounded corners are approximated by Cubic bezier curve with control point at an end point and the other at the corner
- * @license MIT License
- * Copyright (c) 2018 Yusuf Ades
- * @param {Object} dimension - Dimensions of rectangle.
- * @param {number} width - Width.
- * @param {number} height - Height.
- * @param {number} [r=0] - Corner Radius. Keep this smaller than half of width or height.
- * @param {number} [x=0] - Offset from top left corner in x axis. default 0.
- * @param {number} [y=0] - Offset from top left corner in y axis. default 0.
- * @returns {string} - Rounded rectangle path data.
- */
- function roundRectPath({ width, height, r = 0, x = 0, y = 0 }) {
- const v0 = { x: x, y: y };
- const v1 = { x: x, y: y + height };
- const v2 = { x: x + width, y: y + height };
- const v3 = { x: x + width, y: y };
- return `M${v0.x} ${v0.y + r} V${v1.y - r} C${v1.x} ${v1.y} ${v1.x + r} ${v1.y} ${v1.x + r} ${v1.y} H${v2.x - r} \
- C${v2.x} ${v2.y} ${v2.x} ${v2.y - r} ${v2.x} ${v2.y - r} V${v3.y + r} C${v3.x} ${v3.y} ${v3.x - r} ${v3.y} ${v3.x - r} ${v3.y} \
- H${v0.x + r} C${v0.x} ${v0.y} ${v0.x} ${v0.y + r} ${v0.x} ${v0.y + r} Z`;
- }
Add Comment
Please, Sign In to add comment