# Some useful algorithms in pure Cython - no dependencies
### Tested against Windows 10 / Python 3.11 / Anaconda
### pip install cythoncubicspline
### Cython and a C compiler must be installed!
``` py
from cythoncubicspline import (
calculate_missing_coords,
get_rectangle_coordinates_surface,
get_circle_coordinates_surface,
get_ellipse_coordinates_surface,
bresenham_line,
get_polygon_coordinates_surface,
convex_hull,
calculate_missing_coords_and_fill_all_holes,
get_coords_of_line,
logsplit,
logspace,
linspace,
get_circle_coordinates,
groupcoords_asc_desc,
cubic_interp1d,
difflist,
)
circle_coords = get_circle_coordinates(x=20, y=20, r=10)
print(f"{circle_coords=}")
```
----------------------------
``` py
rect_coords = get_rectangle_coordinates_surface(10, 10, 5, 5)
print(f"{rect_coords=}")
```
----------------------------
``` py
circle_surface_coords = get_circle_coordinates_surface(
x_center=20, y_center=20, radius=10
)
print(f"{circle_surface_coords=}")
```
----------------------------
``` py
ellipse_coords = get_ellipse_coordinates_surface(0, 0, 10, 5)
print(f"{ellipse_coords}")
```
----------------------------
``` py
line_coords = bresenham_line(0, 0, 25, 5)
print(f"{line_coords=}")
```
----------------------------
``` py
polygon_coords = get_polygon_coordinates_surface(
[
(350, 100),
(450, 450),
(150, 400),
(100, 200),
(350, 100),
(200, 300),
(350, 350),
(300, 200),
(200, 300),
]
)
print(f"{polygon_coords=}")
```
----------------------------
``` pyhull_coords = convex_hull([(1, 1), (3, 2), (2, 3), (0, 0), (3, 3)])
print(hull_coords)
```
----------------------------
``` pycoordlist = [
(12, 100),
(9, 90),
(10, 80),
(9, 70),
(7, 60),
(5, 50),
(6, 40),
(5, 30),
(4, 20),
(4, 10),
(3, 0),
(3, 10),
(5, 20),
(3, 30),
(7, 40),
(7, 50),
(7, 60),
(9, 70),
(11, 80),
(12, 90),
(11, 100),
(7, 70),
(7, 40),
(4, 10),
]
result_groupcoords = groupcoords_asc_desc(coordlist, xtolerance=-2)
for x in result_groupcoords:
print(x)
[(0, (12, 100))]
[(1, (9, 90)), (3, (9, 70))]
[(4, (7, 60))]
[(5, (5, 50)), (7, (5, 30))]
[(8, (4, 20)), (10, (3, 0)), (11, (3, 10)), (12, (5, 20))]
[
(13, (3, 30)),
(14, (7, 40)),
(15, (7, 50)),
(16, (7, 60)),
(17, (9, 70)),
(18, (11, 80)),
(20, (11, 100)),
]
[(21, (7, 70)), (22, (7, 40))]
```
----------------------------
``` py
coords=[
(160, 218),
(133, 305),
(109, 399),
(128, 502),
(120, 608),
(107, 705),
(106, 806),
(174, 898),
(325, 928),
(399, 881),
(444, 751),
(474, 583),
(479, 453),
(496, 337),
(545, 234),
(670, 177),
(796, 219),
(910, 285),
(951, 363),
(972, 483),
(991, 602),
(1056, 744),
(1137, 817),
(1286, 877),
(1419, 777),
(1507, 603),
(1504, 446),
(1341, 282),
(1218, 238),
(1111, 233),
(1010, 200),
(888, 172),
(715, 173),
(595, 165),
(487, 167),
(367, 178),
(283, 210),
(216, 269),
(172, 348),
(151, 442),
(171, 543),
(224, 634),
(254, 720),
(323, 772),
(443, 789),
(562, 797),
(680, 802),
(802, 808),
(929, 807),
(1089, 826),
(1220, 863),
(1341, 902),
(1300, 972),
(1179, 981),
(1019, 956),
(845, 927),
(694, 903),
(514, 878),
(361, 845),
(269, 785),
(203, 698),
(170, 606),
(197, 513),
(272, 454),
(366, 398),
(475, 347),
(661, 329),
(863, 359),
(1010, 358),
(1211, 351),
(1350, 308),
(1449, 259),
(1447, 178),
(1302, 120),
(1197, 114),
(1062, 122),
(908, 125),
(797, 129),
(699, 137),
]
calcalist = calculate_missing_coords(coordlist=coords, xtolerance=-2)
print(f"{calcalist=}")
calcalist = calculate_missing_coords_and_fill_all_holes(coordlist=coords, xtolerance=-2)
print(f"{calcalist=}")
# import matplotlib.pyplot as plt
# plt.plot(*zip(*calcalist))
# plt.show()
```
----------------------------
``` pylinecoords = get_coords_of_line(10, 20, 50, 70)
#import matplotlib.pyplot as plt
#plt.plot(*zip(*linecoords))
#plt.show()
```
----------------------------
``` pyfor l in logsplit(list(range(50))):
print(l)
[0]
[1, 2]
[3, 4, 5]
[6, 7, 8, 9]
[10, 11, 12, 13, 14]
[15, 16, 17, 18, 19, 20]
[21, 22, 23, 24, 25, 26, 27]
[28, 29, 30, 31, 32, 33, 34, 35]
[36, 37, 38, 39, 40, 41, 42, 43, 44]
[45, 46, 47, 48, 49]
```
``` pyfor l in logspace(start=10, stop=100, num=20):
print(l)
10.0
11.14684748713282
11.46139906526985
11.86222427300331
12.372985808857322
13.023836457655403
13.853199158847453
14.910035303051664
16.25673516559804
17.97280111369074
20.159541025162195
22.946048994588956
26.49682639749191
31.021493221811085
36.787162974681834
44.13421171659021
53.49637214714573
65.4263389959423
80.62839733163142
100.0
```
----------------------------
``` py
for l in linspace(start=10, stop=100, number=7, endpoint=True):
print(l)
10.0
25.0
40.0
55.0
70.0
85.0
100.0
```
----------------------------
``` py
for q in difflist(list(range(1,20,3))):
print(q)
3
3
3
3
3
3
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/cythoncubicspline",
"name": "cythoncubicspline",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "cython",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/7b/ba/41f25a4e99b72844f87d16c91f621ab50ba7e99d2ddf45288bcbf735ad03/cythoncubicspline-0.11.tar.gz",
"platform": null,
"description": "\r\n# Some useful algorithms in pure Cython - no dependencies\r\n\r\n### Tested against Windows 10 / Python 3.11 / Anaconda\r\n\r\n### pip install cythoncubicspline\r\n\r\n### Cython and a C compiler must be installed!\r\n\r\n\r\n``` py\r\nfrom cythoncubicspline import (\r\n calculate_missing_coords,\r\n get_rectangle_coordinates_surface,\r\n get_circle_coordinates_surface,\r\n get_ellipse_coordinates_surface,\r\n bresenham_line,\r\n get_polygon_coordinates_surface,\r\n convex_hull,\r\n calculate_missing_coords_and_fill_all_holes,\r\n get_coords_of_line,\r\n logsplit,\r\n logspace,\r\n linspace,\r\n get_circle_coordinates,\r\n groupcoords_asc_desc,\r\n cubic_interp1d,\r\n difflist,\r\n)\r\n\r\ncircle_coords = get_circle_coordinates(x=20, y=20, r=10)\r\nprint(f\"{circle_coords=}\")\r\n\r\n```\r\n\r\n----------------------------\r\n``` py\r\nrect_coords = get_rectangle_coordinates_surface(10, 10, 5, 5)\r\nprint(f\"{rect_coords=}\")\r\n```\r\n\r\n----------------------------\r\n``` py\r\ncircle_surface_coords = get_circle_coordinates_surface(\r\n x_center=20, y_center=20, radius=10\r\n)\r\nprint(f\"{circle_surface_coords=}\")\r\n```\r\n\r\n----------------------------\r\n``` py\r\nellipse_coords = get_ellipse_coordinates_surface(0, 0, 10, 5)\r\nprint(f\"{ellipse_coords}\")\r\n```\r\n\r\n----------------------------\r\n``` py\r\nline_coords = bresenham_line(0, 0, 25, 5)\r\nprint(f\"{line_coords=}\")\r\n\r\n```\r\n\r\n----------------------------\r\n``` py\r\npolygon_coords = get_polygon_coordinates_surface(\r\n [\r\n (350, 100),\r\n (450, 450),\r\n (150, 400),\r\n (100, 200),\r\n (350, 100),\r\n (200, 300),\r\n (350, 350),\r\n (300, 200),\r\n (200, 300),\r\n ]\r\n)\r\nprint(f\"{polygon_coords=}\")\r\n```\r\n\r\n----------------------------\r\n``` pyhull_coords = convex_hull([(1, 1), (3, 2), (2, 3), (0, 0), (3, 3)])\r\nprint(hull_coords)\r\n\r\n```\r\n\r\n----------------------------\r\n``` pycoordlist = [\r\n (12, 100),\r\n (9, 90),\r\n (10, 80),\r\n (9, 70),\r\n (7, 60),\r\n (5, 50),\r\n (6, 40),\r\n (5, 30),\r\n (4, 20),\r\n (4, 10),\r\n (3, 0),\r\n (3, 10),\r\n (5, 20),\r\n (3, 30),\r\n (7, 40),\r\n (7, 50),\r\n (7, 60),\r\n (9, 70),\r\n (11, 80),\r\n (12, 90),\r\n (11, 100),\r\n (7, 70),\r\n (7, 40),\r\n (4, 10),\r\n]\r\nresult_groupcoords = groupcoords_asc_desc(coordlist, xtolerance=-2)\r\nfor x in result_groupcoords:\r\n print(x)\r\n[(0, (12, 100))]\r\n[(1, (9, 90)), (3, (9, 70))]\r\n[(4, (7, 60))]\r\n[(5, (5, 50)), (7, (5, 30))]\r\n[(8, (4, 20)), (10, (3, 0)), (11, (3, 10)), (12, (5, 20))]\r\n[\r\n (13, (3, 30)),\r\n (14, (7, 40)),\r\n (15, (7, 50)),\r\n (16, (7, 60)),\r\n (17, (9, 70)),\r\n (18, (11, 80)),\r\n (20, (11, 100)),\r\n]\r\n[(21, (7, 70)), (22, (7, 40))]\r\n```\r\n\r\n----------------------------\r\n``` py\r\ncoords=[\r\n (160, 218),\r\n (133, 305),\r\n (109, 399),\r\n (128, 502),\r\n (120, 608),\r\n (107, 705),\r\n (106, 806),\r\n (174, 898),\r\n (325, 928),\r\n (399, 881),\r\n (444, 751),\r\n (474, 583),\r\n (479, 453),\r\n (496, 337),\r\n (545, 234),\r\n (670, 177),\r\n (796, 219),\r\n (910, 285),\r\n (951, 363),\r\n (972, 483),\r\n (991, 602),\r\n (1056, 744),\r\n (1137, 817),\r\n (1286, 877),\r\n (1419, 777),\r\n (1507, 603),\r\n (1504, 446),\r\n (1341, 282),\r\n (1218, 238),\r\n (1111, 233),\r\n (1010, 200),\r\n (888, 172),\r\n (715, 173),\r\n (595, 165),\r\n (487, 167),\r\n (367, 178),\r\n (283, 210),\r\n (216, 269),\r\n (172, 348),\r\n (151, 442),\r\n (171, 543),\r\n (224, 634),\r\n (254, 720),\r\n (323, 772),\r\n (443, 789),\r\n (562, 797),\r\n (680, 802),\r\n (802, 808),\r\n (929, 807),\r\n (1089, 826),\r\n (1220, 863),\r\n (1341, 902),\r\n (1300, 972),\r\n (1179, 981),\r\n (1019, 956),\r\n (845, 927),\r\n (694, 903),\r\n (514, 878),\r\n (361, 845),\r\n (269, 785),\r\n (203, 698),\r\n (170, 606),\r\n (197, 513),\r\n (272, 454),\r\n (366, 398),\r\n (475, 347),\r\n (661, 329),\r\n (863, 359),\r\n (1010, 358),\r\n (1211, 351),\r\n (1350, 308),\r\n (1449, 259),\r\n (1447, 178),\r\n (1302, 120),\r\n (1197, 114),\r\n (1062, 122),\r\n (908, 125),\r\n (797, 129),\r\n (699, 137),\r\n]\r\ncalcalist = calculate_missing_coords(coordlist=coords, xtolerance=-2)\r\nprint(f\"{calcalist=}\")\r\ncalcalist = calculate_missing_coords_and_fill_all_holes(coordlist=coords, xtolerance=-2)\r\nprint(f\"{calcalist=}\")\r\n# import matplotlib.pyplot as plt\r\n# plt.plot(*zip(*calcalist))\r\n# plt.show()\r\n```\r\n\r\n----------------------------\r\n``` pylinecoords = get_coords_of_line(10, 20, 50, 70)\r\n#import matplotlib.pyplot as plt\r\n#plt.plot(*zip(*linecoords))\r\n#plt.show()\r\n\r\n```\r\n\r\n----------------------------\r\n``` pyfor l in logsplit(list(range(50))):\r\n print(l)\r\n[0]\r\n[1, 2]\r\n[3, 4, 5]\r\n[6, 7, 8, 9]\r\n[10, 11, 12, 13, 14]\r\n[15, 16, 17, 18, 19, 20]\r\n[21, 22, 23, 24, 25, 26, 27]\r\n[28, 29, 30, 31, 32, 33, 34, 35]\r\n[36, 37, 38, 39, 40, 41, 42, 43, 44]\r\n[45, 46, 47, 48, 49]\r\n```\r\n\r\n``` pyfor l in logspace(start=10, stop=100, num=20):\r\n print(l)\r\n10.0\r\n11.14684748713282\r\n11.46139906526985\r\n11.86222427300331\r\n12.372985808857322\r\n13.023836457655403\r\n13.853199158847453\r\n14.910035303051664\r\n16.25673516559804\r\n17.97280111369074\r\n20.159541025162195\r\n22.946048994588956\r\n26.49682639749191\r\n31.021493221811085\r\n36.787162974681834\r\n44.13421171659021\r\n53.49637214714573\r\n65.4263389959423\r\n80.62839733163142\r\n100.0\r\n```\r\n\r\n----------------------------\r\n``` py\r\nfor l in linspace(start=10, stop=100, number=7, endpoint=True):\r\n print(l)\r\n10.0\r\n25.0\r\n40.0\r\n55.0\r\n70.0\r\n85.0\r\n100.0\r\n```\r\n\r\n----------------------------\r\n``` py\r\nfor q in difflist(list(range(1,20,3))):\r\n print(q)\r\n3\r\n3\r\n3\r\n3\r\n3\r\n3\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Some useful algorithms in pure Cython - no dependencies",
"version": "0.11",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/cythoncubicspline"
},
"split_keywords": [
"cython"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6430b07d0d96d9c4370b854790d2b96b090ee4437fce44cbcfe44e6eeb9705dd",
"md5": "75c7f3eff26245ceb65dd662a1cb58a7",
"sha256": "868f080af5738259c9a910ee7d6452fb70d7b57425d3cb1ecbd140034ade14d6"
},
"downloads": -1,
"filename": "cythoncubicspline-0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "75c7f3eff26245ceb65dd662a1cb58a7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 16277,
"upload_time": "2024-07-16T05:15:57",
"upload_time_iso_8601": "2024-07-16T05:15:57.153204Z",
"url": "https://files.pythonhosted.org/packages/64/30/b07d0d96d9c4370b854790d2b96b090ee4437fce44cbcfe44e6eeb9705dd/cythoncubicspline-0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7bba41f25a4e99b72844f87d16c91f621ab50ba7e99d2ddf45288bcbf735ad03",
"md5": "4fd8e5c27279c5d86c35683727491f0a",
"sha256": "35c17ab28408472470ea10e9a53b301d8441fac532b383dfbf967568dadfafa5"
},
"downloads": -1,
"filename": "cythoncubicspline-0.11.tar.gz",
"has_sig": false,
"md5_digest": "4fd8e5c27279c5d86c35683727491f0a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 15284,
"upload_time": "2024-07-16T05:15:58",
"upload_time_iso_8601": "2024-07-16T05:15:58.358827Z",
"url": "https://files.pythonhosted.org/packages/7b/ba/41f25a4e99b72844f87d16c91f621ab50ba7e99d2ddf45288bcbf735ad03/cythoncubicspline-0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-16 05:15:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "cythoncubicspline",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "Cython",
"specs": []
},
{
"name": "setuptools",
"specs": []
}
],
"lcname": "cythoncubicspline"
}