Skip to content

Technical indexing

JeremyF edited this page Apr 20, 2020 · 14 revisions

Syntax

Any comment not preceded by a character, that contains any amount of spaces followed by [digit] or [digit.digit]. Regex : (?!\w+)\s*//(?!\s*\w)(\s*\[.*\d+\.\d+.*\].*|.*\[.*\d+.*\].*)

app

[ 1.0 ] Main class of the application

  Creates the THREE.js canvas containing
  the interesting part of the app.

[ 1.1 ] Re-sizing of the Canvas

[ 2.0 ] Application state variables

  Shared and used between many files

[ 3.0 ] Tiling manipulation controls

  See Tiling.js [ 2.0 ]

[ 3.1 ] Apply one sandpile step

  Tiling.js [ 2.2 ] [ 2.6 ]

[ 3.2 ] Apply multiple steps and color

  Tiling.js [ 2.2 ] [ 2.6 ]

[ 3.3 ] Assign sandpile identity to

  		the currentIdentity variable.
  Tiling.js [ 2.4 ] [ 2.5 ]

[ 3.4 ] Stabilize the current Tiling

  Tiling.js [ 2.5 ]

[ 3.5 ] Empty the Tiling

  Tiling.js [ 2.4 ]

[ 3.6 ] Adding, Subtracting and setting

  		complex operations over the
  		current Tiling.
  
  This section could be improved ...

  Tiling.js [ 2.3 ] [ 2.4 ] [ 2.5 ]

[ 4.0 ] Tiling display controls

  See Tiling [ 2.0 ]

[ 4.1 ] Main play function

[ 4.2 ] Either play, or pause

[ 4.3 ] Shift hue of selected tile

  	Called by a routine.

[ 4.4 ] Display border of tiles.

[ 4.5 ] Draws currentTiling on

  		the THREE.js Canvas.

  App.js [ 1.0 ]

[ 5.0 ] Misc Functions

[ 5.1 ] JS implementation of sleep

[ 5.2 ] Refresh the zoom according to

  		the html element.

  	Called by a routine.

[ 5.3 ] Locally saves tiling

[ 6.0 ] Mouse Click

  See Tiling 

Tiling

[ 1.0 ] Representation of any Tile

  The tile contains a list of its neighbors,
  all tiles are included in a Tiling.			
  See [ 2.0 ]

[1.1] homemade Tile cloning method

[1.2] geometric transformations of a tile (scale, shift, rotate)

[ 2.0 ] Representation of any Tiling

  This class contains maily a list of
  Tiles, which themselves contains 
  references to their neighbors.

  This class also contains the THREE.js
  Objects displayed in the app.

[ 2.1 ] The Tiling object takes in

[ 2.2 ] Apply one sandpile step

[ 2.3 ] Basic operation functions

[ 2.4 ] "Everywhere" operations

[ 2.5 ] Complex operations

[ 2.6 ] Coloring and display

Tiling2

[ 1.0 ] Representation of any Tile

  The tile contains a list of its neighbors,
  all tiles are included in a Tiling.			
  See [ 2.0 ]

[ 2.0 ] Representation of any Tiling

  This class contains maily a list of
  Tiles, which themselves contains 
  references to their neighbors.

  This class also contains the THREE.js
  Objects displayed in the app.

[ 2.1 ] The Tiling object takes in

[ 2.2 ] Apply one sandpile step

[ 2.3 ] Basic operation functions

[ 2.4 ] "Everywhere" operations

[ 2.5 ] Complex operations

[ 2.6 ] Coloring and display

ChangeDisplay

[ 1.0 ] GUI Functions

  Used directly by Sandpiles.html

[ 2.0 ] Color picking window

  See Tiling.js [ 2.0 ] and [ 2.6 ]
  for the use of colormaps.

[ 2.1 ] Re-build the content of the

[ 2.2 ] Manages presets

[ 3.0 ] Misc display Functions

  Used directly by Sandpiles.html

Harmonics

[ 1.0 ] Apply Square Tiling harmonics

ImportExport

[ 1.0 ] JSON Translation of Tilings

[ 2.0 ] Tiling Download

Roundness

[ 1.0 ] Measures the roundness of

  		the operation max_stable +
  		Identity.
  		Calculates radius by estimating
  		the center of mass of the tiling,
  		or by measuring from the center
  		of canvas space.

  This section could be improved.
  	-> Make a better center estimation
  	-> Let the user choose or not to compute the estimated center
  	-> Apply direclty max_stable + identity

[ 2.0 ] Creates a file corresponding

  		to all measures of roundness

[ 3.0 ] Roundness file download

  Same as ImportExport.js [ 2.0 ]

Stats

[ 1.0 ] Produces various measure of the

  		toppling of the Tiling.

[ 1.1 ] Display various measures

  		of the current Tiling.

[ 2.0 ] Stats file download

  Same as ImportExport.js [ 2.0 ]

AmmannBeenkerA5Substitution

[0] toolbox

[1] define tile types A5

[2] define substitution A5

[3] defined duplicated tile informations A5

[4] fill neighbors informations in A5 newtiles (by side effect)

[6] use default neighbors2bounds

[7] construct base tilings and call substitute

[7.1] construct "Ammann-Beenker by subst" tiling by substitution

BirdsBeesSubstitution

[0] toolbox

[1] define tile types bird, bee, rien

[2] define substitution BB

[3] no duplicated tiles

[4] I am lazy

[6] use default neighbors2bounds

[7] construct base tilings and call substitute

[7.1] construct "Birds and Bees 1 by subst" tiling by substitution

PenroseP2Substitution

[0] toolbox

[1] define tile types P2

[2] define substitution P2

[3] defined duplicated tile informations P2

[4] fill neighbors informations in P2 newtiles (by side effect)

[6] use default neighbors2bounds

[7] construct base tilings and call substitute

[7.1] construct "P2 (kite-dart) Sun by subst" tiling by substitution

[7.2] construct "P2 (kite-dart) Star by subst" tiling by substitution

PenroseP3Substitution

[0] toolbox

[1] define tile types P3

[2] define substitution P3

[3] defined duplicated tile informations P3

[4] fill neighbors informations in P3 newtiles (by side effect)

[6] use default neighbors2bounds

[7] construct base tilings and call substitute

[7.1] construct "P3 (rhomb) Star1 by subst" tiling by substitution

[7.2] construct "P3 (rhomb) Star2 by subst" tiling by substitution

[7.3] construct "P3 (rhomb) Sun by subst" tiling by substitution

PenroseTiling

[ 1.0 ] Penrose generation main variables

[ 2.0 ] Penrose generation main functions

[ 3.0 ] Penrose generation split functions

[ 4.0 ] Penrose generation functions

[ 5.0 ] Convert Penrose tilings to

  		Tiling objects.

SubstitutionAPI

[0] Substitution API

tile ids are arrays of strings, where:

  • the first string is the tile type,
  • the second is a unique string in the base tiling,
  • each subsequent string identifies the child of a parent tile (uses push method) THESE IDENTIFIERS MUST BE UNIQUE

How to use this API? see [1] to [7]

"side effect" = a function modifies directly the objects it receives as argument

[0.1] toolbox: convert an id array to a key (used in maps)

[0.2] toolbox: test if two id Arrays are equal

[1] user creates base Tile objects (id, bounds, lim)

remark: each one must have a unique id identifying the type e.g. ['kite'] or ['dart']

remark: it may be useful for the substitution to have some typeX2typeY method, converting (by side effect) some tile of typeX to typeY at the "same position" with the "same orientation". e.g. Tile.prototype.kite2dart = function(){ update id[0] and move bounds } geometric point transformations provided by Utils/Geometry.js may be useful

remark: neighbors may be left empty [] or set all neighbors as undefined [undefined,undefined,...,undefined] (remember this when creating you base tiling at step [7])

[2] user creates a substitution function 'mysubstitution'

input:

  • Tile output:
  • (Array of) Tile

useful methods:

  • Tile.myclone()
  • Tile.typeX2typeY()
  • Tile.scale(...)
  • Tile.rotate(...)
  • Tile.shift(...) depending on how you code neighbors computation:
  • Tile.resetNeighbors()

remark: newtiles are supposed to be scaled down by 1/ratio, with ratio the value passed to substitute at step [7]

remark: should may use "switch(tile.id[0]){...}" for the different tile types

remark: the substitution may create duplicated tiles

[3] user provides informations on duplicated tiles as

'mydupinfos' an Array of DupInfo, and 'mydupinfosoriented' an Array of DupInfoOriented

indeed, it often happens that the subsitution "déborde" and as a consequence, neighboring parent tiles may create twice a same newtile. If your substitution is very nice and does not have this issue, then simply set 'mydupinfo=[];'. Otherwise init to [] and then 'mydupinfo.push(new Dupinfo(...));' for each potential duplicate case.

[3.1]

data structure storing informations about the potential duplicated children of a parent tile

meaning: if parent is 'ptype' and parent.neighbors['index'] is 'potype', then "'id' child of parent" is a duplicate of "'oid' child of parent.neighbors['index']" (both are 'type')

[3.2]

data structure storing informations about the potential duplicated children of a parent tile, when this also depends on the matching side of neighbor tile (thus on the orientation of the neighboring tile)

meaning: if parent is 'ptype' and parent.neighbors['index'] is 'potype', and if furthermore the former is neighbor 'oindex' of the latter, then "'id' child of parent" is a duplicate of "'oid' child of parent.neighbors['index']" (both are 'type')

[3.3]

construct a map of duplicated tiles:

  • idkey of duplicated -> id of original from:
  • an Array of DupInfo
  • an Array of Tile

[3.4]

check if child id of pid is a duplicated tile, with

  • newdup the map of duplicated tiles
  • pid the parend of id (Array)
  • id the child id (last part)
  • type the child type

[4] user creates a function 'myneighbors' to fill (by side effect)

neighbors of the new tiles input:

  • Array of tiles
  • Map of tiles (idkey -> tile)
  • Array of newtiles (obtained from 'mysubstitution')
  • Map of newtiles (newidkey -> newtile)
  • Map of duplicated newtiles (newidkey -> id of original) no output, just return;

remark: newtiles' neighbors are computed based on the parent's neighbors, therefore it may be natural to iterate over parent tiles.

remark: you may have used Tile.resetNeighbors() at step [2]

remark: no need to fill the neighbors of duplicated tiles (see isDup at [3.3])

remark: the cleaning of duplicated tiles at step [5] will update the neighbors which are duplicated tiles. It means that you may set as neighbors some tiles which turn out to be duplicated, the replacement for the original tile will be handled automatically from your 'mydupinfos'

remark: maps (aka dictionaries) may be useful to get the neighbor of a neighbor, do not forget to use id2key(id) (see [0.1]) when calling .has and .get methods.

see useful methods [4.1] to [4.3]

[4.1] set some neighbor of a newtile

modifies

  • tilesdict (map of tiles with id2key) by adding child nid (of type ntype) of pnid as neighbor number i of child id (of type type) of pid, with:
  • pid the parent id (Array)
  • id the child id (last part)
  • type the child type
  • i the neighbors index (integer)
  • pnid the neighbors parent id (Array)
  • nid the neighbors id (last part)
  • ntype the neighbors type

[4.2] set some neighbor of a newtile as undefined

similar to setNeighbor

[4.3] set some neighbor of a newtile and check if this neighbor is duplicated

(if it is then set the original as neighbor) similar to setNeighbor CAUTION: not useful because clean updates duplicated tiles in neighbors

[5] clean duplicates: remove duplicated tiles and update neighbors

[6] (optional)

 findNeighbors checks if non-neighboring tiles have neighborhing children,
 in time O(n log n) with n the number of undefined neighbors
 (hoping that javascript Array.sort() implements quicksort)

remark: the default correspondence is that tile.neighbors[i] corresponds to segment (tile.bounds[2i],tile.bounds[2i+1]) -- (tile.bounds[2i+2 %_],tile.bounds[2i+3 %_]). If this is not the case in user's implementation, then user will provide a correspondance method (see [6.2] and [7])

remark: it is expected that tile.bounds.length = 2*tile.neighbors.length

remark: this takes into account rounding error in coordinates computation, up to a distance between two points (expected to be identical) less than:

[6.1] toolbox

[6.2] neighbors' index to bounds' indices correspondence, for each tile type,

   in order to fill the second par of the Map:
   'type' -> Array of neighbors.length Arrays of four indices
   (these latter corresponding to bounds)

default one: tile.neighbors[i] corresponds to segment (tile.bounds[2i],tile.bounds[2i+1]) -- (tile.bounds[2i+2 %_],tile.bounds[2i+3 %_]) may be constructed via the method below, as it depends on input:

  • number of neighbors

[6.3] findneighbors

input:

  • Array of tiles
  • Map of tiles (idkey -> tile)
  • neighbors2bounds (n2b) is a Map tile 'type' -> Array of neighbors.length Arrays of four indices output:
  • number of matching segments founds

[6.4] set undefined neighbors for lazy user, by side effet

[7] (eventually) the substitution method to call

at this point the user writes its Tiling.mytiling function:

  1. define a base tiling
  2. call substitute
  3. return a Tiling

Tiling.mytiling = function({iterations}={}){

var tiles = []; etc tiles.push(mytile1); etc

remark: use the base tiles from step [1] and myclone() method, do not forget to fill neighbors for tiles of the base tiling and leave the boundary as 'undefined'

  1. tiles = substitute(...);

input:

  • number of iterations
  • Array of tiles (aka base tiling)
  • scaling ratio of the substitution
  • mysubstitution (see [2])
  • mydupinfos (see [3])
  • myneighbors (see [4])
  • (optional) whether to call findNeighbors (see [6]), one of:
    • false
    • neighbors2bounds how it work? see the code below
  • (optional) a tile type to initial sand content for decoration purpose, one of:
    • false
    • a Map tile type (tile.id[0]) -> number
  1. return new Tiling(tiles);

}

Geometry

[1.0] geometric transformations of points

[1.1] scale point A towards point B by factor f (homothecy)

   return the new coordinates for point A

[1.2] shift point A by vector B

   return the new coordinates for point A

[1.3] rotate point A around point B by angle a (in radian)

   return the new coordinates for point A
   caution: a positive = counterclockwise
            a negative = clockwise

Clone this wiki locally