Corridor Numerics العربية
Menu

Open source · MIT · Preview 0.3

What did the codec save on this drawing?

The rectangular cassette drawing from the F1 bench occupies 142,986 bytes as STEP text. The published comparison starts with that particular file and checks whether it comes back intact.

File benchmark. Compare the codec with ordinary compressors on the same drawing. To repeat the test on your own work, record the file, compressed size, time to restore it and whether every byte matches.

Compare the published sizes
One part from the open aperture bench

The rectangular cassette

Original STEP file · 142,986 bytes

Brotli 11
14,298 B
CN preview 0.1
4,300 B
CN preview 0.2 · default
3,393 B
CN preview 0.3 · default
3,357 B

Complete packed files, in bytes. Brotli 11 was the smallest of the eight conventional settings we tried on this part. All four packed files restored exactly.

Inside the codec

What repeats inside a STEP file?

A CAD exporter might write a surface as a list of numbered points. Three references such as #1201, #1202, #1203 repeat most of their digits. Once the reader knows the first number, two steps of +1 describe the next two. The codec can store these steps together, away from the words that describe the surface.

Preview 0.3 can build a dictionary of frequently repeated coordinate values and store a short code wherever a value recurs. When the exporter wrote 1.000, the reader must return all three zeros. The encoder tries several layouts, keeps the smallest complete file it made, then restores it and compares the bytes with the input before saving.

You can pack other single files up to 64 MiB. Eligible STEP text and NOAA SURFRAD solar records up to 8 MiB get extra, format-specific choices. On a small or already compressed input, the bytes needed to describe the packed file can outweigh the saving.

Measured STEP files

How much smaller did the drawings get?

We packed each original drawing separately and checked that it restored byte for byte. The tables add up the complete packed files, including their headers. Each savings column uses its group’s original byte count.

Four further drawings

Three public NIST drawings and one private engineering file.

4,988,119 original bytes

MethodPacked
bytes
Saved vs.
original
Codec 0.3 · default451,7164,536,40390.94%
Codec 0.3 · with Brotli444,9054,543,21491.08%
.stpZ · Deflate 91,015,2373,972,88279.65%
XZ · level 6662,6924,325,42786.71%
Smallest of eight controls per file649,3134,338,80686.98%

With Brotli enabled, 0.3 saved 204,408 bytes (31.48%) against the smallest conventional output for each file. Preview 0.2 with Brotli used 452,008 bytes. The update saved 7,103 more bytes (1.57%).

15 previously studied drawings

Six open bench drawings and nine public NIST drawings.

18,766,338 original bytes

MethodPacked
bytes
Saved vs.
original
Codec 0.3 · default3,042,02315,724,31583.79%
Codec 0.3 · with Brotli3,033,99915,732,33983.83%
.stpZ · Deflate 94,989,38813,776,95073.41%
XZ · level 63,411,04015,355,29881.82%
Smallest of eight controls per file3,402,02815,364,31081.87%

With Brotli enabled, 0.3 saved 368,029 bytes (10.82%) against the smallest conventional output for each file. Preview 0.2 with Brotli used 3,047,965 bytes. The update saved 13,966 more bytes (0.46%).

The eight conventional settings were ZIP-based .stpZ (Deflate 6 and 9), gzip 9, bzip2 9, Zstandard 19, Brotli 11 and XZ 6 and 9. “Smallest” selects the shortest result separately for each drawing, then adds them. These comparisons measure storage size. Encoding time, drawing structure and exporter also matter when choosing a method.

Hands-on

Try the same cassette.

Extract the preview kit and the open-bench fixture kit. From the fixture kit’s hardware folder, copy A1_RECT_cassette.step next to cn-preview.pyz in the preview kit. Open a terminal there and run these commands with Python 3.9 or later. The default test runs offline.

python3 cn-preview.pyz pack A1_RECT_cassette.step cassette.cn
python3 cn-preview.pyz inspect cassette.cn
python3 cn-preview.pyz unpack cassette.cn restored.step
cmp A1_RECT_cassette.step restored.step

Preview 0.3 produces 3,357 bytes for this cassette with the default settings. inspect shows which encoding won. On macOS and Linux, cmp exits silently when the files match. On Windows, use py -3 for Python and fc.exe /b A1_RECT_cassette.step restored.step for the comparison.

To try optional Brotli, install its executable and add --with-brotli to the pack command, using a new output name. If Brotli wins, the recipient needs it to restore that file.

Research connection

What connects this to the aperture paper?

Both projects ask what information a reader needs. For a CAD archive, the answer is every original byte. For an optical simulation, a reader may only need the fraction of light that passes through a recess at a given angle.

The kit includes a separate geometry format called GX01. It stores a compact description of an ideal straight recess and lets you query its transmission. The example rectangle gives a predicted transmission of 0.75 at horizontal slope 0.5. You can check the numerical error bound of 0.010 against the input geometry. The physical bench is how we plan to test the prediction on a built part.

Independent tests

Bring a file from your field.

A particularly useful test is a STEP export from a CAD tool we have yet to try. Pack it at default settings and compare it with the tool you ordinarily use. Share the complete byte counts, the codec version, the method shown by inspect and whether the restored file matched. If you time it, list the machine, software versions and which steps you timed.

You can report a larger output, a slow restore or an unreadable file. A public sample or a reproducible description is enough to start. Keep private drawings on your machine.

Development

Improve the next release.

The MIT-licensed source includes the encoder, decoder, format notes and tests. To propose a different encoding, bring an example it helps, the comparison you used and a test showing that the original comes back intact. The test suite also checks that earlier preview files still open.