Skip to content

Commit 0cf3c4f

Browse files
committed
Per row output to increase buffer.
1 parent 993a8ce commit 0cf3c4f

File tree

3 files changed

+75
-41
lines changed

3 files changed

+75
-41
lines changed

list2mesh/list2dxf.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@
6969
# per pyramid write(''.join(list)), ca. 19% speedup.
7070
# 3.23.13.13 All docstrings go to ReST.
7171
# 3.26.10.10 Pixel reading scheme changed.
72+
# 3.27.10.10 Turned to per row output to increase buffer.
7273

7374
__author__ = 'Ilya Razmanov'
7475
__copyright__ = '(c) 2024-2026 Ilya Razmanov'
7576
__credits__ = 'Ilya Razmanov'
7677
__license__ = 'unlicense'
77-
__version__ = '3.27.8.1'
78+
__version__ = '3.27.10.10'
7879
__maintainer__ = 'Ilya Razmanov'
7980
__email__ = 'ilyarazmanov@gmail.com'
8081
__status__ = 'Production'
@@ -196,6 +197,7 @@ def _y_out(y: int, shift: float) -> float:
196197
# ↑ Not needed for Python but Ruff gets mad about "Undefined name" without it.
197198

198199
for y in range(Y - 1):
200+
row = [] # Starting a row of pyramids.
199201
for x in range(X - 1):
200202
if x > 0:
201203
v1 = v2
@@ -263,12 +265,11 @@ def _y_out(y: int, shift: float) -> float:
263265
]
264266
)
265267

266-
# ↓ Built pyramid as list, now writing pyramid
267-
# as single string in attempt to reduce disk access.
268-
# .write(.join(pyramid)) gives ca. 20% speed up vs .writelines()
269-
resultfile.write(''.join(pyramid))
270-
271-
# ↑ Pyramid construction complete. Ave me!
268+
# ↓ Pyramid construction complete. Ave me!
269+
# Now adding it to a row.
270+
row.extend(pyramid)
271+
# ↓ Finally writing a row to file.
272+
resultfile.write(''.join(row))
272273

273274
resultfile.write('ENDSEC\n0\nEOF\n') # closing object
274275

list2mesh/list2obj.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@
6969
# per pyramid write(''.join(list)), ca. 20% speedup.
7070
# 3.23.13.13 All docstrings go to ReST.
7171
# 3.26.10.10 Pixel reading scheme changed.
72+
# 3.27.10.10 Turned to per row output to increase buffer.
7273

7374
__author__ = 'Ilya Razmanov'
7475
__copyright__ = '(c) 2024-2026 Ilya Razmanov'
7576
__credits__ = 'Ilya Razmanov'
7677
__license__ = 'unlicense'
77-
__version__ = '3.27.8.1'
78+
__version__ = '3.27.10.10'
7879
__maintainer__ = 'Ilya Razmanov'
7980
__email__ = 'ilyarazmanov@gmail.com'
8081
__status__ = 'Production'
@@ -190,6 +191,7 @@ def _y_out(y: int, shift: float) -> float:
190191
# ↑ Not needed for Python but Ruff gets mad about "Undefined name" without it.
191192

192193
for y in range(Y - 1):
194+
row = [] # Starting a row of pyramids.
193195
for x in range(X - 1):
194196
if x > 0:
195197
v1 = v2
@@ -215,6 +217,7 @@ def _y_out(y: int, shift: float) -> float:
215217
# ↓ Finally going to build a pyramid!
216218
# Triangles are described clockwise, then connection order reset counterclockwise.
217219
pyramid = []
220+
218221
if (v1 + v2 + v0) > (0.5 / maxcolors):
219222
pyramid.extend(
220223
[
@@ -252,12 +255,11 @@ def _y_out(y: int, shift: float) -> float:
252255
]
253256
) # ↑ triangle 4-1-0, order changed to counterclockwise
254257

255-
# ↓ Built pyramid as list, now writing pyramid
256-
# as single string in attempt to reduce disk access.
257-
# .write(.join(pyramid)) gives ca. 20% speed up vs .writelines()
258-
resultfile.write(''.join(pyramid))
259-
260-
# ↑ Pyramid construction complete. Ave me!
258+
# ↓ Pyramid construction complete. Ave me!
259+
# Now adding it to a row.
260+
row.extend(pyramid)
261+
# ↓ Finally writing a row to file.
262+
resultfile.write(''.join(row))
261263

262264
resultfile.write('# end pryanik_nepechatnyj') # closing object
263265

list2mesh/list2pov.py

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@
7676
# Threshold set ad hoc and needs more experiments.
7777
# 3.23.13.13 All docstrings go to ReST.
7878
# 3.26.10.10 Pixel reading scheme changed.
79+
# 3.27.10.10 Rewritten from condensed f-strings to sparse list
80+
# in attempt to make it easier to edit further.
81+
# Turned to per row output to increase buffer.
7982

8083
__author__ = 'Ilya Razmanov'
8184
__copyright__ = '(c) 2023-2026 Ilya Razmanov'
8285
__credits__ = 'Ilya Razmanov'
8386
__license__ = 'unlicense'
84-
__version__ = '3.27.8.1'
87+
__version__ = '3.27.10.10'
8588
__maintainer__ = 'Ilya Razmanov'
8689
__email__ = 'ilyarazmanov@gmail.com'
8790
__status__ = 'Production'
@@ -280,9 +283,9 @@ def _src_lum_blin(x: float, y: float) -> float:
280283
' pigment {',
281284
' gradient z',
282285
' colour_map {',
283-
' [0.0, rgb <1, 0, 0>]',
284-
' [0.5, rgb <0, 0, 1>]',
285-
' [1.0, rgb <1, 1, 1>]',
286+
' [0.0, rgb <1, 0, 0>]', # [0.0, rgb <0.0, 1.5, 0.0>]
287+
' [0.5, rgb <0, 0, 1>]', # [0.5, rgb <0.88, 0.62, 0>]
288+
' [1.0, rgb <1, 1, 1>]', # [1.0, rgb <1.5, 0.0, 0.0>]
286289
' }',
287290
' }',
288291
' finish {phong 1.0}',
@@ -344,8 +347,7 @@ def _y_out(y: int, shift: float) -> float:
344347
# ↑ Not needed for Python but Ruff gets mad about "Undefined name" without it.
345348

346349
for y in range(Y - 1): # Mesh includes extra pixels at the right and below, therefore -1
347-
resultfile.write(f'\n\n // Row {y}')
348-
350+
row = [f'\n\n // Row {y}'] # Starting a row of pyramids.
349351
for x in range(X - 1): # Mesh includes extra pixels at the right and below, therefore -1
350352
"""Pixel order around default pixel 1.
351353
┌───┬───┐
@@ -378,36 +380,65 @@ def _y_out(y: int, shift: float) -> float:
378380

379381
# ↓ Finally going to build a pyramid!
380382
# Triangles are described clockwise.
383+
pyramid = []
381384

385+
# ↓ Triangle 1-2-0
382386
if (v1 + v2 + v0) > (0.5 / maxcolors):
383-
triangle_120 = f'\n triangle {{<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}'
384-
# ↑ Triangle 1-2-0
385-
else:
386-
triangle_120 = ''
387+
pyramid.extend([
388+
'\n triangle{',
389+
f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})>',
390+
391+
f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})>',
387392

393+
f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>',
394+
'}',
395+
])
396+
# ↑ Triangle 1-2-0
397+
398+
# ↓ Triangle 2-3-0
388399
if (v0 + v2 + v3) > (0.5 / maxcolors):
389-
triangle_230 = f'\n triangle {{<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}'
390-
# ↑ Triangle 2-3-0
391-
else:
392-
triangle_230 = ''
400+
pyramid.extend([
401+
'\n triangle{',
402+
f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v2:.{PRECISION}}".rstrip("0").rstrip(".")})>',
403+
404+
f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})>',
393405

406+
f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>',
407+
'}',
408+
])
409+
# ↑ Triangle 2-3-0
410+
411+
# ↓ Triangle 3-4-0
394412
if (v0 + v3 + v4) > (0.5 / maxcolors):
395-
triangle_340 = f'\n triangle {{<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}'
396-
# ↑ Triangle 3-4-0
397-
else:
398-
triangle_340 = ''
413+
pyramid.extend([
414+
'\n triangle{',
415+
f'<{f"{_x_out(x, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v3:.{PRECISION}}".rstrip("0").rstrip(".")})>',
399416

400-
if (v0 + v1 + v4) > (0.5 / maxcolors):
401-
triangle_410 = f'\n triangle {{<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})> <{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>}}'
402-
# ↑ Triangle 4-1-0
403-
else:
404-
triangle_410 = ''
417+
f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})>',
405418

406-
# ↓ Built triangles as four strings, now writing pyramid
407-
# as single string in attempt to reduce disk access.
408-
resultfile.write(f'{triangle_120}{triangle_230}{triangle_340}{triangle_410}')
419+
f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>',
420+
'}',
421+
])
422+
# ↑ Triangle 3-4-0
409423

410-
# ↑ Pyramid construction complete. Ave me!
424+
# ↓ Triangle 4-1-0
425+
if (v0 + v1 + v4) > (0.5 / maxcolors):
426+
pyramid.extend([
427+
'\n triangle{'
428+
f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 1):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v4:.{PRECISION}}".rstrip("0").rstrip(".")})>',
429+
430+
f'<{f"{_x_out(x, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v1:.{PRECISION}}".rstrip("0").rstrip(".")})>',
431+
432+
f'<{f"{_x_out(x, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, {f"{_y_out(y, 0.5):.{PRECISION}}".rstrip("0").rstrip(".")}, Map({f"{v0:.{PRECISION}}".rstrip("0").rstrip(".")})>',
433+
'}',
434+
])
435+
# ↑ Triangle 4-1-0
436+
437+
# ↓ Pyramid construction complete. Ave me!
438+
# Now adding it to a row.
439+
row.extend(pyramid)
440+
# ↓ Finally writing a row to file.
441+
resultfile.write(''.join(row))
411442

412443
resultfile.write(
413444
'\n'.join(

0 commit comments

Comments
 (0)