You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/c.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ This code should not compile pedanticly as original ANSI C = C89.
41
41
42
42
## Changes to the C, mandatory and optional ##
43
43
44
-
The C code cannot quite be executed directly out of the box: a few trivial customisations are needed, which are in the <kbd>controls.c</kbd> file.
44
+
The C code cannot quite be executed directly out of the box: a few trivial customisations are needed, which are in the [<kbd>controls.c</kbd>](../C/controls.c) file.
45
45
46
46
***Most important**: to what directory should output go, as used by <code>fopen(…, "w")</code>?
47
47
This is in `filePath_staticConst[]`, which has default value `"/Users/JDAW/Documents/outputPenrose/"`.
@@ -53,7 +53,7 @@ By default, these call Chrome and Adobe Distiller, in my computer’s locati
53
53
These calls are made by the <code>system(…)</code> command, which could in theory do anything, so check that your (and indeed, my) invocations are safe.
54
54
Or, to have them do nothing, replace both of these <code>execute_…</code> routines with a do‑nothing `{return;}`.
55
55
56
-
The optional customisations are also within the <kbd>controls.c</kbd> file.
56
+
The optional customisations are also within the [<kbd>controls.c</kbd>](../C/controls.c) file.
57
57
58
58
* There are many file types of possible output, which could be output for all the `tilingId`s.
59
59
Which is to be output is controlled by `exportQ()`.
@@ -153,7 +153,7 @@ The following is an overrview, but only an overview, of the workings of the code
153
153
154
154
### The header ###
155
155
156
-
There is a single header file, <kbd>penrose.h</kbd>, which:
156
+
There is a single header file, [<kbd>penrose.h</kbd>](../C/penrose.h), which:
157
157
*`#include`s multiple library headers;
158
158
* declares and defines various `static double const`,
159
159
* declares types, both simple aliases, `enum`s, and `struct`s;
@@ -162,23 +162,23 @@ There is a single header file, <kbd>penrose.h</kbd>, which:
162
162
163
163
### Functions ###
164
164
165
-
As explained above, in <kbd>controls.c</kbd> are multiple definitions needing, or perhaps needing, user attention.
165
+
As explained above, in [<kbd>controls.c</kbd>](../C/controls.c) are multiple definitions needing, or perhaps needing, user attention.
166
166
167
-
<kbd>main.c</kbd> asks <samp>"What is to be the recursion depth = numTilings?"</samp>, with an `fscanf()` into `numTilings`.
167
+
[<kbd>main.c</kbd>](../C/main.c) asks <samp>"What is to be the recursion depth = numTilings?"</samp>, with an `fscanf()` into `numTilings`.
168
168
There is a `malloc()` of this length, and trivial initialisation.
169
169
The showtime loop: <code>if( tilingId == 0 )</code> it calls `tiling_initial()`; otherwise passing the previous tiling into `tiling_descendant()`.
170
170
171
-
These two, `tiling_initial()` and `tiling_descendant()`, are in <kbd>tilings.c</kbd>.
171
+
These two, `tiling_initial()` and `tiling_descendant()`, are in [<kbd>tilings.c</kbd>](../C/tilings.c).
172
172
The latter is more complicated; the former creates an initial rhombus and does much as the former.
173
173
These invoke much work.
174
174
175
175
* Computes `rhombii_NumMax`, and `malloc()` enough space for that many rhombii.
176
176
177
-
* For each rhombus in the ancestor tiling, appends its descendants to the descendant tiling by repeated calls of `rhombus_append_descendants` (which is in <kbd>rhombii.c</kbd>).
178
-
When almost `rhombii_NumMax` rhombii have been created, space is freed by `rhombii_purgeDuplicates()` (which is in <kbd>purgeDuplicates.c</kbd>), which is called again after the loop.
177
+
* For each rhombus in the ancestor tiling, appends its descendants to the descendant tiling by repeated calls of `rhombus_append_descendants` (which is in [<kbd>rhombii.c</kbd>](../C/rhombii.c)).
178
+
When almost `rhombii_NumMax` rhombii have been created, space is freed by `rhombii_purgeDuplicates()` (which is in [<kbd>purgeDuplicates.c</kbd>](../C/purgeDuplicates.c)), which is called again after the loop.
179
179
180
-
* Then `neighbours_populate()` (which is in <kbd>neighbours.c</kbd>), and self-evidently populates the neighbours of each rhombus.
181
-
Both this and the earlier duplicate-purging work with rhombii sorted by the *y* position, as done by `rhombii_sort()` in <kbd>sortRhombii.c</kbd>.
180
+
* Then `neighbours_populate()` (which is in [<kbd>neighbours.c</kbd>](../C/neighbours.c)), and self-evidently populates the neighbours of each rhombus.
181
+
Both this and the earlier duplicate-purging work with rhombii sorted by the *y* position, as done by `rhombii_sort()` in [<kbd>sortRhombii.c</kbd>](../C/sortRhombii.c).
182
182
183
183
* The next work is the most interesting. There is a call of `holesFill()`.
184
184
Let’s start with two examples, both using [the example tiling](../images/Penrose_Rh_10_clipped_norths.svg) at the top of the [Paths page](paths.md).
@@ -211,25 +211,25 @@ And there are other positions for which holes or gaps have a unique completion,
211
211
212
212
These extra rhombii require neighbourification, and for some of the `holesFill()` patterns, re-de-duplication.
213
213
214
-
* <kbd>paths.c</kbd> finds paths. Naturally enough, start at an as-yet-unpathed fat rhombus, and trace using neighbours. If it is an open path, then on coming to an end it restarts from there. For closed paths, there a rhombus must be chosen to have zero `.withinPathNum`, so to be the first rhombus of the path. This is chosen by `rhWithinPathMoreSpecial()` to be one of the rhombii that is as close as possible to the centre of the path, and in the first quadrant.
214
+
*[<kbd>paths.c</kbd>](../C/paths.c) finds paths. Naturally enough, start at an as-yet-unpathed fat rhombus, and trace using neighbours. If it is an open path, then on coming to an end it restarts from there. For closed paths, there a rhombus must be chosen to have zero `.withinPathNum`, so to be the first rhombus of the path. This is chosen by `rhWithinPathMoreSpecial()` to be one of the rhombii that is as close as possible to the centre of the path, and in the first quadrant.
215
215
216
216
* Which is the smallest enclosing path? But the level of the question varies.
217
217
- Open paths cannot have an enclosing path.
218
218
- Closed paths can, though not all do. So for fat rhombii, enclosing-path is at the level of the path.
219
219
- But for thin rhombii, it is at the level of the rhombus. For thin rhombii, find a touching fat, and either the thin is immediately inside that fat’s path, or the answer is the same as for that fat’s path.
220
220
221
-
Insideness is computed in <kbd>insideness.c</kbd>, which makes much use of <kbd>windingNumber.c</kbd>.
221
+
Insideness is computed in [<kbd>insideness.c</kbd>](../C/insideness.c), which makes much use of [<kbd>windingNumber.c</kbd>](../C/windingNumber.c).
222
222
Because there are many candidate enclosing paths to be tested, this is potentially slow.
223
223
224
224
* For each length of path, how many paths are there?
225
225
How many fats and thins are enclosed?
226
226
What are the minimum and maximum radii?
227
-
This data is gathered by <kbd>pathStats.c</kbd>.
227
+
This data is gathered by [<kbd>pathStats.c</kbd>](../C/pathStats.c).
228
228
229
-
* When making `holesFill()`, some properties were observed, and were checked over some good-size tilings by a routine `verifyHypothesisedProperties()` in <kbd>propertyVerifying.c</kbd>.
229
+
* When making `holesFill()`, some properties were observed, and were checked over some good-size tilings by a routine `verifyHypothesisedProperties()` in [<kbd>propertyVerifying.c</kbd>](../C/propertyVerifying.c).
230
230
The routine remains, in case similar is needed, but currently does nothing.
231
231
232
-
* Arrays needs sorting, requiring renumbering of pointers into into them. Already mentioned are `rhombii_sort()` in <kbd>sortRhombii.c</kbd>; also `paths_sort()` in <kbd>sortPaths.c</kbd>; and `pathStats_sort()` in <kbd>sortPathStats.c</kbd>.
232
+
* Arrays needs sorting, requiring renumbering of pointers into into them. Already mentioned are `rhombii_sort()` in [<kbd>sortRhombii.c</kbd>](../C/sortRhombii.c); also `paths_sort()` in [<kbd>sortPaths.c</kbd>](../C/sortPaths.c); and `pathStats_sort()` in [<kbd>sortPathStats.c</kbd>](../C/sortPathStats.c).
233
233
234
234
* PostScript ([wikipedia](http://en.wikipedia.org/wiki/PostScript), [Adobe’s PostScript Language Reference 3<small><sup>rd</sup></small> edition](https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf)) is an an early-1980s printer-control language.
235
235
It is a delightful simple clean text-based user-alterable [Turing-complete](https://en.wikipedia.org/wiki/Turing_completeness) means of making [PDF](https://en.wikipedia.org/wiki/PDF)s.
@@ -238,25 +238,25 @@ And there are other positions for which holes or gaps have a unique completion,
238
238
For example, arrays and data structures have a maximum length of 2<small><sup>16</sup></small> − 1 = 65,535 ([PLRM3, Appendix B, p739](https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf#page=753), table B.1, row 3).
239
239
That is, for all `tilingId` ≥ 10, it is not possible to output all the data in a PostScript object.
240
240
Instead a ‘wanted’ subset is chosen.
241
-
In <kbd>controls.c</kbd> there are functions `wantedPostScriptCentre()` which returns the centre of the desired region, and `wantedPostScriptAspect()` which returns the desired _y_/_x_ aspect ratio.
241
+
In [<kbd>controls.c</kbd>](../C/controls.c) there are functions `wantedPostScriptCentre()` which returns the centre of the desired region, and `wantedPostScriptAspect()` which returns the desired _y_/_x_ aspect ratio.
242
242
The largest possible area is then chosen, such that there are ≤ 65535 rhombii (sometimes _x_ or _y_ equalities compel the number of rhombii to be slightly less than 65535).
243
243
(The other two PostScript output formats merely paint one thing after another, so never need a large PostScript array, and hence can cope with lots of stuff.)
244
244
245
-
* Some minor and small administration functions are in <kbd>smalls.c</kbd>. Numbers comparisons (which perhaps should have been overloaded, but which weren’t): `max_2()`, `min_2()`, `max_4()`, `min_4()`, `avg_2()`, `median_3()`, `median_4()`. Point comparisons (ditto): `points_different_2()`, `points_same_2()`, `points_different_3()`, `points_same_3()`, `points_different_4()`, `points_same_4()`, `collinear()`. Small exporting helpers: `newlinesInString()`, `fileExtension_from_ExportFormat()`.
245
+
* Some minor and small administration functions are in [<kbd>smalls.c</kbd>](../C/smalls.c). Numbers comparisons (which perhaps should have been overloaded, but which weren’t): `max_2()`, `min_2()`, `max_4()`, `min_4()`, `avg_2()`, `median_3()`, `median_4()`. Point comparisons (ditto): `points_different_2()`, `points_same_2()`, `points_different_3()`, `points_same_3()`, `points_different_4()`, `points_same_4()`, `collinear()`. Small exporting helpers: `newlinesInString()`, `fileExtension_from_ExportFormat()`.
246
246
247
247
248
248
### Exporting code ###
249
249
250
-
* There is occasional need to `sprintf()` to a string, for subsequent use. So <kbd>exportTilings.c</kbd> creates `scratchString[]` of length 32767, which many export routines access with `extern char scratchString[];`.
250
+
* There is occasional need to `sprintf()` to a string, for subsequent use. So [<kbd>exportTilings.c</kbd>](../C/exportTilings.c) creates `scratchString[]` of length 32767, which many export routines access with `extern char scratchString[];`.
251
251
252
-
* Some of the output files are large. There should be some effort to not enlarge them needlessly. In particular, the likes of “<samp>1.000000000</samp>” should be trimmed to “<samp>1</samp>”. This should not be done with scientific notation: if an _x_ or _y_ value is almost zero, then it should be “<samp>0</samp>” rather than “<samp>-1.234567E-89</samp>”. So there is a routine `stringClean()`, in <kbd>stringClean.c</kbd>, which cleans a string in this style. Almost always, the string passed to this is `scratchString`.
252
+
* Some of the output files are large. There should be some effort to not enlarge them needlessly. In particular, the likes of “<samp>1.000000000</samp>” should be trimmed to “<samp>1</samp>”. This should not be done with scientific notation: if an _x_ or _y_ value is almost zero, then it should be “<samp>0</samp>” rather than “<samp>-1.234567E-89</samp>”. So there is a routine `stringClean()`, in [<kbd>stringClean.c</kbd>](../C/stringClean.c), which cleans a string in this style. Almost always, the string passed to this is `scratchString`.
253
253
254
254
255
255
There are two very different types of export format.
256
256
257
-
* Those with `enum``ExportFormat` values {`JSON`, `TSV`, `PS_data`} hold data from multiple tilings, for subsequent processing. In <kbd>exportTilings.c</kbd> it loops over tilings, calling code in <kbd>exportTiling.c</kbd>. Each of these loops over arrays, so repeatedly calling code in <kbd>exportPathStats.c</kbd>, in <kbd>exportPath.c</kbd>, and in <kbd>exportRh.c</kbd>. For `TSV`the passed item can be a `NULL` pointer, instructing thar that the header row be output.
257
+
* Those with `enum``ExportFormat` values {`JSON`, `TSV`, `PS_data`} hold data from multiple tilings, for subsequent processing. In [<kbd>exportTilings.c</kbd>](../C/exportTilings.c) it loops over tilings, calling code in [<kbd>exportTiling.c</kbd>](../C/exportTiling.c). Each of these loops over arrays, so repeatedly calling code in <kbd>exportPathStats.c</kbd>, in [<kbd>exportPath.c</kbd>](../C/exportPath.c), and in [<kbd>exportRh.c</kbd>](../C/exportRh.c). For `TSV`the passed item can be a `NULL` pointer, instructing that the header row be output.
258
258
259
-
* Those with `enum``ExportFormat` values {`PS_rhomb`, `PS_arcs`, `SVG_rhomb`, `SVG_arcs`} output something useful as-is. That is, an SVG can be viewed; a PostScript file can be distilled (using [Adobe Distiller](https://en.wikipedia.org/wiki/Adobe_Distiller) or [Ghostscript](https://en.wikipedia.org/wiki/Ghostscript)) into a PDF. For these, code in <kbd>export_SoloTiling.c</kbd> calls the appropriate one of <kbd>export_PaintArcsPS.c</kbd>, <kbd>export_PaintArcsSVG.c</kbd>, <kbd>export_PaintRhPS.c</kbd>, <kbd>export_PaintRhSVG.c</kbd>. Some SVG processing is in <kbd>Smalls_SVG.c</kbd>.
259
+
* Those with `enum``ExportFormat` values {`PS_rhomb`, `PS_arcs`, `SVG_rhomb`, `SVG_arcs`} output something useful as-is. That is, an SVG can be viewed; a PostScript file can be distilled (using [Adobe Distiller](https://en.wikipedia.org/wiki/Adobe_Distiller) or [Ghostscript](https://en.wikipedia.org/wiki/Ghostscript)) into a PDF. For these, code in [<kbd>export_SoloTiling.c</kbd>](../C/export_SoloTiling.c) calls the appropriate one of [<kbd>export_PaintArcsPS.c</kbd>](../C/export_PaintArcsPS.c), [<kbd>export_PaintArcsSVG.c</kbd>](../C/export_PaintArcsSVG.c), [<kbd>export_PaintRhPS.c</kbd>](../C/export_PaintRhPS.c), [<kbd>export_PaintRhSVG.c</kbd>](../C/export_PaintRhSVG.c). Some SVG processing is in [<kbd>Smalls_SVG.c</kbd>](../C/Smalls_SVG.c).
0 commit comments