diff --git a/src/ArcCollection.ts b/src/ArcCollection.ts index 846f9d3..9c6ce6e 100644 --- a/src/ArcCollection.ts +++ b/src/ArcCollection.ts @@ -13,7 +13,6 @@ import { error, initializeArray, intersectSegments, - utilsForEach, } from "./utils"; export type ArcCollection = { @@ -255,13 +254,16 @@ export function ArcCollection$findSegmentIntersections(self: ArcCollection) { self, stripeSizes.reduce((acc, cur) => acc + cur, 0), ); - let offs = 0; - const stripes: any[] = []; - utilsForEach(stripeSizes, (stripeSize: number) => { - const start = offs; - offs += stripeSize; - stripes.push(stripeData.subarray(start, offs)); - }); + let offset = 0; + + const stripes: Uint32Array[] = []; + for (let i = 0; i < stripeSizes.length; i++) { + const stripeSize = stripeSizes[i]; + const start = offset; + offset += stripeSize; + stripes.push(stripeData.subarray(start, offset)); + } + // Assign segment ids to each stripe initializeArray(stripeSizes, 0); ArcCollection$forEachSegment( diff --git a/src/utils.ts b/src/utils.ts index e93f980..511383c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,35 +1,8 @@ -// @kobakazu0429----utils.ts export function error(...args: any[]) { const msg = args.join(" "); throw new Error(msg); } -export function isArrayLike(obj: any) { - if (!obj) return false; - if (isArray(obj)) return true; - if (isString(obj)) return false; - if (obj.length === 0) return true; - return obj.length > 0; -} - -function isString(obj: any) { - return obj != null && obj.toString === String.prototype.toString; -} - -function isArray(obj: any) { - return Array.isArray(obj); -} - -// Support for iterating over array-like objects, like typed arrays -export function utilsForEach(arr: any, func: any, ctx?: any) { - if (!isArrayLike(arr)) { - throw new Error(`#forEach() takes an array-like argument. ${arr}`); - } - for (let i = 0, n = arr.length; i < n; i++) { - func.call(ctx, arr[i], i); - } -} - export function initializeArray(arr: any, init: any) { for (let i = 0, len = arr.length; i < len; i++) { arr[i] = init;