@antv/g-math
Advanced tools
Comparing version 1.0.0-alpha.4 to 1.0.0-alpha.5
@@ -1,17 +0,5 @@ | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
import { __read } from "tslib"; | ||
import { distance, piMod } from './util'; | ||
import ellipse from './ellipse'; | ||
import ellipse from './ellipse'; // 偏导数 x | ||
// 偏导数 x | ||
function derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) { | ||
@@ -100,4 +88,4 @@ return -1 * rx * Math.cos(xRotation) * Math.sin(angle) - ry * Math.sin(xRotation) * Math.cos(angle); | ||
for (var _i = 0; _i < xs.length; _i++) { | ||
var x = xAt(cx, cy, rx, ry, xRotation, xs[_i]); | ||
for (var i = 0; i < xs.length; i++) { | ||
var x = xAt(cx, cy, rx, ry, xRotation, xs[i]); | ||
@@ -118,4 +106,4 @@ if (x < minX) { | ||
for (var _i2 = -Math.PI * 2; _i2 <= Math.PI * 2; _i2 += Math.PI) { | ||
var yAngle = yDim + _i2; | ||
for (var i = -Math.PI * 2; i <= Math.PI * 2; i += Math.PI) { | ||
var yAngle = yDim + i; | ||
@@ -133,4 +121,4 @@ if (startAngle < endAngle) { | ||
for (var _i3 = 0; _i3 < ys.length; _i3++) { | ||
var y = yAt(cx, cy, rx, ry, xRotation, ys[_i3]); | ||
for (var i = 0; i < ys.length; i++) { | ||
var y = yAt(cx, cy, rx, ry, xRotation, ys[i]); | ||
@@ -184,5 +172,5 @@ if (y < minY) { | ||
var _relativeVector = _slicedToArray(relativeVector, 2), | ||
x1 = _relativeVector[0], | ||
y1 = _relativeVector[1]; // 计算点到椭圆的最近的点 | ||
var _a = __read(relativeVector, 2), | ||
x1 = _a[0], | ||
y1 = _a[1]; // 计算点到椭圆的最近的点 | ||
@@ -189,0 +177,0 @@ |
@@ -55,3 +55,3 @@ import { distance } from './util'; | ||
for (var _i = 0; _i < 32; _i++) { | ||
for (var i = 0; i < 32; i++) { | ||
if (interval < EPSILON) { | ||
@@ -63,9 +63,8 @@ break; | ||
var next = t + interval; | ||
var _v = [tCallback.apply(null, xArr.concat([prev])), tCallback.apply(null, yArr.concat([prev]))]; | ||
var v1 = [tCallback.apply(null, xArr.concat([prev])), tCallback.apply(null, yArr.concat([prev]))]; | ||
var d1 = distance(v0[0], v0[1], v1[0], v1[1]); | ||
var _d = distance(v0[0], v0[1], _v[0], _v[1]); | ||
if (prev >= 0 && _d < d) { | ||
if (prev >= 0 && d1 < d) { | ||
t = prev; | ||
d = _d; | ||
d = d1; | ||
} else { | ||
@@ -72,0 +71,0 @@ var v2 = [tCallback.apply(null, xArr.concat([next])), tCallback.apply(null, yArr.concat([next]))]; |
@@ -1,13 +0,2 @@ | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
import { __read, __spreadArray } from "tslib"; | ||
import { distance, isNumberEqual, getBBoxByArray, piMod } from './util'; | ||
@@ -89,4 +78,7 @@ import line from './line'; | ||
var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5); | ||
var left = [].concat(_toConsumableArray(cubics[0]), [iterationCount - 1]); | ||
var right = [].concat(_toConsumableArray(cubics[1]), [iterationCount - 1]); | ||
var left = __spreadArray(__spreadArray([], __read(cubics[0])), [iterationCount - 1]); | ||
var right = __spreadArray(__spreadArray([], __read(cubics[1])), [iterationCount - 1]); | ||
return cubicLength.apply(null, left) + cubicLength.apply(null, right); | ||
@@ -107,4 +99,4 @@ } | ||
for (var _i = 0; _i < yExtrema.length; _i++) { | ||
yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i])); | ||
for (var i = 0; i < yExtrema.length; i++) { | ||
yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[i])); | ||
} | ||
@@ -111,0 +103,0 @@ |
import line from './line'; | ||
import { distance, isNumberEqual, getBBoxByArray, piMod } from './util'; | ||
import { nearestPoint as _nearestPoint } from './bezier'; | ||
import { nearestPoint as _nearestPoint } from './bezier'; // 差值公式 | ||
// 差值公式 | ||
function quadraticAt(p0, p1, p2, t) { | ||
@@ -7,0 +6,0 @@ var onet = 1 - t; |
@@ -12,10 +12,10 @@ import line from './line'; | ||
var to = points[i + 1]; | ||
var length = distance(from[0], from[1], to[0], to[1]); | ||
var length_1 = distance(from[0], from[1], to[0], to[1]); | ||
var seg = { | ||
from: from, | ||
to: to, | ||
length: length | ||
length: length_1 | ||
}; | ||
segments.push(seg); | ||
totalLength += length; | ||
totalLength += length_1; | ||
} | ||
@@ -57,5 +57,5 @@ | ||
var _analyzePoints = analyzePoints(points), | ||
segments = _analyzePoints.segments, | ||
totalLength = _analyzePoints.totalLength; // 多个点有可能重合 | ||
var _a = analyzePoints(points), | ||
segments = _a.segments, | ||
totalLength = _a.totalLength; // 多个点有可能重合 | ||
@@ -103,5 +103,5 @@ | ||
var _analyzePoints2 = analyzePoints(points), | ||
segments = _analyzePoints2.segments, | ||
totalLength = _analyzePoints2.totalLength; // 计算比例 | ||
var _a = analyzePoints(points), | ||
segments = _a.segments, | ||
totalLength = _a.totalLength; // 计算比例 | ||
@@ -134,7 +134,6 @@ | ||
var nextPoint = points[i + 1]; | ||
var distance_1 = line.pointDistance(point[0], point[1], nextPoint[0], nextPoint[1], x, y); | ||
var _distance = line.pointDistance(point[0], point[1], nextPoint[0], nextPoint[1], x, y); | ||
if (_distance < minDistance) { | ||
minDistance = _distance; | ||
if (distance_1 < minDistance) { | ||
minDistance = distance_1; | ||
} | ||
@@ -141,0 +140,0 @@ } |
import { max, min } from '@antv/util'; | ||
/** | ||
@@ -11,2 +10,3 @@ * 两点之间的距离 | ||
*/ | ||
export function distance(x1, y1, x2, y2) { | ||
@@ -13,0 +13,0 @@ var dx = x1 - x2; |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _tslib = require("tslib"); | ||
var _util = require("./util"); | ||
@@ -15,14 +17,2 @@ | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
// 偏导数 x | ||
@@ -112,4 +102,4 @@ function derivativeXAt(cx, cy, rx, ry, xRotation, startAngle, endAngle, angle) { | ||
for (var _i = 0; _i < xs.length; _i++) { | ||
var x = xAt(cx, cy, rx, ry, xRotation, xs[_i]); | ||
for (var i = 0; i < xs.length; i++) { | ||
var x = xAt(cx, cy, rx, ry, xRotation, xs[i]); | ||
@@ -130,4 +120,4 @@ if (x < minX) { | ||
for (var _i2 = -Math.PI * 2; _i2 <= Math.PI * 2; _i2 += Math.PI) { | ||
var yAngle = yDim + _i2; | ||
for (var i = -Math.PI * 2; i <= Math.PI * 2; i += Math.PI) { | ||
var yAngle = yDim + i; | ||
@@ -145,4 +135,4 @@ if (startAngle < endAngle) { | ||
for (var _i3 = 0; _i3 < ys.length; _i3++) { | ||
var y = yAt(cx, cy, rx, ry, xRotation, ys[_i3]); | ||
for (var i = 0; i < ys.length; i++) { | ||
var y = yAt(cx, cy, rx, ry, xRotation, ys[i]); | ||
@@ -196,5 +186,5 @@ if (y < minY) { | ||
var _relativeVector = _slicedToArray(relativeVector, 2), | ||
x1 = _relativeVector[0], | ||
y1 = _relativeVector[1]; // 计算点到椭圆的最近的点 | ||
var _a = (0, _tslib.__read)(relativeVector, 2), | ||
x1 = _a[0], | ||
y1 = _a[1]; // 计算点到椭圆的最近的点 | ||
@@ -201,0 +191,0 @@ |
@@ -64,3 +64,3 @@ "use strict"; | ||
for (var _i = 0; _i < 32; _i++) { | ||
for (var i = 0; i < 32; i++) { | ||
if (interval < EPSILON) { | ||
@@ -72,9 +72,8 @@ break; | ||
var next = t + interval; | ||
var _v = [tCallback.apply(null, xArr.concat([prev])), tCallback.apply(null, yArr.concat([prev]))]; | ||
var v1 = [tCallback.apply(null, xArr.concat([prev])), tCallback.apply(null, yArr.concat([prev]))]; | ||
var d1 = (0, _util.distance)(v0[0], v0[1], v1[0], v1[1]); | ||
var _d = (0, _util.distance)(v0[0], v0[1], _v[0], _v[1]); | ||
if (prev >= 0 && _d < d) { | ||
if (prev >= 0 && d1 < d) { | ||
t = prev; | ||
d = _d; | ||
d = d1; | ||
} else { | ||
@@ -81,0 +80,0 @@ var v2 = [tCallback.apply(null, xArr.concat([next])), tCallback.apply(null, yArr.concat([next]))]; |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _tslib = require("tslib"); | ||
var _util = require("./util"); | ||
@@ -17,14 +19,2 @@ | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function cubicAt(p0, p1, p2, p3, t) { | ||
@@ -107,4 +97,4 @@ var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍 | ||
var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5); | ||
var left = [].concat(_toConsumableArray(cubics[0]), [iterationCount - 1]); | ||
var right = [].concat(_toConsumableArray(cubics[1]), [iterationCount - 1]); | ||
var left = (0, _tslib.__spreadArray)((0, _tslib.__spreadArray)([], (0, _tslib.__read)(cubics[0])), [iterationCount - 1]); | ||
var right = (0, _tslib.__spreadArray)((0, _tslib.__spreadArray)([], (0, _tslib.__read)(cubics[1])), [iterationCount - 1]); | ||
return cubicLength.apply(null, left) + cubicLength.apply(null, right); | ||
@@ -125,4 +115,4 @@ } | ||
for (var _i = 0; _i < yExtrema.length; _i++) { | ||
yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i])); | ||
for (var i = 0; i < yExtrema.length; i++) { | ||
yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[i])); | ||
} | ||
@@ -129,0 +119,0 @@ |
@@ -25,10 +25,10 @@ "use strict"; | ||
var to = points[i + 1]; | ||
var length = (0, _util.distance)(from[0], from[1], to[0], to[1]); | ||
var length_1 = (0, _util.distance)(from[0], from[1], to[0], to[1]); | ||
var seg = { | ||
from: from, | ||
to: to, | ||
length: length | ||
length: length_1 | ||
}; | ||
segments.push(seg); | ||
totalLength += length; | ||
totalLength += length_1; | ||
} | ||
@@ -71,5 +71,5 @@ | ||
var _analyzePoints = analyzePoints(points), | ||
segments = _analyzePoints.segments, | ||
totalLength = _analyzePoints.totalLength; // 多个点有可能重合 | ||
var _a = analyzePoints(points), | ||
segments = _a.segments, | ||
totalLength = _a.totalLength; // 多个点有可能重合 | ||
@@ -118,5 +118,5 @@ | ||
var _analyzePoints2 = analyzePoints(points), | ||
segments = _analyzePoints2.segments, | ||
totalLength = _analyzePoints2.totalLength; // 计算比例 | ||
var _a = analyzePoints(points), | ||
segments = _a.segments, | ||
totalLength = _a.totalLength; // 计算比例 | ||
@@ -151,6 +151,6 @@ | ||
var _distance = _line.default.pointDistance(point[0], point[1], nextPoint[0], nextPoint[1], x, y); | ||
var distance_1 = _line.default.pointDistance(point[0], point[1], nextPoint[0], nextPoint[1], x, y); | ||
if (_distance < minDistance) { | ||
minDistance = _distance; | ||
if (distance_1 < minDistance) { | ||
minDistance = distance_1; | ||
} | ||
@@ -157,0 +157,0 @@ } |
@@ -1,1 +0,5 @@ | ||
"use strict"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); |
{ | ||
"name": "@antv/g-math", | ||
"version": "1.0.0-alpha.4", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Geometry util", | ||
@@ -40,3 +40,3 @@ "main": "lib/index.js", | ||
"homepage": "https://github.com/antvis/g#readme", | ||
"gitHead": "bfcb87639cfb109825e1d4515ffef6ea48e2b65f" | ||
"gitHead": "9dd75b27ba6bf0c42256b1971cde602a765e7f23" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115871
58
3230