Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Inside Block by alterGNU
from typing import Tuple
projection_X = lambda a,b,pt: ((((pt[1]-a[1])*(b[0]-a[0]))/(b[1]-a[1]))+a[0],pt[1])
projection_Y = lambda a,b,pt: (pt[0],(((pt[0]-a[0])*(b[1]-a[1]))/(b[0]-a[0]))+a[1])
def is_inside(points,pt):
if len(points)<3: return False
x_candidats=[ (x,y) for (x,y) in points if y==pt[1] ]
y_candidats=[ (x,y) for (x,y) in points if x==pt[0] ]
if (pt in x_candidats)or(pt in y_candidats): return True
points = points+points[0:1]
for i in range(len(points)-1):
if (points[i][1]pt[1])or(points[i][1]>pt[1] and points[i+1][1]pt[0])or(points[i][0]>pt[0] and points[i+1][0]=pt[0] ])
y_inf=max([ (y,x) for (x,y) in y_candidats if y<=pt[1] ])[::-1]
y_sup=min([ (y,x) for (x,y) in y_candidats if y>=pt[1] ])[::-1]
both_side=(len(x_inf)>0)and(len(x_sup)>0)and(len(y_inf)>0)and(len(y_sup)>0)
return (inter_even)and(both_side)
except:
return False
if __name__ == '__main__':
assert is_inside(((4,2),(2,4),(0,3),(2,3),(3,2),(3,0)),(3,3)) is True
assert is_inside(((1,1),(2,3),(1,3),(3,4),(5,3),(4,3),(3,1)),(2,2)) is True
assert is_inside(((1,1),(2,4),(5,4),(4,1),(3,1),(4,3),(3,3),(2,1)),(3,2)) is False
assert is_inside(((3,4),(4,2),(2,1),(1,3)),(2,2)) is True
assert is_inside(((1, 1), (1, 3), (3, 3), (3, 1)), (2, 2)) is True, "First"
assert is_inside(((1, 1), (1, 3), (3, 3), (3, 1)), (4, 2)) is False, "Second"
assert is_inside(((1, 1), (4, 1), (2, 3)), (3, 2)) is True, "Third"
assert is_inside(((1, 1), (4, 1), (1, 3)), (3, 3)) is False, "Fourth"
assert is_inside(((2, 1), (4, 1), (5, 3), (3, 4), (1, 3)), (4, 3)) is True, "Fifth"
assert is_inside(((2, 1), (4, 1), (3, 2), (3, 4), (1, 3)), (4, 3)) is False, "Sixth"
assert is_inside(((1, 1), (3, 2), (5, 1), (4, 3), (5, 5), (3, 4), (1, 5), (2, 3)), (3, 3)) is True, "Seventh"
assert is_inside(((1, 1), (1, 5), (5, 5), (5, 4), (2, 4), (2, 2), (5, 2), (5, 1)), (4, 3)) is False, "Eighth"
print("All done! Let's check now")
June 6, 2021
Comments: