# diapasons
simple library for working with data that can be represented as a set of points on a straight line.
# Installing
```commandline
pip install diapasons
```
# Usage
Here is some examples, how you can use this module
### Create some diapason objects
```python
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
```python
from diapasons import Diapason
first_diapason = Diapason([1, 2, 3])
first_diapason.length # 2
len(first_diapason) # 2
```
### diapason can have only one point
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
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
```python
from diapasons import Diapason
my_diapason = Diapason([1, 10])
another_diapason = Diapason([2, 4, 5])
print(my_diapason.overlaps(another_diapason)) # True
```
Raw data
{
"_id": null,
"home_page": "https://github.com/AlbertSabirzianov/diapasons",
"name": "diapasons",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "diapasons sections lines points",
"author": "a.sabirzianov",
"author_email": "albertuno@mail.com",
"download_url": "https://files.pythonhosted.org/packages/03/33/6282acbe317c77aebd242312767a97915d9d2226dbb5d5db23e3fa44c8b2/diapasons-0.0.3.tar.gz",
"platform": null,
"description": "# diapasons\r\nsimple library for working with data that can be represented as a set of points on a straight line.\r\n# Installing\r\n```commandline\r\npip install diapasons\r\n```\r\n# Usage\r\nHere is some examples, how you can use this module\r\n### Create some diapason objects\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nfirst_diapason = Diapason([1, 2, 3])\r\nsecond_diapason = Diapason([3, 4, 5])\r\nprint(first_diapason.points) # [1, 2, 3]\r\nprint(second_diapason.points) # [3, 4, 5]\r\n```\r\nNow you can imagine them as segments on a straight line\r\n### You can easily see length each of objects\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nfirst_diapason = Diapason([1, 2, 3])\r\n\r\nfirst_diapason.length # 2\r\nlen(first_diapason) # 2\r\n```\r\n### diapason can have only one point\r\n\r\n```python\r\nfrom diapasons import Diapason\r\n\r\npoint_diapason = Diapason([1])\r\npoint_diapason.is_point # True\r\nline_diapason = Diapason([5, 16, 9.6])\r\nline_diapason.is_point # False\r\n```\r\n### You can add points to diapason\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 4])\r\nmy_diapason.points # [1, 4]\r\nmy_diapason.add_point(9)\r\nmy_diapason.points # [1, 4, 9]\r\nmy_diapason.add_points([3, 5])\r\nmy_diapason.points # [1, 3, 4, 5, 9]\r\n```\r\nPoint can be only integer or float!\r\n### Each Diapason have start_point, end_point\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 4, 8])\r\nmy_diapason.start_point # 1\r\nmy_diapason.end_point # 8\r\n```\r\n### Operations with diapasons\r\nadd diapasons to each other\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 2.6]) + Diapason([5, 6])\r\nprint(my_diapason.points) # [1, 2.6, 5, 6]\r\n```\r\nmove diapason on straight line\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 2.6])\r\nmy_diapason.move(2)\r\nprint(my_diapason.points) # [2, 3.6]\r\nmy_diapason.move(-3)\r\nprint(my_diapason.points) # [-1, 0.6]\r\n```\r\nsplit by point\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 2.6])\r\nleft_d, right_d = my_diapason.split_by_point(2)\r\nleft_d.points # [1, 2]\r\nright_d.points # [2, 2.6]\r\n```\r\nsplit by another diapason\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nspliter = Diapason([3, 6])\r\nleft_diapason, right_diapason = my_diapason.split_by_diapason(spliter)\r\nleft_diapason.points # [1, 3]\r\nright_diapason.points # [6, 10]\r\n```\r\nfind common diapason\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([3, 15])\r\ncommon = my_diapason.common(another_diapason)\r\nprint(common.points) # [3, 10]\r\n```\r\nfind different\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([3, 15])\r\nleft_d, right_d = my_diapason.different(another_diapason)\r\nprint(left_d.points) # [1, 3]\r\nprint(right_d.points) # [10, 15]\r\n```\r\nfind distance between diapasons\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([20, 25, 30])\r\ndistance = my_diapason.distance(another_diapason)\r\nprint(distance) # 10\r\n```\r\n### Diapason comparisons\r\ndiapason touch another, when they have at least one common point\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([10, 45])\r\nmy_diapason.touch(another_diapason) # True\r\n```\r\ndiapason intersects another when they have more than one common point\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([5, 45])\r\nmy_diapason.intersects(another_diapason) # True\r\n```\r\ndiapason contains another when all the points of one are \"on the body\" of the other\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([2, 4, 5])\r\nprint(another_diapason in my_diapason) # True\r\n```\r\ndiapason equal another when equal they start and end points\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([1, 4, 5, 10])\r\nprint(another_diapason == my_diapason) # True\r\n```\r\ndiapason crosses another then they touch each other in one point\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([10, 15, 30])\r\nprint(another_diapason.crosses(my_diapason)) # True\r\n```\r\ndiapason overlaps another when\r\n```python\r\nfrom diapasons import Diapason\r\n\r\nmy_diapason = Diapason([1, 10])\r\nanother_diapason = Diapason([2, 4, 5])\r\nprint(my_diapason.overlaps(another_diapason)) # True\r\n```\r\n",
"bugtrack_url": null,
"license": "",
"summary": "simple library for working with data that can be represented as a set of points on a straight line.",
"version": "0.0.3",
"project_urls": {
"GitHub": "https://github.com/AlbertSabirzianov/diapasons",
"Homepage": "https://github.com/AlbertSabirzianov/diapasons"
},
"split_keywords": [
"diapasons",
"sections",
"lines",
"points"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ae9164b1358c6c3151c8b61248127f35b17a88366828fdfa5881d9cb601e7f8e",
"md5": "33f4b27543edc29269f381ead16a87d4",
"sha256": "1c2da0a4512a9672984e96327f3efc0382bb298ebb0901f0963f784eedd0ec9c"
},
"downloads": -1,
"filename": "diapasons-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "33f4b27543edc29269f381ead16a87d4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 6744,
"upload_time": "2024-02-25T09:27:32",
"upload_time_iso_8601": "2024-02-25T09:27:32.496819Z",
"url": "https://files.pythonhosted.org/packages/ae/91/64b1358c6c3151c8b61248127f35b17a88366828fdfa5881d9cb601e7f8e/diapasons-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "03336282acbe317c77aebd242312767a97915d9d2226dbb5d5db23e3fa44c8b2",
"md5": "236229ae4f876193f89dadd93e7cfee9",
"sha256": "c743fcd21c51c35b94eca426c03bd62e20724bacdc42e6748fd1786388c646de"
},
"downloads": -1,
"filename": "diapasons-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "236229ae4f876193f89dadd93e7cfee9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 7053,
"upload_time": "2024-02-25T09:27:34",
"upload_time_iso_8601": "2024-02-25T09:27:34.130907Z",
"url": "https://files.pythonhosted.org/packages/03/33/6282acbe317c77aebd242312767a97915d9d2226dbb5d5db23e3fa44c8b2/diapasons-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-25 09:27:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "AlbertSabirzianov",
"github_project": "diapasons",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "diapasons"
}