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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file diapasons-0.0.3.tar.gz.
File metadata
- Download URL: diapasons-0.0.3.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c743fcd21c51c35b94eca426c03bd62e20724bacdc42e6748fd1786388c646de
|
|
| MD5 |
236229ae4f876193f89dadd93e7cfee9
|
|
| BLAKE2b-256 |
03336282acbe317c77aebd242312767a97915d9d2226dbb5d5db23e3fa44c8b2
|
File details
Details for the file diapasons-0.0.3-py3-none-any.whl.
File metadata
- Download URL: diapasons-0.0.3-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c2da0a4512a9672984e96327f3efc0382bb298ebb0901f0963f784eedd0ec9c
|
|
| MD5 |
33f4b27543edc29269f381ead16a87d4
|
|
| BLAKE2b-256 |
ae9164b1358c6c3151c8b61248127f35b17a88366828fdfa5881d9cb601e7f8e
|