From 61e9a38aa795573ad77b5d3d44f913b106a08f2f Mon Sep 17 00:00:00 2001 From: xile611 Date: Tue, 16 Jul 2024 17:50:56 +0800 Subject: [PATCH] fix: export mergebase --- .../__tests__/graphics/intersect.test.ts | 40 +++++++++++++++++++ packages/vutils/src/common/index.ts | 2 +- packages/vutils/src/common/merge.ts | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 packages/vutils/__tests__/graphics/intersect.test.ts diff --git a/packages/vutils/__tests__/graphics/intersect.test.ts b/packages/vutils/__tests__/graphics/intersect.test.ts new file mode 100644 index 0000000..cc48739 --- /dev/null +++ b/packages/vutils/__tests__/graphics/intersect.test.ts @@ -0,0 +1,40 @@ +import { + isIntersect, + getIntersectPoint, + getRectIntersect, + rectInsideAnotherRect, + isRectIntersect, + pointInRect, + isRotateAABBIntersect +} from '../../src'; + +describe('intersects', () => { + it('isIntersect', () => { + expect(isIntersect([0, 0], [100, 100], [50, 20], [0, 100])).toBeTruthy(); + }); + + it('getIntersectPoint', () => { + const p = getIntersectPoint([0, 0], [100, 100], [50, 20], [0, 100]); + expect(p[0]).toBeCloseTo(38.46153846153847); + expect(p[1]).toBeCloseTo(38.46153846153847); + }); + + it('getRectIntersect', () => { + const p = getRectIntersect( + { + x1: 0, + x2: 50, + y1: 0, + y2: 100 + }, + { + x1: 30, + y1: 30, + x2: 100, + y2: 150 + }, + true + ); + expect(p).toEqual({ x1: 30, x2: 50, y1: 30, y2: 100 }); + }); +}); diff --git a/packages/vutils/src/common/index.ts b/packages/vutils/src/common/index.ts index fd56590..b467eaa 100644 --- a/packages/vutils/src/common/index.ts +++ b/packages/vutils/src/common/index.ts @@ -27,7 +27,7 @@ export { default as get } from './get'; export { default as has } from './has'; export { default as clone } from './clone'; export { default as cloneDeep } from './cloneDeep'; -export { default as merge } from './merge'; +export { default as merge, baseMerge } from './merge'; export { default as pick } from './pick'; export { default as pickWithout } from './pickWithout'; export { isEqual } from './isEqual'; diff --git a/packages/vutils/src/common/merge.ts b/packages/vutils/src/common/merge.ts index 432e86c..3f39a29 100644 --- a/packages/vutils/src/common/merge.ts +++ b/packages/vutils/src/common/merge.ts @@ -3,7 +3,7 @@ import isArrayLike from './isArrayLike'; import isPlainObject from './isPlainObject'; import isValid from './isValid'; -function baseMerge(target: any, source: any, shallowArray: boolean = false, skipTargetArray: boolean = false) { +export function baseMerge(target: any, source: any, shallowArray: boolean = false, skipTargetArray: boolean = false) { if (source) { if (target === source) { return;