Package: diapasons
diapasonssimple library for working with data that can be represented as a set of points on a straight line.Installingpip install diapasonsUsageHere is some examples, how you can use this moduleCreate some diapason objectsfromdiapasonsimportDiapasonfirst_diapason=Diapason([1,2,3])second_diapason=Diapason([3,4,5])print(first_diapason.points)# [1, 2, 3]print(second_diapason.points)# [3, 4, 5]Now you can imagine them as segments on a straight lineYou can easily see length each of objectsfromdiapasonsimportDiapasonfirst_diapason=Diapason([1,2,3])first_diapason.length# 2len(first_diapason)# 2diapason can have only one pointfromdiapasonsimportDiapasonpoint_diapason=Diapason([1])point_diapason.is_point# Trueline_diapason=Diapason([5,16,9.6])line_diapason.is_point# FalseYou can add points to diapasonfromdiapasonsimportDiapasonmy_diapason=Diapason([1,4])my_diapason.points# [1, 4]my_diapason.add_point(9)my_diapason.points# [1, 4, 9]my_diapason.add_points([3,5])my_diapason.points# [1, 3, 4, 5, 9]Point can be only integer or float!Each Diapason have start_point, end_pointfromdiapasonsimportDiapasonmy_diapason=Diapason([1,4,8])my_diapason.start_point# 1my_diapason.end_point# 8Operations with diapasonsadd diapasons to each otherfromdiapasonsimportDiapasonmy_diapason=Diapason([1,2.6])+Diapason([5,6])print(my_diapason.points)# [1, 2.6, 5, 6]move diapason on straight linefromdiapasonsimportDiapasonmy_diapason=Diapason([1,2.6])my_diapason.move(2)print(my_diapason.points)# [2, 3.6]my_diapason.move(-3)print(my_diapason.points)# [-1, 0.6]split by pointfromdiapasonsimportDiapasonmy_diapason=Diapason([1,2.6])left_d,right_d=my_diapason.split_by_point(2)left_d.points# [1, 2]right_d.points# [2, 2.6]split by another diapasonfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])spliter=Diapason([3,6])left_diapason,right_diapason=my_diapason.split_by_diapason(spliter)left_diapason.points# [1, 3]right_diapason.points# [6, 10]find common diapasonfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([3,15])common=my_diapason.common(another_diapason)print(common.points)# [3, 10]find differentfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([3,15])left_d,right_d=my_diapason.different(another_diapason)print(left_d.points)# [1, 3]print(right_d.points)# [10, 15]find distance between diapasonsfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([20,25,30])distance=my_diapason.distance(another_diapason)print(distance)# 10Diapason comparisonsdiapason touch another, when they have at least one common pointfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([10,45])my_diapason.touch(another_diapason)# Truediapason intersects another when they have more than one common pointfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([5,45])my_diapason.intersects(another_diapason)# Truediapason contains another when all the points of one are "on the body" of the otherfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([2,4,5])print(another_diapasoninmy_diapason)# Truediapason equal another when equal they start and end pointsfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([1,4,5,10])print(another_diapason==my_diapason)# Truediapason crosses another then they touch each other in one pointfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([10,15,30])print(another_diapason.crosses(my_diapason))# Truediapason overlaps another whenfromdiapasonsimportDiapasonmy_diapason=Diapason([1,10])another_diapason=Diapason([2,4,5])print(my_diapason.overlaps(another_diapason))# True