From 9590d3657acc441bc00c797b3ecfa63322ba0bd1 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Sun, 27 Sep 2020 10:04:06 +0530 Subject: [PATCH 01/21] Create vector3_for_2d_rendering.py Edited for passing travis test --- vector3_for_2d_rendering.py | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 vector3_for_2d_rendering.py diff --git a/vector3_for_2d_rendering.py b/vector3_for_2d_rendering.py new file mode 100644 index 000000000000..a36a2d074ee8 --- /dev/null +++ b/vector3_for_2d_rendering.py @@ -0,0 +1,70 @@ +""" +render 3d points for 2d surfaces. +""" + +import math + +__version__ = "2020.9.26" +__author__ = "xcodz-dot" + + +def convert_to_2d(x: float, y: float, z: float, scale: float, + distance: float) -> (float, float): + """ + Converts 3d point to a 2d drawable point + + >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) + (7.6923076923076925, 15.384615384615385) + """ + if not isinstance(x, (float, int)): + raise ValueError("x must be float or int") + if not isinstance(y, (float, int)): + raise ValueError("y must be float or int") + if not isinstance(z, (float, int)): + raise ValueError("z must be float or int") + if not isinstance(scale, (float, int)): + raise ValueError("scale must be float or int") + if not isinstance(distance, (float, int)): + raise ValueError("distance must be float") + projected_x = ((x * distance) / (z + distance)) * scale + projected_y = ((y * distance) / (z + distance)) * scale + return projected_x, projected_y + + +def rotate(x: float, y: float, z: float, axis: str, + angle: float) -> (float, float, float): + """ + rotate a point around a certain axis with a certain angle + angle can be any integer between 1, 360 and axis can be any one of + 'x', 'y', 'z' + + >>> rotate(1.0, 2.0, 3.0, 'y', 90.0) + (3.130524675073759, 2.0, 0.4470070007889556) + """ + if not isinstance(angle, (int, float)): + raise ValueError("Angel must be int or float") + if angle > 360 or angle < 0: + raise ValueError("Angle is supposed to be in between 0, 360") + if not isinstance(x, (int, float)): + raise ValueError("x must be int or float") + if not isinstance(y, (int, float)): + raise ValueError("y must be int or float") + if not isinstance(z, (int, float)): + raise ValueError("z must be int or float") + angle = angle / 450 * 180 / math.pi + if axis == 'z': + new_x = x * math.cos(angle) - y * math.sin(angle) + new_y = y * math.cos(angle) + x * math.sin(angle) + new_z = z + elif axis == 'x': + new_y = y * math.cos(angle) - z * math.sin(angle) + new_z = z * math.cos(angle) + y * math.sin(angle) + new_x = x + elif axis == 'y': + new_x = x * math.cos(angle) - z * math.sin(angle) + new_z = z * math.cos(angle) + x * math.sin(angle) + new_y = y + else: + raise ValueError("not a valid axis, choose one of 'x', 'y', 'z'") + + return new_x, new_y, new_z From 57ee51c50fb7cbc7fcf9c42f32b67af0fc449e17 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Sun, 27 Sep 2020 10:13:27 +0530 Subject: [PATCH 02/21] Delete vector3_for_2d_rendering.py --- vector3_for_2d_rendering.py | 70 ------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 vector3_for_2d_rendering.py diff --git a/vector3_for_2d_rendering.py b/vector3_for_2d_rendering.py deleted file mode 100644 index a36a2d074ee8..000000000000 --- a/vector3_for_2d_rendering.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -render 3d points for 2d surfaces. -""" - -import math - -__version__ = "2020.9.26" -__author__ = "xcodz-dot" - - -def convert_to_2d(x: float, y: float, z: float, scale: float, - distance: float) -> (float, float): - """ - Converts 3d point to a 2d drawable point - - >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) - (7.6923076923076925, 15.384615384615385) - """ - if not isinstance(x, (float, int)): - raise ValueError("x must be float or int") - if not isinstance(y, (float, int)): - raise ValueError("y must be float or int") - if not isinstance(z, (float, int)): - raise ValueError("z must be float or int") - if not isinstance(scale, (float, int)): - raise ValueError("scale must be float or int") - if not isinstance(distance, (float, int)): - raise ValueError("distance must be float") - projected_x = ((x * distance) / (z + distance)) * scale - projected_y = ((y * distance) / (z + distance)) * scale - return projected_x, projected_y - - -def rotate(x: float, y: float, z: float, axis: str, - angle: float) -> (float, float, float): - """ - rotate a point around a certain axis with a certain angle - angle can be any integer between 1, 360 and axis can be any one of - 'x', 'y', 'z' - - >>> rotate(1.0, 2.0, 3.0, 'y', 90.0) - (3.130524675073759, 2.0, 0.4470070007889556) - """ - if not isinstance(angle, (int, float)): - raise ValueError("Angel must be int or float") - if angle > 360 or angle < 0: - raise ValueError("Angle is supposed to be in between 0, 360") - if not isinstance(x, (int, float)): - raise ValueError("x must be int or float") - if not isinstance(y, (int, float)): - raise ValueError("y must be int or float") - if not isinstance(z, (int, float)): - raise ValueError("z must be int or float") - angle = angle / 450 * 180 / math.pi - if axis == 'z': - new_x = x * math.cos(angle) - y * math.sin(angle) - new_y = y * math.cos(angle) + x * math.sin(angle) - new_z = z - elif axis == 'x': - new_y = y * math.cos(angle) - z * math.sin(angle) - new_z = z * math.cos(angle) + y * math.sin(angle) - new_x = x - elif axis == 'y': - new_x = x * math.cos(angle) - z * math.sin(angle) - new_z = z * math.cos(angle) + x * math.sin(angle) - new_y = y - else: - raise ValueError("not a valid axis, choose one of 'x', 'y', 'z'") - - return new_x, new_y, new_z From 2775efee838bb025961cf5a8edb2c22567b8d70b Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Sun, 27 Sep 2020 10:14:30 +0530 Subject: [PATCH 03/21] Create vector3_for_2d_rendering.py --- graphics/vector3_for_2d_rendering.py | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 graphics/vector3_for_2d_rendering.py diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py new file mode 100644 index 000000000000..a36a2d074ee8 --- /dev/null +++ b/graphics/vector3_for_2d_rendering.py @@ -0,0 +1,70 @@ +""" +render 3d points for 2d surfaces. +""" + +import math + +__version__ = "2020.9.26" +__author__ = "xcodz-dot" + + +def convert_to_2d(x: float, y: float, z: float, scale: float, + distance: float) -> (float, float): + """ + Converts 3d point to a 2d drawable point + + >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) + (7.6923076923076925, 15.384615384615385) + """ + if not isinstance(x, (float, int)): + raise ValueError("x must be float or int") + if not isinstance(y, (float, int)): + raise ValueError("y must be float or int") + if not isinstance(z, (float, int)): + raise ValueError("z must be float or int") + if not isinstance(scale, (float, int)): + raise ValueError("scale must be float or int") + if not isinstance(distance, (float, int)): + raise ValueError("distance must be float") + projected_x = ((x * distance) / (z + distance)) * scale + projected_y = ((y * distance) / (z + distance)) * scale + return projected_x, projected_y + + +def rotate(x: float, y: float, z: float, axis: str, + angle: float) -> (float, float, float): + """ + rotate a point around a certain axis with a certain angle + angle can be any integer between 1, 360 and axis can be any one of + 'x', 'y', 'z' + + >>> rotate(1.0, 2.0, 3.0, 'y', 90.0) + (3.130524675073759, 2.0, 0.4470070007889556) + """ + if not isinstance(angle, (int, float)): + raise ValueError("Angel must be int or float") + if angle > 360 or angle < 0: + raise ValueError("Angle is supposed to be in between 0, 360") + if not isinstance(x, (int, float)): + raise ValueError("x must be int or float") + if not isinstance(y, (int, float)): + raise ValueError("y must be int or float") + if not isinstance(z, (int, float)): + raise ValueError("z must be int or float") + angle = angle / 450 * 180 / math.pi + if axis == 'z': + new_x = x * math.cos(angle) - y * math.sin(angle) + new_y = y * math.cos(angle) + x * math.sin(angle) + new_z = z + elif axis == 'x': + new_y = y * math.cos(angle) - z * math.sin(angle) + new_z = z * math.cos(angle) + y * math.sin(angle) + new_x = x + elif axis == 'y': + new_x = x * math.cos(angle) - z * math.sin(angle) + new_z = z * math.cos(angle) + x * math.sin(angle) + new_y = y + else: + raise ValueError("not a valid axis, choose one of 'x', 'y', 'z'") + + return new_x, new_y, new_z From d9fcc662cde0efb214cef9f867e6b362c8bfd2ce Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 10:57:27 +0530 Subject: [PATCH 04/21] Update vector3_for_2d_rendering.py Compressed the line 19 to 28 into 19 to 21 --- graphics/vector3_for_2d_rendering.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index a36a2d074ee8..87e4b429d06d 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -16,16 +16,8 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) (7.6923076923076925, 15.384615384615385) """ - if not isinstance(x, (float, int)): - raise ValueError("x must be float or int") - if not isinstance(y, (float, int)): - raise ValueError("y must be float or int") - if not isinstance(z, (float, int)): - raise ValueError("z must be float or int") - if not isinstance(scale, (float, int)): - raise ValueError("scale must be float or int") - if not isinstance(distance, (float, int)): - raise ValueError("distance must be float") + if not all(isinstance(val, (float, int)) for val in locals().values()): + raise ValueError(f"Input values must either be float or int: {list(locals().values())}") projected_x = ((x * distance) / (z + distance)) * scale projected_y = ((y * distance) / (z + distance)) * scale return projected_x, projected_y From ae70f41b502431c1967306be02e3ca8bac6b9ee2 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:46:12 +0530 Subject: [PATCH 05/21] Update vector3_for_2d_rendering.py --- graphics/vector3_for_2d_rendering.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index 87e4b429d06d..6969dc50c6f6 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -17,7 +17,8 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, (7.6923076923076925, 15.384615384615385) """ if not all(isinstance(val, (float, int)) for val in locals().values()): - raise ValueError(f"Input values must either be float or int: {list(locals().values())}") + raise ValueError(f"Input values must either be float or int: "+ + f"{list(locals().values())}") projected_x = ((x * distance) / (z + distance)) * scale projected_y = ((y * distance) / (z + distance)) * scale return projected_x, projected_y @@ -33,16 +34,15 @@ def rotate(x: float, y: float, z: float, axis: str, >>> rotate(1.0, 2.0, 3.0, 'y', 90.0) (3.130524675073759, 2.0, 0.4470070007889556) """ - if not isinstance(angle, (int, float)): - raise ValueError("Angel must be int or float") if angle > 360 or angle < 0: raise ValueError("Angle is supposed to be in between 0, 360") - if not isinstance(x, (int, float)): - raise ValueError("x must be int or float") - if not isinstance(y, (int, float)): - raise ValueError("y must be int or float") - if not isinstance(z, (int, float)): - raise ValueError("z must be int or float") + input_variables = dict(locals()) + del input_variables["axis"] + if not all(isinstance(val, (float, int)) for val in input_variables.values()): + raise ValueError(f"Input values except axis must either be float or int: "+ + f"{list(input_variables.values())}") + if not isinstance(axis, str): + raise ValueError(f"Axis must be a str") angle = angle / 450 * 180 / math.pi if axis == 'z': new_x = x * math.cos(angle) - y * math.sin(angle) From 3e528319744c2849c81b3b72ac886aaa5174961c Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:48:03 +0530 Subject: [PATCH 06/21] Update vector3_for_2d_rendering.py --- graphics/vector3_for_2d_rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index 6969dc50c6f6..cafbe4523ae2 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -34,7 +34,7 @@ def rotate(x: float, y: float, z: float, axis: str, >>> rotate(1.0, 2.0, 3.0, 'y', 90.0) (3.130524675073759, 2.0, 0.4470070007889556) """ - if angle > 360 or angle < 0: + if not 0 <= angle <= 360: raise ValueError("Angle is supposed to be in between 0, 360") input_variables = dict(locals()) del input_variables["axis"] From ccb6c9fa0d21675e59fff1a54da6c69deb051f7b Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 11:55:22 +0530 Subject: [PATCH 07/21] Update vector3_for_2d_rendering.py completly corrected pep8 errors using Pycharm IDE --- graphics/vector3_for_2d_rendering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index cafbe4523ae2..b840ec5c5d5c 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -17,7 +17,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, (7.6923076923076925, 15.384615384615385) """ if not all(isinstance(val, (float, int)) for val in locals().values()): - raise ValueError(f"Input values must either be float or int: "+ + raise ValueError(f"Input values must either be float or int: " + f"{list(locals().values())}") projected_x = ((x * distance) / (z + distance)) * scale projected_y = ((y * distance) / (z + distance)) * scale @@ -39,7 +39,7 @@ def rotate(x: float, y: float, z: float, axis: str, input_variables = dict(locals()) del input_variables["axis"] if not all(isinstance(val, (float, int)) for val in input_variables.values()): - raise ValueError(f"Input values except axis must either be float or int: "+ + raise ValueError(f"Input values except axis must either be float or int: " + f"{list(input_variables.values())}") if not isinstance(axis, str): raise ValueError(f"Axis must be a str") From 828f11a15c51b87312c07dc17ec761c5961ec1fd Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 12:06:59 +0530 Subject: [PATCH 08/21] Update vector3_for_2d_rendering.py --- graphics/vector3_for_2d_rendering.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index b840ec5c5d5c..db95d86728c3 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -17,7 +17,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, (7.6923076923076925, 15.384615384615385) """ if not all(isinstance(val, (float, int)) for val in locals().values()): - raise ValueError(f"Input values must either be float or int: " + + raise ValueError("Input values must either be float or int: " f"{list(locals().values())}") projected_x = ((x * distance) / (z + distance)) * scale projected_y = ((y * distance) / (z + distance)) * scale @@ -39,10 +39,10 @@ def rotate(x: float, y: float, z: float, axis: str, input_variables = dict(locals()) del input_variables["axis"] if not all(isinstance(val, (float, int)) for val in input_variables.values()): - raise ValueError(f"Input values except axis must either be float or int: " + + raise ValueError("Input values except axis must either be float or int: " f"{list(input_variables.values())}") if not isinstance(axis, str): - raise ValueError(f"Axis must be a str") + raise ValueError("Axis must be a str") angle = angle / 450 * 180 / math.pi if axis == 'z': new_x = x * math.cos(angle) - y * math.sin(angle) From 9975733217149c757fbfddce61ff2fad05265886 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 12:12:04 +0530 Subject: [PATCH 09/21] Update graphics/vector3_for_2d_rendering.py Co-authored-by: Dhruv --- graphics/vector3_for_2d_rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index db95d86728c3..3541f6e7ad4b 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -17,7 +17,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, (7.6923076923076925, 15.384615384615385) """ if not all(isinstance(val, (float, int)) for val in locals().values()): - raise ValueError("Input values must either be float or int: " + raise TypeError("Input values must either be float or int: " f"{list(locals().values())}") projected_x = ((x * distance) / (z + distance)) * scale projected_y = ((y * distance) / (z + distance)) * scale From 022f7d515a0848da9fba3a47444d06a07e53c9f5 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 12:14:25 +0530 Subject: [PATCH 10/21] Update graphics/vector3_for_2d_rendering.py Co-authored-by: Dhruv --- graphics/vector3_for_2d_rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index 3541f6e7ad4b..c6624babeee8 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -36,7 +36,7 @@ def rotate(x: float, y: float, z: float, axis: str, """ if not 0 <= angle <= 360: raise ValueError("Angle is supposed to be in between 0, 360") - input_variables = dict(locals()) + input_variables = locals() del input_variables["axis"] if not all(isinstance(val, (float, int)) for val in input_variables.values()): raise ValueError("Input values except axis must either be float or int: " From 7b13ddcf083cd527c2d938d92b9b20e7878a2630 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 12:15:47 +0530 Subject: [PATCH 11/21] Update graphics/vector3_for_2d_rendering.py Co-authored-by: Dhruv --- graphics/vector3_for_2d_rendering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index c6624babeee8..009c413a6658 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -39,10 +39,10 @@ def rotate(x: float, y: float, z: float, axis: str, input_variables = locals() del input_variables["axis"] if not all(isinstance(val, (float, int)) for val in input_variables.values()): - raise ValueError("Input values except axis must either be float or int: " + raise TypeError("Input values except axis must either be float or int: " f"{list(input_variables.values())}") if not isinstance(axis, str): - raise ValueError("Axis must be a str") + raise TypeError("Axis must be a str") angle = angle / 450 * 180 / math.pi if axis == 'z': new_x = x * math.cos(angle) - y * math.sin(angle) From af6cd9e4e873a8139c25180a1294df0d94ade385 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 12:21:19 +0530 Subject: [PATCH 12/21] Update vector3_for_2d_rendering.py --- graphics/vector3_for_2d_rendering.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index 009c413a6658..f992cd91328d 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -18,7 +18,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, """ if not all(isinstance(val, (float, int)) for val in locals().values()): raise TypeError("Input values must either be float or int: " - f"{list(locals().values())}") + f"{list(locals().values())}") projected_x = ((x * distance) / (z + distance)) * scale projected_y = ((y * distance) / (z + distance)) * scale return projected_x, projected_y @@ -40,7 +40,7 @@ def rotate(x: float, y: float, z: float, axis: str, del input_variables["axis"] if not all(isinstance(val, (float, int)) for val in input_variables.values()): raise TypeError("Input values except axis must either be float or int: " - f"{list(input_variables.values())}") + f"{list(input_variables.values())}") if not isinstance(axis, str): raise TypeError("Axis must be a str") angle = angle / 450 * 180 / math.pi From 1bad0cc7d6d713f7e3949e71c6dc842b765902f3 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:12:37 +0530 Subject: [PATCH 13/21] Update vector3_for_2d_rendering.py --- graphics/vector3_for_2d_rendering.py | 1 + 1 file changed, 1 insertion(+) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index f992cd91328d..e67579d8481b 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -2,6 +2,7 @@ render 3d points for 2d surfaces. """ +from __future__ import annotations import math __version__ = "2020.9.26" From a098a17a042a1be5cdec158b7879b68bb1f5477c Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:13:15 +0530 Subject: [PATCH 14/21] Update graphics/vector3_for_2d_rendering.py Co-authored-by: Christian Clauss --- graphics/vector3_for_2d_rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index e67579d8481b..9bc1db383d0a 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -10,7 +10,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, - distance: float) -> (float, float): + distance: float) -> tuple[float, float]: """ Converts 3d point to a 2d drawable point From b2fee5d8e1d30c10399f0f1340f98379df29536f Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:14:06 +0530 Subject: [PATCH 15/21] Update graphics/vector3_for_2d_rendering.py Co-authored-by: Christian Clauss --- graphics/vector3_for_2d_rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index 9bc1db383d0a..ad71002ab3ae 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -26,7 +26,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, def rotate(x: float, y: float, z: float, axis: str, - angle: float) -> (float, float, float): + angle: float) -> tuple[float, float, float]: """ rotate a point around a certain axis with a certain angle angle can be any integer between 1, 360 and axis can be any one of From fe96c7fdb1dfa799917703844d2e8bae77b1fe3a Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:17:17 +0530 Subject: [PATCH 16/21] Apply suggestions from code review Co-authored-by: Christian Clauss --- graphics/vector3_for_2d_rendering.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index ad71002ab3ae..3a8cfe87730d 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -35,15 +35,16 @@ def rotate(x: float, y: float, z: float, axis: str, >>> rotate(1.0, 2.0, 3.0, 'y', 90.0) (3.130524675073759, 2.0, 0.4470070007889556) """ - if not 0 <= angle <= 360: - raise ValueError("Angle is supposed to be in between 0, 360") + if not isinstance(axis, str): + raise TypeError("Axis must be a str") input_variables = locals() del input_variables["axis"] if not all(isinstance(val, (float, int)) for val in input_variables.values()): raise TypeError("Input values except axis must either be float or int: " f"{list(input_variables.values())}") - if not isinstance(axis, str): - raise TypeError("Axis must be a str") + angle %= 360 # wrap around if angle >= 360 + if not 0 <= angle < 360: + raise ValueError("Angle is supposed to be in between 0, 360") angle = angle / 450 * 180 / math.pi if axis == 'z': new_x = x * math.cos(angle) - y * math.sin(angle) @@ -61,3 +62,10 @@ def rotate(x: float, y: float, z: float, axis: str, raise ValueError("not a valid axis, choose one of 'x', 'y', 'z'") return new_x, new_y, new_z + +if __name__ == "__main__": + import doctest + + doctest.modtest() + print(f"{convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) = }") + print(f"{rotate(1.0, 2.0, 3.0, 'y', 90.0) = }") From ff55531ecc155721048d8a00ee63eba7211571a5 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:21:48 +0530 Subject: [PATCH 17/21] Update vector3_for_2d_rendering.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added A few extra names to __author__ 😄 --- graphics/vector3_for_2d_rendering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index 3a8cfe87730d..c6bb2560fabb 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -6,7 +6,7 @@ import math __version__ = "2020.9.26" -__author__ = "xcodz-dot" +__author__ = "xcodz-dot, cclaus, dhruvmanila" def convert_to_2d(x: float, y: float, z: float, scale: float, From c5f6164e38f433419f26df779b845c234f723ba7 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:25:40 +0530 Subject: [PATCH 18/21] Update vector3_for_2d_rendering.py Used Pycharm to fix PEP8 errors, doctest errors --- graphics/vector3_for_2d_rendering.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index c6bb2560fabb..98c8954dee20 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -8,9 +8,11 @@ __version__ = "2020.9.26" __author__ = "xcodz-dot, cclaus, dhruvmanila" +from typing import Tuple + def convert_to_2d(x: float, y: float, z: float, scale: float, - distance: float) -> tuple[float, float]: + distance: float) -> Tuple[float, float]: """ Converts 3d point to a 2d drawable point @@ -26,7 +28,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, def rotate(x: float, y: float, z: float, axis: str, - angle: float) -> tuple[float, float, float]: + angle: float) -> Tuple[float, float, float]: """ rotate a point around a certain axis with a certain angle angle can be any integer between 1, 360 and axis can be any one of @@ -63,9 +65,10 @@ def rotate(x: float, y: float, z: float, axis: str, return new_x, new_y, new_z + if __name__ == "__main__": import doctest - doctest.modtest() + doctest.testmod() print(f"{convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) = }") print(f"{rotate(1.0, 2.0, 3.0, 'y', 90.0) = }") From f5e9d4ea2e86f65a64bfada41d137ceb8a8ad1e2 Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:44:47 +0530 Subject: [PATCH 19/21] Update vector3_for_2d_rendering.py Added enough doctests --- graphics/vector3_for_2d_rendering.py | 29 ++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index 98c8954dee20..cbfff4c17c6a 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -18,6 +18,14 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, >>> convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) (7.6923076923076925, 15.384615384615385) + + >>> convert_to_2d(1, 2, 3, 10, 10) + (7.6923076923076925, 15.384615384615385) + + >>> convert_to_2d("1", 2, 3, 10, 10) # '1' is str + Traceback (most recent call last): + ... + TypeError: Input values must either be float or int: ['1', 2, 3, 10, 10] """ if not all(isinstance(val, (float, int)) for val in locals().values()): raise TypeError("Input values must either be float or int: " @@ -36,6 +44,25 @@ def rotate(x: float, y: float, z: float, axis: str, >>> rotate(1.0, 2.0, 3.0, 'y', 90.0) (3.130524675073759, 2.0, 0.4470070007889556) + + >>> rotate(1, 2, 3, "z", 180) + (0.999736015495891, -2.0001319704760485, 3) + + >>> rotate('1', 2, 3, "z", 90.0) # '1' is str + Traceback (most recent call last): + ... + TypeError: Input values except axis must either be float or int: ['1', 2, 3, 90.0] + + >>> rotate(1, 2, 3, "n", 90) # 'n' is not a valid axis + Traceback (most recent call last): + ... + ValueError: not a valid axis, choose one of 'x', 'y', 'z' + + >>> rotate(1, 2, 3, "x", -90) + (1, -2.5049096187183877, -2.5933429780983657) + + >>> rotate(1, 2, 3, "x", 450) # 450 wrap around to 90 + (1, 3.5776792428178217, -0.44744970165427644) """ if not isinstance(axis, str): raise TypeError("Axis must be a str") @@ -45,8 +72,6 @@ def rotate(x: float, y: float, z: float, axis: str, raise TypeError("Input values except axis must either be float or int: " f"{list(input_variables.values())}") angle %= 360 # wrap around if angle >= 360 - if not 0 <= angle < 360: - raise ValueError("Angle is supposed to be in between 0, 360") angle = angle / 450 * 180 / math.pi if axis == 'z': new_x = x * math.cos(angle) - y * math.sin(angle) From 44404efdc9f381d9182fc6e27b808371ef975c8d Mon Sep 17 00:00:00 2001 From: xcodz-dot <71920621+xcodz-dot@users.noreply.github.com> Date: Mon, 28 Sep 2020 14:53:25 +0530 Subject: [PATCH 20/21] Update graphics/vector3_for_2d_rendering.py Co-authored-by: Christian Clauss --- graphics/vector3_for_2d_rendering.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index cbfff4c17c6a..e2885bc9bd20 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -90,6 +90,13 @@ def rotate(x: float, y: float, z: float, axis: str, return new_x, new_y, new_z +if __name__ == "__main__": + import doctest + + doctest.modtest() + print(f"{convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) = }") + print(f"{rotate(1.0, 2.0, 3.0, 'y', 90.0) = }") + if __name__ == "__main__": import doctest From c5f35b56c7c1989ec2d2b31e310ead4fe92714c1 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 28 Sep 2020 11:37:48 +0200 Subject: [PATCH 21/21] Remove second main() --- graphics/vector3_for_2d_rendering.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/graphics/vector3_for_2d_rendering.py b/graphics/vector3_for_2d_rendering.py index e2885bc9bd20..f55bfc7579b5 100644 --- a/graphics/vector3_for_2d_rendering.py +++ b/graphics/vector3_for_2d_rendering.py @@ -8,11 +8,9 @@ __version__ = "2020.9.26" __author__ = "xcodz-dot, cclaus, dhruvmanila" -from typing import Tuple - def convert_to_2d(x: float, y: float, z: float, scale: float, - distance: float) -> Tuple[float, float]: + distance: float) -> tuple[float, float]: """ Converts 3d point to a 2d drawable point @@ -36,7 +34,7 @@ def convert_to_2d(x: float, y: float, z: float, scale: float, def rotate(x: float, y: float, z: float, axis: str, - angle: float) -> Tuple[float, float, float]: + angle: float) -> tuple[float, float, float]: """ rotate a point around a certain axis with a certain angle angle can be any integer between 1, 360 and axis can be any one of @@ -71,8 +69,7 @@ def rotate(x: float, y: float, z: float, axis: str, if not all(isinstance(val, (float, int)) for val in input_variables.values()): raise TypeError("Input values except axis must either be float or int: " f"{list(input_variables.values())}") - angle %= 360 # wrap around if angle >= 360 - angle = angle / 450 * 180 / math.pi + angle = (angle % 360) / 450 * 180 / math.pi if axis == 'z': new_x = x * math.cos(angle) - y * math.sin(angle) new_y = y * math.cos(angle) + x * math.sin(angle) @@ -90,13 +87,6 @@ def rotate(x: float, y: float, z: float, axis: str, return new_x, new_y, new_z -if __name__ == "__main__": - import doctest - - doctest.modtest() - print(f"{convert_to_2d(1.0, 2.0, 3.0, 10.0, 10.0) = }") - print(f"{rotate(1.0, 2.0, 3.0, 'y', 90.0) = }") - if __name__ == "__main__": import doctest