From 633bbbc8fa115520516bd3d0c0145588f2e77cf3 Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 13:12:23 -0700 Subject: [PATCH 01/11] Add math_atan2 block with two inputs --- blocks/math.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/blocks/math.js b/blocks/math.js index 9f95654af..18f664368 100644 --- a/blocks/math.js +++ b/blocks/math.js @@ -372,6 +372,29 @@ Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT "colour": "%{BKY_MATH_HUE}", "tooltip": "%{BKY_MATH_RANDOM_FLOAT_TOOLTIP}", "helpUrl": "%{BKY_MATH_RANDOM_FLOAT_HELPURL}" + }, + + // Block for calculating atan2 of [X] and [Y]. + { + "type": "math_atan2", + "message0": "%{BKY_MATH_ATAN2_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "X", + "check": "Number" + }, + { + "type": "input_value", + "name": "Y", + "check": "Number" + } + ], + "inputsInline": true, + "output": "Number", + "colour": "%{BKY_MATH_HUE}", + "tooltip": "%{BKY_MATH_ATAN2_TOOLTIP}", + "helpUrl": "%{BKY_MATH_ATAN2_HELPURL}" } ]); // END JSON EXTRACT (Do not delete this comment.) From c89909bd29ca2419d5e0e633bbbf675dd359fd36 Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 13:29:42 -0700 Subject: [PATCH 02/11] Add math_atan2 strings --- msg/messages.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/msg/messages.js b/msg/messages.js index 15110d0f5..d3fea6ce9 100644 --- a/msg/messages.js +++ b/msg/messages.js @@ -557,6 +557,13 @@ Blockly.Msg.MATH_RANDOM_FLOAT_TITLE_RANDOM = 'random fraction'; /// tooltip - Return a random fraction between 0 and 1. The value may be equal to 0 but must be less than 1. Blockly.Msg.MATH_RANDOM_FLOAT_TOOLTIP = 'Return a random fraction between 0.0 (inclusive) and 1.0 (exclusive).'; +/// {{Optional}} url - Information about how to calculate atan2. +Blockly.Msg.MATH_ATAN2_HELPURL = 'https://en.wikipedia.org/wiki/Atan2'; +/// block text - The title of the block that calculates atan2 of point (X, Y). For example, if the point is (-1, -1), this returns -135. %1 is a placeholder for the X coordinate, %2 is the placeholder for the Y coordinate. +Blockly.Msg.MATH_ATAN2_TITLE = 'atan2 of X:%1 Y:%2'; +/// tooltip - Return the arctangent of point (X, Y) in degrees from -180 to 180. For example, if the point is (-1, -1) this returns -135. +Blockly.Msg.MATH_ATAN2_TOOLTIP = 'Return the arctangent of point (X, Y) in degrees from -180 to 180.'; + // Text Blocks. /// {{Optional}} url - Information about how computers represent text (sometimes referred to as ''string''s). Blockly.Msg.TEXT_TEXT_HELPURL = 'https://en.wikipedia.org/wiki/String_(computer_science)'; From 23bb0e00d94bad0d7079ee471e6fcf600c997764 Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 14:18:25 -0700 Subject: [PATCH 03/11] Add math_atan2 JavaScript generator --- generators/javascript/math.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generators/javascript/math.js b/generators/javascript/math.js index 191e7af1e..fa7d7714b 100644 --- a/generators/javascript/math.js +++ b/generators/javascript/math.js @@ -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]; +}; From fd0bcabacd5f0f5682507e1b9e9b7ebe8643ed52 Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 14:19:01 -0700 Subject: [PATCH 04/11] Add math_atan2 Dart generator --- generators/dart/math.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/generators/dart/math.js b/generators/dart/math.js index c37df0ea3..5696483ff 100644 --- a/generators/dart/math.js +++ b/generators/dart/math.js @@ -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]; +}; \ No newline at end of file From 683a7381665d1146ca4793ef38cbf72fb48c300a Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 14:19:40 -0700 Subject: [PATCH 05/11] Add math_atan2 Lua generator --- generators/lua/math.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generators/lua/math.js b/generators/lua/math.js index eefcee4ae..a105371e5 100644 --- a/generators/lua/math.js +++ b/generators/lua/math.js @@ -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]; +}; \ No newline at end of file From c61822befa791d5bf9641f649441558dcdc69c85 Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 14:20:27 -0700 Subject: [PATCH 06/11] Add math_atan2 PHP generator --- generators/php/math.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/generators/php/math.js b/generators/php/math.js index 5100d0f4b..cef909281 100644 --- a/generators/php/math.js +++ b/generators/php/math.js @@ -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]; +}; \ No newline at end of file From d3deeedc029db8479be2b0213b050b67e26e9db4 Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 14:34:26 -0700 Subject: [PATCH 07/11] Add math_atan2 Python generator --- generators/python/math.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/generators/python/math.js b/generators/python/math.js index f1307d71a..11e8466e2 100644 --- a/generators/python/math.js +++ b/generators/python/math.js @@ -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]; +}; From d822efa322c79535ae2e21d715c16700af1967bb Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 14:56:13 -0700 Subject: [PATCH 08/11] Add math_atan2 block to demos and playgrounds --- demos/code/index.html | 12 ++++++++++++ demos/graph/index.html | 12 ++++++++++++ demos/rtl/index.html | 1 + demos/toolbox/index.html | 1 + tests/generators/index.html | 1 + tests/multi_playground.html | 12 ++++++++++++ tests/playground.html | 24 ++++++++++++++++++++++++ tests/workspace_svg/index.html | 12 ++++++++++++ 8 files changed, 75 insertions(+) diff --git a/demos/code/index.html b/demos/code/index.html index 3210db5e0..e591c6a54 100644 --- a/demos/code/index.html +++ b/demos/code/index.html @@ -200,6 +200,18 @@ + + + + 1 + + + + + 1 + + + diff --git a/demos/graph/index.html b/demos/graph/index.html index dd5401e29..ec6ba5e36 100644 --- a/demos/graph/index.html +++ b/demos/graph/index.html @@ -145,6 +145,18 @@ + + + + 1 + + + + + 1 + + + diff --git a/demos/rtl/index.html b/demos/rtl/index.html index 917d6f906..240cf8d20 100644 --- a/demos/rtl/index.html +++ b/demos/rtl/index.html @@ -117,6 +117,7 @@ + diff --git a/demos/toolbox/index.html b/demos/toolbox/index.html index 311460e0a..77ee1d58f 100644 --- a/demos/toolbox/index.html +++ b/demos/toolbox/index.html @@ -114,6 +114,7 @@ + diff --git a/tests/generators/index.html b/tests/generators/index.html index 23289f767..4a73a3bd6 100644 --- a/tests/generators/index.html +++ b/tests/generators/index.html @@ -320,6 +320,7 @@ h1 { + diff --git a/tests/multi_playground.html b/tests/multi_playground.html index afbcbf8cf..8177a87db 100644 --- a/tests/multi_playground.html +++ b/tests/multi_playground.html @@ -289,6 +289,18 @@ h1 { + + + + 1 + + + + + 1 + + + diff --git a/tests/playground.html b/tests/playground.html index 39b4283a5..20a216c73 100644 --- a/tests/playground.html +++ b/tests/playground.html @@ -519,6 +519,18 @@ h1 { + + + + 1 + + + + + 1 + + + @@ -848,6 +860,18 @@ h1 { + + + + 1 + + + + + 1 + + + diff --git a/tests/workspace_svg/index.html b/tests/workspace_svg/index.html index 53006a634..a4c7aebd3 100644 --- a/tests/workspace_svg/index.html +++ b/tests/workspace_svg/index.html @@ -202,6 +202,18 @@ h1 { + + + + 1 + + + + + 1 + + + From da48f3c66f87abd79f9e38294d3260b48d975a37 Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Thu, 11 Oct 2018 15:14:08 -0700 Subject: [PATCH 09/11] Add math_atan2 unit test --- tests/generators/math.xml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/generators/math.xml b/tests/generators/math.xml index 9c1f644f8..9515e015b 100644 --- a/tests/generators/math.xml +++ b/tests/generators/math.xml @@ -36,6 +36,11 @@ + + + + + @@ -1881,4 +1886,36 @@ + + test atan2 + Describe this function... + + + + + atan2 + + + + + + + -1 + + + + + -1 + + + + + + + -135 + + + + + \ No newline at end of file From e1217252ff435ab44854224f203e5223f8fdb1be Mon Sep 17 00:00:00 2001 From: Nadya Febiana Djojosantoso Date: Mon, 15 Oct 2018 21:01:53 -0700 Subject: [PATCH 10/11] Update math_atan2 unit test --- tests/generators/math.xml | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/generators/math.xml b/tests/generators/math.xml index 9515e015b..3988ebd6e 100644 --- a/tests/generators/math.xml +++ b/tests/generators/math.xml @@ -1900,21 +1900,49 @@ - -1 + -5 - -1 + 5 - -135 + 135 + + + + + atan2 + + + + + + + 0 + + + + + -12 + + + + + + + -90 + + + + From 58bfab7c6c657eaf7d8f1d8207b187aca2184209 Mon Sep 17 00:00:00 2001 From: Andrew n marshall Date: Tue, 16 Oct 2018 11:25:10 -0700 Subject: [PATCH 11/11] Math.PI => Math.pi The Dart test was failing prior to this. --- generators/dart/math.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/dart/math.js b/generators/dart/math.js index 5696483ff..f5b75e183 100644 --- a/generators/dart/math.js +++ b/generators/dart/math.js @@ -494,6 +494,6 @@ Blockly.Dart['math_atan2'] = function(block) { 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', + return ['Math.atan2(' + argument1 + ', ' + argument0 + ') / Math.pi * 180', Blockly.Dart.ORDER_MULTIPLICATIVE]; -}; \ No newline at end of file +};