Skip to main content

simple library for working with data that can be represented as a set of points on a straight line.

Project description

diapasons

simple library for working with data that can be represented as a set of points on a straight line.

Installing

pip install diapasons

Usage

Here is some examples, how you can use this module

Create some diapason objects

from diapasons import Diapason

first_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 line

You can easily see length each of objects

from diapasons import Diapason

first_diapason = Diapason([1, 2, 3])

first_diapason.length # 2
len(first_diapason) # 2

diapason can have only one point

from diapasons import Diapason

point_diapason = Diapason([1])
point_diapason.is_point  # True
line_diapason = Diapason([5, 16, 9.6])
line_diapason.is_point # False

You can add points to diapason

from diapasons import Diapason

my_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_point

from diapasons import Diapason

my_diapason = Diapason([1, 4, 8])
my_diapason.start_point # 1
my_diapason.end_point # 8

Operations with diapasons

add diapasons to each other

from diapasons import Diapason

my_diapason = Diapason([1, 2.6]) + Diapason([5, 6])
print(my_diapason.points) # [1, 2.6, 5, 6]

move diapason on straight line

from diapasons import Diapason

my_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 point

from diapasons import Diapason

my_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 diapason

from diapasons import Diapason

my_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 diapason

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([3, 15])
common = my_diapason.common(another_diapason)
print(common.points) # [3, 10]

find different

from diapasons import Diapason

my_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 diapasons

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([20, 25, 30])
distance = my_diapason.distance(another_diapason)
print(distance) # 10

Diapason comparisons

diapason touch another, when they have at least one common point

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([10, 45])
my_diapason.touch(another_diapason) # True

diapason intersects another when they have more than one common point

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([5, 45])
my_diapason.intersects(another_diapason) # True

diapason contains another when all the points of one are "on the body" of the other

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([2, 4, 5])
print(another_diapason in my_diapason) # True

diapason equal another when equal they start and end points

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([1, 4, 5, 10])
print(another_diapason == my_diapason) # True

diapason crosses another then they touch each other in one point

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([10, 15, 30])
print(another_diapason.crosses(my_diapason)) # True

diapason overlaps another when

from diapasons import Diapason

my_diapason = Diapason([1, 10])
another_diapason = Diapason([2, 4, 5])
print(my_diapason.overlaps(another_diapason)) # True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diapasons-0.0.3.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

diapasons-0.0.3-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page