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

이슈 8773 처리 #2863

Merged
merged 1 commit into from
Nov 11, 2024
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
12 changes: 6 additions & 6 deletions src/playground/blocks/block_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,22 +745,17 @@ module.exports = {
class: 'calc',
isNotFor: [],
func(sprite, script) {
let value = script.getNumberValue('LEFTHAND', script);
const value = script.getNumberValue('LEFTHAND', script);
let operator = script.getField('VALUE', script);
const xRangeCheckList = ['asin_radian', 'acos_radian'];
if (xRangeCheckList.indexOf(operator) > -1 && (value > 1 || value < -1)) {
throw new Error('x range exceeded');
}

const needToConvertList = ['sin', 'cos', 'tan'];
if (operator.indexOf('_')) {
operator = operator.split('_')[0];
}

if (needToConvertList.indexOf(operator) > -1) {
value = Entry.toRadian(value);
}

let returnVal = 0;
switch (operator) {
case 'square':
Expand All @@ -783,6 +778,11 @@ module.exports = {
case 'atan':
returnVal = Entry.toDegrees(Math[operator](value));
break;
case 'sin':
case 'cos':
case 'tan':
returnVal = Entry.preciseTrig(value, operator);
break;
case 'unnatural': {
returnVal = new BigNumber(value).minus(Math.floor(value));
returnVal = returnVal.toNumber();
Expand Down
73 changes: 73 additions & 0 deletions src/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,79 @@ Entry.toDegrees = function (radians) {
return (radians * 180) / Math.PI;
};

const TRIG_VALUES = {
sin: {
0: 0,
30: 0.5,
45: Math.SQRT2 / 2,
60: Math.SQRT3 / 2,
90: 1,
120: Math.SQRT3 / 2,
135: Math.SQRT2 / 2,
150: 0.5,
180: 0,
210: -0.5,
225: -Math.SQRT2 / 2,
240: -Math.SQRT3 / 2,
270: -1,
300: -Math.SQRT3 / 2,
315: -Math.SQRT2 / 2,
330: -0.5,
360: 0,
},
cos: {
0: 1,
30: Math.SQRT3 / 2,
45: Math.SQRT2 / 2,
60: 0.5,
90: 0,
120: -0.5,
135: -Math.SQRT2 / 2,
150: -Math.SQRT3 / 2,
180: -1,
210: -Math.SQRT3 / 2,
225: -Math.SQRT2 / 2,
240: -0.5,
270: 0,
300: 0.5,
315: Math.SQRT2 / 2,
330: Math.SQRT3 / 2,
360: 1,
},
tan: {
0: 0,
30: Math.sqrt(3) / 3,
45: 1,
60: Math.sqrt(3),
90: Infinity,
120: -Math.sqrt(3),
135: -1,
150: -Math.sqrt(3) / 3,
180: 0,
210: Math.sqrt(3) / 3,
225: 1,
240: Math.sqrt(3),
270: -Infinity,
300: -Math.sqrt(3),
315: -1,
330: -Math.sqrt(3) / 3,
360: 0,
},
};

Entry.preciseTrig = (degrees, operator) => {
const angle = degrees % 360;

if (
TRIG_VALUES[operator] &&
Object.prototype.hasOwnProperty.call(TRIG_VALUES[operator], angle)
) {
return TRIG_VALUES[operator][angle];
}

return Math[operator](Entry.toRadian(angle));
};

Entry.getPicturesJSON = function (pictures = [], isClone) {
return pictures.reduce((acc, p) => {
const o = {};
Expand Down
Loading