From 793e7009e996dca9b99b590e470a090549c6f6df Mon Sep 17 00:00:00 2001 From: "Jeison Yehuda Amihud (Blender Dumbass)" Date: Thu, 3 Dec 2020 15:05:02 +0000 Subject: [PATCH] Upload files to 'UI' --- UI/UI_math.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 UI/UI_math.py diff --git a/UI/UI_math.py b/UI/UI_math.py new file mode 100644 index 0000000..39a96ee --- /dev/null +++ b/UI/UI_math.py @@ -0,0 +1,63 @@ +# THIS FILE IS A PART OF VCStudio +# PYTHON 3 + + +# This is collection of simple geometric math operations that I gonna use trough +# out the UI of the VCStudio. Stuff like collision detections, overlap detections +# and other verious little tiny, but overused functions. + +def line_overlap(line1, line2): + + # This function will check if 2 one dimenshional line overlap. + + overlap = False + + # Let's sort them just incase. + + line1.sort() + line2.sort() + + + # Well. I guess this is the least ambiguos way of doing so. In my opinion + + if line1[0] > line2[0] and line1[0] < line2[1]: + overlap = True + elif line1[1] > line2[0] and line1[1] < line2[1]: + overlap = True + elif line2[0] > line1[0] and line2[0] < line1[1]: + overlap = True + elif line2[1] > line1[0] and line2[1] < line1[1]: + overlap = True + + + return overlap + +def rectangle_overlap(rectangle1, rectangle2): + + # This function will see if 2 rectangle overlap. It returns either True or + # False. + + overlap = False + + # Now since it's going to be easier for me to use the same type of coordi- + # nates as in cairo to draw rectangles. I need to purify them first. Meaning + # convert the width and height into real points on a plane. + + r1x, r1y, r1w, r1h = rectangle1 + r2x, r2y, r2w, r2h = rectangle2 + + + r1w += r1x + r1h += r1y + r2w += r2x + r2h += r2y + + + # Now we going to simply compare if overlapping lines of x coordinates and if + # yes. Coordinates of y coordinates. + + if line_overlap([r1x, r1w],[r2x, r2w]) and line_overlap([r1y, r1h],[r2y, r2h]): + overlap = True + + + return overlap