bin2path 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bin2path-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bin2path contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: bin2path
3
+ Version: 0.1.0
4
+ Summary: Transform numbers into 3D geometric paths - binary visualization
5
+ Author: bin2path
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Sett11/bin2path
8
+ Project-URL: Repository, https://github.com/Sett11/bin2path
9
+ Keywords: binary,3d,visualization,geometry,hashing
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Topic :: Scientific/Engineering :: Visualization
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: matplotlib>=3.7.0
21
+ Requires-Dist: numpy>=1.24.0
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
24
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
25
+ Requires-Dist: build>=1.2.0; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # bin2path
29
+
30
+ Transform numbers into 3D geometric paths.
31
+
32
+ A Python library for converting natural numbers into 3D geometric shapes (spatial polylines on an integer lattice).
33
+ We use a **cellular-automaton scheme** that produces a sequence of symbolic steps `L/R/U/D`, and then interpret these steps as **local** (orientation-dependent) moves in 3D.
34
+
35
+ ## Concept
36
+
37
+ Each number is represented as a 3D path on an integer lattice via a **discrete step rule**:
38
+
39
+ - We work with the binary representation **MSB → LSB** (left-to-right bits).
40
+ - Each bit is mapped to one of 4 **symbols**: `L/R/U/D`.
41
+ - Each symbol is then interpreted as a **relative 3D move** based on the current orientation (`forward/up/right`), so the path is not constrained to a plane.
42
+
43
+ ### Bits → symbols (cellular automaton)
44
+
45
+ - **First bit**:
46
+ - `0` → first step `L`
47
+ - `1` → first step `R`
48
+ - **Each next bit** (only previous step matters):
49
+ - if bit = `0`:
50
+ - if previous step was `L` → current step `D`
51
+ - otherwise → `L`
52
+ - if bit = `1`:
53
+ - if previous step was `R` → current step `U`
54
+ - otherwise → `R`
55
+
56
+ ### Symbols → 3D steps (local orientation)
57
+
58
+ We maintain a local frame:
59
+
60
+ - `forward` (where “go forward” points)
61
+ - `up` (local up)
62
+ - `right = cross(forward, up)`
63
+
64
+ Initial frame:
65
+
66
+ - `forward = (0, 0, 1)` (along +Z)
67
+ - `up = (0, 1, 0)` (along +Y)
68
+
69
+ Step semantics (rotate if needed, then move 1 unit along the new `forward`):
70
+
71
+ - `R`: move forward
72
+ - `L`: yaw left around `up`, then move forward
73
+ - `U`: pitch up around `right`, then move forward
74
+ - `D`: pitch down around `right`, then move forward
75
+
76
+ So the path is built from `(0,0,0)` by applying these steps.
77
+
78
+ The representation is:
79
+ - **Unique**: Different numbers produce different paths
80
+ - **Reversible**: You can decode the path back to the original number
81
+ - **Deterministic**: Same number always produces same path
82
+
83
+ ## Installation
84
+
85
+ ```bash
86
+ pip install bin2path
87
+ ```
88
+
89
+ Or from source:
90
+
91
+ ```bash
92
+ git clone https://github.com/Sett11/bin2path.git
93
+ cd bin2path
94
+ pip install -e .
95
+ ```
96
+
97
+ ## Quick Start
98
+
99
+ ```python
100
+ import bin2path
101
+
102
+ # Encode a number to 3D path
103
+ path = bin2path.encode(42)
104
+
105
+ # Get path data
106
+ print(path.vertices) # list of (x,y,z)
107
+ print(path.edges) # list of (from_idx, to_idx)
108
+
109
+ # Decode back to number
110
+ number = bin2path.decode(path) # 42
111
+
112
+ # Visualize
113
+ bin2path.visualize(path)
114
+
115
+ # Extract features for clustering / analysis
116
+ f = bin2path.features(path)
117
+ print(f['path_length']) # number of steps
118
+ print(f['turns']) # number of direction changes (zeros)
119
+ print(f['straightness']) # ratio of direct to path distance
120
+ ```
121
+
122
+ ### Example: 8 = 1000
123
+
124
+ ```python
125
+ import bin2path
126
+
127
+ print(bin2path.encode(8).vertices)
128
+ # [(0, 0, 0), (0, 0, 1), (1, 0, 1), (1, -1, 1), (1, -1, 0)]
129
+ ```
130
+
131
+ ## API Reference
132
+
133
+ ### Core Functions
134
+
135
+ - `encode(number: int) -> Path3D` — Convert number to 3D path
136
+ - `decode(path: Path3D) -> int` — Convert path back to number
137
+ - `features(path: Path3D) -> dict` — Extract features for clustering
138
+ - `visualize(path: Path3D, **kwargs)` — Render 3D visualization
139
+ - `serialize(path) -> dict` — Convert to JSON-serializable dict
140
+ - `deserialize(data) -> Path3D` — Restore from dict
141
+ - `to_json(path) -> str` — Convert to JSON string
142
+ - `from_json(json_str) -> Path3D` — Parse JSON string
143
+ - `compare(path1, path2) -> dict` — Compare similarity between paths
144
+ - `validate(path) -> (bool, list[str])` — Validate path correctness
145
+ - `is_valid(path) -> bool` — Quick validity check
146
+ - `batch_encode(numbers) -> list[Path3D]` — Encode multiple numbers
147
+ - `batch_decode(paths) -> list[int]` — Decode multiple paths
148
+
149
+ ### Path3D Structure
150
+
151
+ ```python
152
+ @dataclass
153
+ class Path3D:
154
+ vertices: list[tuple[int, int, int]] # [(x,y,z), ...]
155
+ edges: list[tuple[int, int]] # [(from_idx, to_idx), ...]
156
+ metadata: PathMetadata # additional info
157
+
158
+ @dataclass
159
+ class PathMetadata:
160
+ original_number: int # original input number
161
+ bits_length: int # length of binary representation
162
+ first_one_pos: int # position of first 1-bit (MSB index)
163
+ step_positions: list[int] # positions of all 1-bits (MSB indices)
164
+ start_direction: tuple # starting forward direction (defaults to +Z)
165
+ ```
166
+
167
+ ### Features
168
+
169
+ The `features()` function returns a dictionary with:
170
+
171
+ - `path_length`: Number of edges/steps
172
+ - `turns`: Approximate number of bit-0 transitions (`bits_length - len(edges)`)
173
+ - `direct_distance`: Straight-line distance from start to end
174
+ - `straightness`: Ratio of direct distance to path length
175
+ - `center_x`, `center_y`, `center_z`: Center of mass coordinates
176
+ - `bbox_x`, `bbox_y`, `bbox_z`: Bounding box dimensions
177
+ - `displacement_x`, `displacement_y`, `displacement_z`: Total displacement
178
+ - `direction_histogram`: Count of steps in ±X/±Y/±Z directions
179
+ - `self_intersections`: Number of vertex revisits
180
+
181
+ ## Examples
182
+
183
+ ### Roundtrip Test
184
+
185
+ ```python
186
+ import bin2path
187
+
188
+ test_numbers = [0, 1, 2, 42, 100, 12345, 2**10, 999999]
189
+ for n in test_numbers:
190
+ path = bin2path.encode(n)
191
+ decoded = bin2path.decode(path)
192
+ assert decoded == n # Always True!
193
+ ```
194
+
195
+ ### Visualization Options
196
+
197
+ ```python
198
+ import bin2path
199
+
200
+ path = bin2path.encode(42)
201
+
202
+ # Basic visualization
203
+ bin2path.visualize(path)
204
+
205
+ # Custom appearance
206
+ bin2path.visualize(
207
+ path,
208
+ figsize=(10, 8),
209
+ vertex_color="red",
210
+ edge_color="blue",
211
+ edge_linewidth=3,
212
+ vertex_size=50,
213
+ )
214
+
215
+ # Save to file
216
+ bin2path.visualize(path, save_path="my_path.png")
217
+
218
+ # Different viewing angle
219
+ bin2path.visualize(path, azim=45, elev=30)
220
+ ```
221
+
222
+ ## Requirements
223
+
224
+ - Python >= 3.10
225
+ - matplotlib >= 3.7.0
226
+ - numpy >= 1.24.0
227
+
228
+ ## License
229
+
230
+ MIT License
231
+
232
+ ## See Also
233
+
234
+ See [`plan.md`](plan.md) for the detailed specification of the scheme (including the local-orientation rules).
@@ -0,0 +1,207 @@
1
+ # bin2path
2
+
3
+ Transform numbers into 3D geometric paths.
4
+
5
+ A Python library for converting natural numbers into 3D geometric shapes (spatial polylines on an integer lattice).
6
+ We use a **cellular-automaton scheme** that produces a sequence of symbolic steps `L/R/U/D`, and then interpret these steps as **local** (orientation-dependent) moves in 3D.
7
+
8
+ ## Concept
9
+
10
+ Each number is represented as a 3D path on an integer lattice via a **discrete step rule**:
11
+
12
+ - We work with the binary representation **MSB → LSB** (left-to-right bits).
13
+ - Each bit is mapped to one of 4 **symbols**: `L/R/U/D`.
14
+ - Each symbol is then interpreted as a **relative 3D move** based on the current orientation (`forward/up/right`), so the path is not constrained to a plane.
15
+
16
+ ### Bits → symbols (cellular automaton)
17
+
18
+ - **First bit**:
19
+ - `0` → first step `L`
20
+ - `1` → first step `R`
21
+ - **Each next bit** (only previous step matters):
22
+ - if bit = `0`:
23
+ - if previous step was `L` → current step `D`
24
+ - otherwise → `L`
25
+ - if bit = `1`:
26
+ - if previous step was `R` → current step `U`
27
+ - otherwise → `R`
28
+
29
+ ### Symbols → 3D steps (local orientation)
30
+
31
+ We maintain a local frame:
32
+
33
+ - `forward` (where “go forward” points)
34
+ - `up` (local up)
35
+ - `right = cross(forward, up)`
36
+
37
+ Initial frame:
38
+
39
+ - `forward = (0, 0, 1)` (along +Z)
40
+ - `up = (0, 1, 0)` (along +Y)
41
+
42
+ Step semantics (rotate if needed, then move 1 unit along the new `forward`):
43
+
44
+ - `R`: move forward
45
+ - `L`: yaw left around `up`, then move forward
46
+ - `U`: pitch up around `right`, then move forward
47
+ - `D`: pitch down around `right`, then move forward
48
+
49
+ So the path is built from `(0,0,0)` by applying these steps.
50
+
51
+ The representation is:
52
+ - **Unique**: Different numbers produce different paths
53
+ - **Reversible**: You can decode the path back to the original number
54
+ - **Deterministic**: Same number always produces same path
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ pip install bin2path
60
+ ```
61
+
62
+ Or from source:
63
+
64
+ ```bash
65
+ git clone https://github.com/Sett11/bin2path.git
66
+ cd bin2path
67
+ pip install -e .
68
+ ```
69
+
70
+ ## Quick Start
71
+
72
+ ```python
73
+ import bin2path
74
+
75
+ # Encode a number to 3D path
76
+ path = bin2path.encode(42)
77
+
78
+ # Get path data
79
+ print(path.vertices) # list of (x,y,z)
80
+ print(path.edges) # list of (from_idx, to_idx)
81
+
82
+ # Decode back to number
83
+ number = bin2path.decode(path) # 42
84
+
85
+ # Visualize
86
+ bin2path.visualize(path)
87
+
88
+ # Extract features for clustering / analysis
89
+ f = bin2path.features(path)
90
+ print(f['path_length']) # number of steps
91
+ print(f['turns']) # number of direction changes (zeros)
92
+ print(f['straightness']) # ratio of direct to path distance
93
+ ```
94
+
95
+ ### Example: 8 = 1000
96
+
97
+ ```python
98
+ import bin2path
99
+
100
+ print(bin2path.encode(8).vertices)
101
+ # [(0, 0, 0), (0, 0, 1), (1, 0, 1), (1, -1, 1), (1, -1, 0)]
102
+ ```
103
+
104
+ ## API Reference
105
+
106
+ ### Core Functions
107
+
108
+ - `encode(number: int) -> Path3D` — Convert number to 3D path
109
+ - `decode(path: Path3D) -> int` — Convert path back to number
110
+ - `features(path: Path3D) -> dict` — Extract features for clustering
111
+ - `visualize(path: Path3D, **kwargs)` — Render 3D visualization
112
+ - `serialize(path) -> dict` — Convert to JSON-serializable dict
113
+ - `deserialize(data) -> Path3D` — Restore from dict
114
+ - `to_json(path) -> str` — Convert to JSON string
115
+ - `from_json(json_str) -> Path3D` — Parse JSON string
116
+ - `compare(path1, path2) -> dict` — Compare similarity between paths
117
+ - `validate(path) -> (bool, list[str])` — Validate path correctness
118
+ - `is_valid(path) -> bool` — Quick validity check
119
+ - `batch_encode(numbers) -> list[Path3D]` — Encode multiple numbers
120
+ - `batch_decode(paths) -> list[int]` — Decode multiple paths
121
+
122
+ ### Path3D Structure
123
+
124
+ ```python
125
+ @dataclass
126
+ class Path3D:
127
+ vertices: list[tuple[int, int, int]] # [(x,y,z), ...]
128
+ edges: list[tuple[int, int]] # [(from_idx, to_idx), ...]
129
+ metadata: PathMetadata # additional info
130
+
131
+ @dataclass
132
+ class PathMetadata:
133
+ original_number: int # original input number
134
+ bits_length: int # length of binary representation
135
+ first_one_pos: int # position of first 1-bit (MSB index)
136
+ step_positions: list[int] # positions of all 1-bits (MSB indices)
137
+ start_direction: tuple # starting forward direction (defaults to +Z)
138
+ ```
139
+
140
+ ### Features
141
+
142
+ The `features()` function returns a dictionary with:
143
+
144
+ - `path_length`: Number of edges/steps
145
+ - `turns`: Approximate number of bit-0 transitions (`bits_length - len(edges)`)
146
+ - `direct_distance`: Straight-line distance from start to end
147
+ - `straightness`: Ratio of direct distance to path length
148
+ - `center_x`, `center_y`, `center_z`: Center of mass coordinates
149
+ - `bbox_x`, `bbox_y`, `bbox_z`: Bounding box dimensions
150
+ - `displacement_x`, `displacement_y`, `displacement_z`: Total displacement
151
+ - `direction_histogram`: Count of steps in ±X/±Y/±Z directions
152
+ - `self_intersections`: Number of vertex revisits
153
+
154
+ ## Examples
155
+
156
+ ### Roundtrip Test
157
+
158
+ ```python
159
+ import bin2path
160
+
161
+ test_numbers = [0, 1, 2, 42, 100, 12345, 2**10, 999999]
162
+ for n in test_numbers:
163
+ path = bin2path.encode(n)
164
+ decoded = bin2path.decode(path)
165
+ assert decoded == n # Always True!
166
+ ```
167
+
168
+ ### Visualization Options
169
+
170
+ ```python
171
+ import bin2path
172
+
173
+ path = bin2path.encode(42)
174
+
175
+ # Basic visualization
176
+ bin2path.visualize(path)
177
+
178
+ # Custom appearance
179
+ bin2path.visualize(
180
+ path,
181
+ figsize=(10, 8),
182
+ vertex_color="red",
183
+ edge_color="blue",
184
+ edge_linewidth=3,
185
+ vertex_size=50,
186
+ )
187
+
188
+ # Save to file
189
+ bin2path.visualize(path, save_path="my_path.png")
190
+
191
+ # Different viewing angle
192
+ bin2path.visualize(path, azim=45, elev=30)
193
+ ```
194
+
195
+ ## Requirements
196
+
197
+ - Python >= 3.10
198
+ - matplotlib >= 3.7.0
199
+ - numpy >= 1.24.0
200
+
201
+ ## License
202
+
203
+ MIT License
204
+
205
+ ## See Also
206
+
207
+ See [`plan.md`](plan.md) for the detailed specification of the scheme (including the local-orientation rules).
@@ -0,0 +1,48 @@
1
+ """
2
+ bin2path - Transform numbers into 3D geometric paths.
3
+
4
+ A library for converting natural numbers into 3D geometric shapes (spatial
5
+ polyline on an integer lattice). Each bit of the binary representation
6
+ is mapped to a symbolic step sequence (L/R/U/D) using a cellular-automaton rule.
7
+ Symbols are then interpreted as local (orientation-dependent) 3D moves, so the
8
+ resulting path is not constrained to a plane.
9
+
10
+ Usage:
11
+ import bin2path
12
+
13
+ path = bin2path.encode(42)
14
+ number = bin2path.decode(path)
15
+ bin2path.visualize(path)
16
+ features = bin2path.features(path)
17
+ """
18
+
19
+ from bin2path.path import Path3D, PathMetadata
20
+ from bin2path.encode import encode
21
+ from bin2path.decode import decode
22
+ from bin2path.features import features
23
+ from bin2path.visualize import visualize
24
+ from bin2path.serialize import serialize, deserialize, to_json, from_json
25
+ from bin2path.compare import compare
26
+ from bin2path.validate import validate, is_valid
27
+ from bin2path.batch import batch_encode, batch_decode
28
+
29
+ __version__ = "0.1.0"
30
+ __author__ = "bin2path"
31
+
32
+ __all__ = [
33
+ "Path3D",
34
+ "PathMetadata",
35
+ "encode",
36
+ "decode",
37
+ "features",
38
+ "visualize",
39
+ "serialize",
40
+ "deserialize",
41
+ "to_json",
42
+ "from_json",
43
+ "compare",
44
+ "validate",
45
+ "is_valid",
46
+ "batch_encode",
47
+ "batch_decode",
48
+ ]