MCPcopy
hub / github.com/Yqnn/svg-path-editor / rotate

Method rotate

src/lib/svg.ts:543–578  ·  view source on GitHub ↗
(ox: number, oy: number, degrees: number)

Source from the content-addressed store, hash-verified

541 }
542
543 rotate(ox: number, oy: number, degrees: number): SvgPath {
544 degrees %= 360;
545 if (degrees == 0) {
546 return this;
547 }
548
549 if (degrees !== 180) {
550 this.path.forEach( (it) => {
551 if (it instanceof HorizontalLineTo || it instanceof VerticalLineTo) {
552 const newType = (it.relative ? 'l' : 'L');
553 this.changeType(it, newType);
554 }
555 });
556 }
557
558 this.path.forEach( (it, idx) => {
559 const lastInstanceOf = it.constructor;
560 it.rotate(ox, oy, degrees, idx === 0);
561
562 if (degrees === 90 || degrees === 270) {
563 if (lastInstanceOf === HorizontalLineTo) {
564 this.refreshAbsolutePositions();
565
566 const newType = (it.relative ? 'v' : 'V');
567 this.changeType(it, newType);
568 } else if (lastInstanceOf === VerticalLineTo) {
569 this.refreshAbsolutePositions();
570
571 const newType = (it.relative ? 'h' : 'H');
572 this.changeType(it, newType);
573 }
574 }
575 });
576 this.refreshAbsolutePositions();
577 return this;
578 }
579
580 setRelative(newRelative: boolean) {
581 this.path.forEach( (it) => {

Callers

nothing calls this directly

Calls 2

changeTypeMethod · 0.95

Tested by

no test coverage detected