Upload files to 'UI'

This commit is contained in:
Jeison Yehuda Amihud (Blender Dumbass) 2020-12-03 15:05:02 +00:00
parent a8a4faf391
commit 793e7009e9

63
UI/UI_math.py Normal file
View file

@ -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