🎥 Make videos programmatically with React
reduced instruction
Jonny Burger52a2da5aed7f
diff --git a/packages/paths/src/get-bounding-box.ts b/packages/paths/src/get-bounding-box.tsindex 6bd9d745c6..a90b2b0a6e 100644--- a/packages/paths/src/get-bounding-box.ts+++ b/packages/paths/src/get-bounding-box.ts@@ -1,4 +1,4 @@-import {removeATSInstructions} from './helpers/remove-a-s-t-curves';+import {removeATSHVInstructions} from './helpers/remove-a-s-t-curves';import type {AbsoluteInstruction, BoundingBox} from './helpers/types';import {normalizePath} from './normalize-path';import {parsePath} from './parse-path';@@ -90,7 +90,7 @@ export const getBoundingBox = (d: string): BoundingBox => {let maxX = -Infinity;let maxY = -Infinity;const parsed = parsePath(normalizePath(d)) as AbsoluteInstruction[];- const unarced = removeATSInstructions(parsed);+ const unarced = removeATSHVInstructions(parsed);let x = 0;let y = 0;@@ -121,34 +121,6 @@ export const getBoundingBox = (d: string): BoundingBox => {break;}- case 'V': {- if (minY > seg.y) {- minY = seg.y;- }-- if (maxY < seg.y) {- maxY = seg.y;- }-- y = seg.y;-- break;- }-- case 'H': {- if (minX > seg.x) {- minX = seg.x;- }-- if (maxX < seg.x) {- maxX = seg.x;- }-- x = seg.x;-- break;- }-case 'C': {const cxMinMax = minmaxC([x, seg.cp1x, seg.cp2x, seg.x]);if (minX > cxMinMax[0]) {diff --git a/packages/paths/src/helpers/iterate.ts b/packages/paths/src/helpers/iterate.tsindex e4359d25a6..7fe4e41f0a 100644--- a/packages/paths/src/helpers/iterate.ts+++ b/packages/paths/src/helpers/iterate.ts@@ -1,6 +1,6 @@-import type {AbsoluteInstruction, ReducesAbsoluteInstruction} from './types';+import type {AbsoluteInstruction, ReducedInstruction} from './types';-export const iterateOverSegments = <T extends ReducesAbsoluteInstruction>({+export const iterateOverSegments = <T extends ReducedInstruction>({segments,iterate,}: {diff --git a/packages/paths/src/helpers/remove-a-s-t-curves.ts b/packages/paths/src/helpers/remove-a-s-t-curves.tsindex 33836260b6..b9abe77e13 100644--- a/packages/paths/src/helpers/remove-a-s-t-curves.ts+++ b/packages/paths/src/helpers/remove-a-s-t-curves.ts@@ -1,5 +1,5 @@import {iterateOverSegments} from './iterate';-import type {AbsoluteInstruction, ReducesAbsoluteInstruction} from './types';+import type {AbsoluteInstruction, ReducedInstruction} from './types';const TAU = Math.PI * 2;@@ -131,13 +131,13 @@ function arcToCircle({// Requires path to be normalizedexport const removeATSHVInstructions = (segments: AbsoluteInstruction[]-): ReducesAbsoluteInstruction[] => {+): ReducedInstruction[] => {let prevControlX = 0;let prevControlY = 0;let curControlX = 0;let curControlY = 0;- return iterateOverSegments<ReducesAbsoluteInstruction>({+ return iterateOverSegments<ReducedInstruction>({segments,iterate: ({segment, prevSegment, x, y}) => {if (segment.type === 'H') {@@ -175,7 +175,7 @@ export const removeATSHVInstructions = (];}- const result = new_segments.map((_s): ReducesAbsoluteInstruction => {+ const result = new_segments.map((_s): ReducedInstruction => {return {type: 'C',cp1x: _s[2],diff --git a/packages/paths/src/helpers/types.ts b/packages/paths/src/helpers/types.tsindex 35831d39b5..081a1dd2c4 100644--- a/packages/paths/src/helpers/types.ts+++ b/packages/paths/src/helpers/types.ts@@ -26,7 +26,7 @@ export interface PointProperties {export type BoundingBox = {x1: number; y1: number; x2: number; y2: number};-export type ReducesAbsoluteInstruction =+export type ReducedInstruction =| {type: 'M';x: number;@@ -58,7 +58,7 @@ export type ReducesAbsoluteInstruction =};export type AbsoluteInstruction =- | ReducesAbsoluteInstruction+ | ReducedInstruction| {type: 'A';rx: number;