1 | import { NUM_DEFAULT } from './constants';
|
2 |
|
3 | export default function rect2Path(options){
|
4 | var x = options.x || NUM_DEFAULT,
|
5 | y = options.y || NUM_DEFAULT,
|
6 | w = (options.width || NUM_DEFAULT) + x,
|
7 | h = (options.height || NUM_DEFAULT) + y;
|
8 |
|
9 | if (options.rx || options.ry) {
|
10 | var rx = options.rx ? options.rx : options.ry,
|
11 | ry = options.ry ? options.ry : options.rx;
|
12 |
|
13 | return "M" + (x + rx) + "," + y +
|
14 | " H" + (w - rx) +
|
15 | " C" + (w - rx) + "," + y + " " + w + "," + y + " " + w + "," + (y + ry) +
|
16 | " V" + (h - ry) +
|
17 | " C" + w + "," + (h - ry) + " " + w + "," + h + " " + (w - rx) + "," + h +
|
18 | " H" + (x + rx) +
|
19 | " C" + (x + rx) + "," + h + " " + x + "," + h + " " + x + "," + (h - ry) +
|
20 | " V" + (y + ry) +
|
21 | " C" + x + "," + (y + ry) + " " + x + "," + y + " " + (x + rx) + "," + y;
|
22 | } else {
|
23 | return "M" + x + "," + y + " H" + w + " V" + h + " H" + x + " Z";
|
24 | }
|
25 |
|
26 | }
|