Add new atan2 block (PR #2079)

Merge pull request from nadyafebi/add-atan2-support-1835
This commit is contained in:
Andrew n marshall
2018-10-16 11:27:00 -07:00
committed by GitHub
16 changed files with 223 additions and 0 deletions

View File

@@ -485,3 +485,15 @@ Blockly.Dart['math_random_float'] = function(block) {
'import \'dart:math\' as Math;';
return ['new Math.Random().nextDouble()', Blockly.Dart.ORDER_UNARY_POSTFIX];
};
Blockly.Dart['math_atan2'] = function(block) {
// Arctangent of point (X, Y) in degrees from -180 to 180.
Blockly.Dart.definitions_['import_dart_math'] =
'import \'dart:math\' as Math;';
var argument0 = Blockly.Dart.valueToCode(block, 'X',
Blockly.Dart.ORDER_NONE) || '0';
var argument1 = Blockly.Dart.valueToCode(block, 'Y',
Blockly.Dart.ORDER_NONE) || '0';
return ['Math.atan2(' + argument1 + ', ' + argument0 + ') / Math.pi * 180',
Blockly.Dart.ORDER_MULTIPLICATIVE];
};

View File

@@ -411,3 +411,13 @@ Blockly.JavaScript['math_random_float'] = function(block) {
// Random fraction between 0 and 1.
return ['Math.random()', Blockly.JavaScript.ORDER_FUNCTION_CALL];
};
Blockly.JavaScript['math_atan2'] = function(block) {
// Arctangent of point (X, Y) in degrees from -180 to 180.
var argument0 = Blockly.JavaScript.valueToCode(block, 'X',
Blockly.JavaScript.ORDER_COMMA) || '0';
var argument1 = Blockly.JavaScript.valueToCode(block, 'Y',
Blockly.JavaScript.ORDER_COMMA) || '0';
return ['Math.atan2(' + argument1 + ', ' + argument0 + ') / Math.PI * 180',
Blockly.JavaScript.ORDER_DIVISION];
};

View File

@@ -425,3 +425,13 @@ Blockly.Lua['math_random_float'] = function(block) {
// Random fraction between 0 and 1.
return ['math.random()', Blockly.Lua.ORDER_HIGH];
};
Blockly.Lua['math_atan2'] = function(block) {
// Arctangent of point (X, Y) in degrees from -180 to 180.
var argument0 = Blockly.Lua.valueToCode(block, 'X',
Blockly.Lua.ORDER_NONE) || '0';
var argument1 = Blockly.Lua.valueToCode(block, 'Y',
Blockly.Lua.ORDER_NONE) || '0';
return ['math.deg(math.atan2(' + argument1 + ', ' + argument0 + '))',
Blockly.Lua.ORDER_HIGH];
};

View File

@@ -372,3 +372,13 @@ Blockly.PHP['math_random_float'] = function(block) {
// Random fraction between 0 and 1.
return ['(float)rand()/(float)getrandmax()', Blockly.PHP.ORDER_FUNCTION_CALL];
};
Blockly.PHP['math_atan2'] = function(block) {
// Arctangent of point (X, Y) in degrees from -180 to 180.
var argument0 = Blockly.PHP.valueToCode(block, 'X',
Blockly.PHP.ORDER_COMMA) || '0';
var argument1 = Blockly.PHP.valueToCode(block, 'Y',
Blockly.PHP.ORDER_COMMA) || '0';
return ['atan2(' + argument1 + ', ' + argument0 + ') / pi() * 180',
Blockly.PHP.ORDER_DIVISION];
};

View File

@@ -386,3 +386,14 @@ Blockly.Python['math_random_float'] = function(block) {
Blockly.Python.definitions_['import_random'] = 'import random';
return ['random.random()', Blockly.Python.ORDER_FUNCTION_CALL];
};
Blockly.Python['math_atan2'] = function(block) {
// Arctangent of point (X, Y) in degrees from -180 to 180.
Blockly.Python.definitions_['import_math'] = 'import math';
var argument0 = Blockly.Python.valueToCode(block, 'X',
Blockly.Python.ORDER_NONE) || '0';
var argument1 = Blockly.Python.valueToCode(block, 'Y',
Blockly.Python.ORDER_NONE) || '0';
return ['math.atan2(' + argument1 + ', ' + argument0 + ') / math.pi * 180',
Blockly.Python.ORDER_MULTIPLICATIVE];
};