UNPKG

grommet

Version:

focus on the essential experience

39 lines (37 loc) 1.9 kB
"use strict"; exports.__esModule = true; exports.translateEndAngle = exports.polarToCartesian = exports.baseUnit = exports.arcCommands = void 0; var POST_DECIMAL_DIGITS = 10; var baseUnit = exports.baseUnit = 24; var polarToCartesian = exports.polarToCartesian = function polarToCartesian(centerX, centerY, radius, angleInDegrees) { var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0; return { x: centerX + radius * Math.cos(angleInRadians), y: centerY + radius * Math.sin(angleInRadians) }; }; var arcCommands = exports.arcCommands = function arcCommands(centerX, centerY, radius, startAngle, endAngle) { // handle that we can't draw a complete circle var normalizedEndAngle = endAngle; /* added endAngle - startAngle >= 360 for SemiCircle the endAngle will never be greater then startAngle since it starts with a startAngle of 270. */ if (endAngle > startAngle && endAngle - startAngle >= 360) { normalizedEndAngle = startAngle + 359.99; } var start = polarToCartesian(centerX, centerY, radius, normalizedEndAngle); var end = polarToCartesian(centerX, centerY, radius, startAngle); var arcSweep = normalizedEndAngle - startAngle <= 180 ? '0' : '1'; var d = ['M', start.x.toFixed(POST_DECIMAL_DIGITS), start.y.toFixed(POST_DECIMAL_DIGITS), 'A', radius.toFixed(POST_DECIMAL_DIGITS), radius.toFixed(POST_DECIMAL_DIGITS), 0, arcSweep, 0, end.x.toFixed(POST_DECIMAL_DIGITS), end.y.toFixed(POST_DECIMAL_DIGITS)].join(' '); return d; }; /* TranslatedEngAngle will now take the value of the startAngle + anglePer * value and mod by 360. This was added to take account the startAngle not being 0. So no matter the value it will be % 360 to get the correct angle. */ var translateEndAngle = exports.translateEndAngle = function translateEndAngle(startAngle, anglePer, value) { return Math.max(0, startAngle + anglePer * value) % 360; };