Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复极大数量求最大值、最小值出错 #727

Merged
merged 3 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/g-base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-base",
"version": "0.5.5",
"version": "0.5.6",
"description": "A common util collection for antv projects",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
17 changes: 9 additions & 8 deletions packages/g-base/src/abstract/container.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { max, min } from '@antv/util';
import { IContainer, IShape, IGroup, IElement, ICanvas } from '../interfaces';
import { BBox, ElementFilterFn } from '../types';
import Timeline from '../animate/timeline';
Expand Down Expand Up @@ -89,10 +90,10 @@ abstract class Container extends Element implements IContainer {
xArr.push(box.minX, box.maxX);
yArr.push(box.minY, box.maxY);
});
minX = Math.min.apply(null, xArr);
maxX = Math.max.apply(null, xArr);
minY = Math.min.apply(null, yArr);
maxY = Math.max.apply(null, yArr);
minX = min(xArr);
maxX = max(xArr);
minY = min(yArr);
maxY = max(yArr);
} else {
minX = 0;
maxX = 0;
Expand Down Expand Up @@ -131,10 +132,10 @@ abstract class Container extends Element implements IContainer {
xArr.push(box.minX, box.maxX);
yArr.push(box.minY, box.maxY);
});
minX = Math.min.apply(null, xArr);
maxX = Math.max.apply(null, xArr);
minY = Math.min.apply(null, yArr);
maxY = Math.max.apply(null, yArr);
minX = min(xArr);
maxX = max(xArr);
minY = min(yArr);
maxY = max(yArr);
} else {
minX = 0;
maxX = 0;
Expand Down
10 changes: 5 additions & 5 deletions packages/g-base/src/bbox/path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Quad as QuadUtil, Cubic as CubicUtil, Arc as EllipseArcUtil } from '@antv/g-math';
import { path2Segments } from '@antv/path-util';
import { isNumberEqual } from '@antv/util';
import { isNumberEqual, max, min } from '@antv/util';
import { SimpleBBox } from '../types';
import { IShape } from '../interfaces';
import { mergeArrowBBox } from './util';
Expand Down Expand Up @@ -50,10 +50,10 @@ function getPathBox(segments, lineWidth) {
// ref: https://github.com/antvis/g/issues/210
xArr = xArr.filter((item) => !Number.isNaN(item));
yArr = yArr.filter((item) => !Number.isNaN(item));
let minX = Math.min.apply(null, xArr);
let minY = Math.min.apply(null, yArr);
let maxX = Math.max.apply(null, xArr);
let maxY = Math.max.apply(null, yArr);
let minX = min(xArr);
let minY = min(yArr);
let maxX = max(xArr);
let maxY = max(yArr);
if (segmentsWithAngle.length === 0) {
return {
x: minX,
Expand Down
2 changes: 1 addition & 1 deletion packages/g-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export { isAllowCapture } from './util/util';
export { multiplyVec2, invert } from './util/matrix';
export { getOffScreenContext } from './util/offscreen';

export const version = '0.5.5';
export const version = '0.5.6';
2 changes: 1 addition & 1 deletion packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "0.5.6",
"version": "0.5.7",
"description": "A canvas library which providing 2d",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
10 changes: 5 additions & 5 deletions packages/g-canvas/src/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Region } from './types';
import ShapeBase from './shape/base';
import * as Shape from './shape';
import { applyAttrsToContext, drawChildren, refreshElement } from './util/draw';
import { each } from '@antv/util';
import { each, max, min } from '@antv/util';
import { intersectRect } from './util/util';

class Group extends AbstractGroup {
Expand Down Expand Up @@ -57,10 +57,10 @@ class Group extends AbstractGroup {
});
let bbox = null;
if (xArr.length) {
const minX = Math.min.apply(null, xArr);
const maxX = Math.max.apply(null, xArr);
const minY = Math.min.apply(null, yArr);
const maxY = Math.max.apply(null, yArr);
const minX = min(xArr);
const maxX = max(xArr);
const minY = min(yArr);
const maxY = max(yArr);
bbox = {
minX,
minY,
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export { default as Group } from './group';
export { Shape };
export { default as getArcParams } from './util/arc-params';

export const version = '0.5.6';
export const version = '0.5.7';
14 changes: 7 additions & 7 deletions packages/g-canvas/src/util/draw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { each, isArray } from '@antv/util';
import { IElement, IGroup } from '../interfaces';
import { each, isArray, max, min } from '@antv/util';
import { IElement } from '../interfaces';
import { Region } from '../types';
import { parseStyle } from './parse';
import getArcParams from './arc-params';
Expand Down Expand Up @@ -265,7 +265,7 @@ export function refreshElement(element, changeType) {
}
}

export function getRefreshRegion(element) {
export function getRefreshRegion(element): Region | undefined {
let region;
if (!element.destroyed) {
const cacheBox = element.get('cacheCanvasBBox');
Expand Down Expand Up @@ -305,10 +305,10 @@ export function getMergedRegion(elements): Region {
}
});
return {
minX: Math.min.apply(null, minXArr),
minY: Math.min.apply(null, minYArr),
maxX: Math.max.apply(null, maxXArr),
maxY: Math.max.apply(null, maxYArr),
minX: min(minXArr),
minY: min(minYArr),
maxX: max(maxXArr),
maxY: max(maxYArr),
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/g-math/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-math",
"version": "0.1.7",
"version": "0.1.8",
"description": "geometry math",
"main": "lib/index.js",
"module": "esm/index.js",
Expand Down
25 changes: 9 additions & 16 deletions packages/g-math/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { max, min } from '@antv/util';
import { BBox } from './types';

function minNum(array: number[]) {
return Math.min.apply(null, array);
}

function maxNum(array: number[]) {
return Math.max.apply(null, array);
}

/**
* 两点之间的距离
* @param {number} x1 起始点 x
Expand All @@ -27,10 +20,10 @@ export function isNumberEqual(v1: number, v2: number) {
}

export function getBBoxByArray(xArr: number[], yArr: number[]): BBox {
const minX = minNum(xArr);
const minY = minNum(yArr);
const maxX = maxNum(xArr);
const maxY = maxNum(yArr);
const minX = min(xArr);
const minY = min(yArr);
const maxX = max(xArr);
const maxY = max(yArr);
return {
x: minX,
y: minY,
Expand All @@ -41,10 +34,10 @@ export function getBBoxByArray(xArr: number[], yArr: number[]): BBox {

export function getBBoxRange(x1: number, y1: number, x2: number, y2: number) {
return {
minX: minNum([x1, x2]),
maxX: maxNum([x1, x2]),
minY: minNum([y1, y2]),
maxY: maxNum([y1, y2]),
minX: min([x1, x2]),
maxX: max([x1, x2]),
minY: min([y1, y2]),
maxY: max([y1, y2]),
};
}

Expand Down