Skip to content

Commit

Permalink
Use Iterable instead of Array
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Feb 27, 2024
1 parent 656b997 commit 20a25d6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export namespace Arc {

export function divideAtTimes(
arc: SimpleSegmentA,
times: number[]
times: Iterable<number>
): VertexA[] {
const [, xAxisRotation, , sweep] = arc.args
const {radii, center, angles} = toCenterParameterization(arc)
Expand Down
8 changes: 3 additions & 5 deletions src/CubicBezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {SegmentLocation} from './Location'
import {VertexC} from './Path'
import {SegmentC} from './Segment'
import {memoize, PartialBy} from './utils'
import {Iter} from './Iter'

/**
* Almost equivalent to {@link SegmentC}, but the redundant `command` field can be ommited. Used for the argument of CubicBezier functions.
Expand Down Expand Up @@ -196,16 +197,13 @@ export namespace CubicBezier {

export function divideAtTimes(
segment: SimpleSegmentC,
times: number[]
times: Iterable<number>
): VertexC[] {
times = [0, ...times, 1]

const vertices: VertexC[] = []

for (let i = 1; i < times.length; i++) {
const from = times[i - 1]
const to = times[i]

for (const [from, to] of Iter.tuple(times)) {
const [, c1, c2, point] = trimBetweenTimes(segment, from, to)

vertices.push({command: 'C', args: [c1, c2], point})
Expand Down
2 changes: 1 addition & 1 deletion src/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export namespace Line {

export function divideAtTimes(
line: SimpleSegmentL,
times: number[]
times: Iterable<number>
): VertexL[] {
return [...times, 1].map(t => {
return {point: vec2.lerp(line.start, line.point, t), command: 'L'}
Expand Down

0 comments on commit 20a25d6

Please sign in to comment.