plotboilerplate 1.12.8 → 1.14.0

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.
Files changed (98) hide show
  1. package/README.md +4 -1
  2. package/changelog.md +26 -0
  3. package/dist/index.esm.js +292 -51
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.esm.min.js +1 -1
  6. package/dist/index.esm.min.js.map +1 -1
  7. package/dist/plotboilerplate.browser.min.js +1 -1
  8. package/dist/plotboilerplate.browser.min.js.map +1 -1
  9. package/dist/plotboilerplate.js +306 -50
  10. package/dist/plotboilerplate.min.js +1 -1
  11. package/package.json +1 -1
  12. package/src/cjs/BezierPath.d.ts +12 -1
  13. package/src/cjs/BezierPath.js +34 -5
  14. package/src/cjs/BezierPath.js.map +1 -1
  15. package/src/cjs/PBText.d.ts +116 -0
  16. package/src/cjs/PBText.js +66 -0
  17. package/src/cjs/PBText.js.map +1 -0
  18. package/src/cjs/PlotBoilerplate.d.ts +2 -1
  19. package/src/cjs/PlotBoilerplate.js +41 -14
  20. package/src/cjs/PlotBoilerplate.js.map +1 -1
  21. package/src/cjs/Vertex.d.ts +18 -4
  22. package/src/cjs/Vertex.js +24 -7
  23. package/src/cjs/Vertex.js.map +1 -1
  24. package/src/cjs/draw.d.ts +30 -2
  25. package/src/cjs/draw.js +51 -6
  26. package/src/cjs/draw.js.map +1 -1
  27. package/src/cjs/drawgl.d.ts +29 -2
  28. package/src/cjs/drawgl.js +21 -4
  29. package/src/cjs/drawgl.js.map +1 -1
  30. package/src/cjs/drawutilssvg.d.ts +25 -7
  31. package/src/cjs/drawutilssvg.js +62 -14
  32. package/src/cjs/drawutilssvg.js.map +1 -1
  33. package/src/cjs/entry.js +1 -0
  34. package/src/cjs/index.d.ts +1 -0
  35. package/src/cjs/index.js +1 -0
  36. package/src/cjs/index.js.map +1 -1
  37. package/src/cjs/interfaces/DrawLib.d.ts +27 -6
  38. package/src/cjs/interfaces/DrawLib.js +3 -0
  39. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  40. package/src/cjs/interfaces/core.d.ts +9 -1
  41. package/src/cjs/interfaces/core.js +1 -0
  42. package/src/cjs/interfaces/core.js.map +1 -1
  43. package/src/cjs/utils/datastructures/Color.d.ts +28 -15
  44. package/src/cjs/utils/datastructures/Color.js +276 -88
  45. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  46. package/src/esm/BezierPath.d.ts +12 -1
  47. package/src/esm/BezierPath.js +34 -5
  48. package/src/esm/BezierPath.js.map +1 -1
  49. package/src/esm/PBText.d.ts +116 -0
  50. package/src/esm/PBText.js +61 -0
  51. package/src/esm/PBText.js.map +1 -0
  52. package/src/esm/PlotBoilerplate.d.ts +2 -1
  53. package/src/esm/PlotBoilerplate.js +41 -14
  54. package/src/esm/PlotBoilerplate.js.map +1 -1
  55. package/src/esm/Vertex.d.ts +18 -4
  56. package/src/esm/Vertex.js +24 -7
  57. package/src/esm/Vertex.js.map +1 -1
  58. package/src/esm/draw.d.ts +30 -2
  59. package/src/esm/draw.js +51 -6
  60. package/src/esm/draw.js.map +1 -1
  61. package/src/esm/drawgl.d.ts +29 -2
  62. package/src/esm/drawgl.js +21 -4
  63. package/src/esm/drawgl.js.map +1 -1
  64. package/src/esm/drawutilssvg.d.ts +25 -7
  65. package/src/esm/drawutilssvg.js +62 -14
  66. package/src/esm/drawutilssvg.js.map +1 -1
  67. package/src/esm/entry.js +1 -0
  68. package/src/esm/index.d.ts +1 -0
  69. package/src/esm/index.js +1 -0
  70. package/src/esm/index.js.map +1 -1
  71. package/src/esm/interfaces/DrawLib.d.ts +27 -6
  72. package/src/esm/interfaces/DrawLib.js +3 -0
  73. package/src/esm/interfaces/DrawLib.js.map +1 -1
  74. package/src/esm/interfaces/core.d.ts +9 -1
  75. package/src/esm/interfaces/core.js +1 -0
  76. package/src/esm/interfaces/core.js.map +1 -1
  77. package/src/esm/utils/datastructures/Color.d.ts +28 -15
  78. package/src/esm/utils/datastructures/Color.js +277 -89
  79. package/src/esm/utils/datastructures/Color.js.map +1 -1
  80. package/src/ts/BezierPath.ts +37 -5
  81. package/src/ts/PBText.ts +147 -0
  82. package/src/ts/PlotBoilerplate.ts +44 -18
  83. package/src/ts/Vertex.ts +26 -7
  84. package/src/ts/draw.ts +71 -8
  85. package/src/ts/drawgl.ts +48 -8
  86. package/src/ts/drawutilssvg.ts +94 -17
  87. package/src/ts/index.ts +1 -0
  88. package/src/ts/interfaces/DrawLib.ts +30 -4
  89. package/src/ts/interfaces/core.ts +9 -0
  90. package/src/ts/utils/datastructures/Color.ts +695 -508
  91. package/dist/plotboilerplate.browser.min.js.LICENSE.txt +0 -8
  92. package/src/ts/utils/algorithms/clearPolygonDuplicateVertices.ts~ +0 -5
  93. package/src/ts/utils/algorithms/findPolygonSelfIntersections.ts~ +0 -45
  94. package/src/ts/utils/algorithms/splitPolygonToNonIntersecting.ts~ +0 -113
  95. package/src/ts/utils/algorithms/sutherlandHodgman.ts~ +0 -88
  96. package/src/ts/utils/datastructures/Color.ts~ +0 -331
  97. package/src/ts/utils/datastructures/Girih.ts~ +0 -151
  98. package/src/ts/utils/datastructures/GirihTile.ts~ +0 -419
@@ -1,151 +0,0 @@
1
- /**
2
- * The Girih datastructure for generating patterns.
3
- *
4
- * @requires PlotBoilerplate
5
- * @requires MouseHandler
6
- * @requires gup
7
- * @requires dat.gui
8
- *
9
- * @author Ikaros Kappler
10
- * @date 2020-11-24
11
- * @modified 2020-11-25 Ported to TypeScript from vanilla JS.
12
- * @version 1.0.1
13
- **/
14
-
15
-
16
- (function(_context) {
17
- "use strict";
18
-
19
-
20
- var Girih = function( edgeLength ) {
21
-
22
- this.edgeLength = edgeLength;
23
-
24
- // Initialize templates, one for each Girih tile type.
25
- // The template array will be filled on initialization (see below).
26
- this.TILE_TEMPLATES = [];
27
-
28
- // The set of all Girih tiles in scene
29
- this.tiles = [];
30
-
31
- this.initTemplates( edgeLength );
32
- };
33
-
34
- // @private
35
- Girih.prototype.initTemplates = function( edgeLength ) {
36
- var decagon = new GirihDecagon( new Vertex(-200,-100), edgeLength, 0.0 ); // Positions don't matter here
37
- var pentagon = new GirihPentagon( new Vertex(-77,-60), edgeLength, 0.0 );
38
- var hexagon = new GirihHexagon( new Vertex(25,-0.5), edgeLength, 0.0 );
39
- var bowtie = new GirihBowtie( new Vertex(-232,0), edgeLength, 0.0 );
40
- var rhombus = new GirihRhombus( new Vertex(-68,-127.5), edgeLength, 0.0 );
41
- var penrose = new GirihPenroseRhombus( new Vertex(-24,-28), edgeLength, 0.0, true );
42
-
43
- // Add tiles to array and put them in the correct adjacency position.
44
- this.TILE_TEMPLATES.push( decagon );
45
- this.TILE_TEMPLATES.push( decagon.transformTilePositionToAdjacency( 2, pentagon ) );
46
- this.TILE_TEMPLATES.push( pentagon.transformTilePositionToAdjacency( 1, penrose ) );
47
- this.TILE_TEMPLATES.push( penrose.transformTilePositionToAdjacency( 3, hexagon ) );
48
- this.TILE_TEMPLATES.push( decagon.transformTilePositionToAdjacency( 5, bowtie ) );
49
- this.TILE_TEMPLATES.push( pentagon.transformTilePositionToAdjacency( 4, rhombus ) );
50
-
51
- /*
52
- for( var i in this.TILE_TEMPLATES ) {
53
- var tile = this.TILE_TEMPLATES[i].clone();
54
- // TODO: move click listener somewhere else
55
- tile.position.listeners.addClickListener( (function(vertex) {
56
- return function(clickEvent) {
57
- console.log('clicked', clickEvent );
58
- vertex.attr.isSelected = !vertex.attr.isSelected;
59
- pb.redraw();
60
- } })(tile.position)
61
- );
62
- tile.position.attr.draggable = false;
63
- pb.add( tile.position );
64
-
65
- this.tiles.push( tile );
66
- }
67
-
68
- console.log( 'tiles', this.tiles );
69
- */
70
- };
71
-
72
- Girih.prototype.addTile = function( tile ) {
73
- this.tiles.push( tile );
74
- };
75
-
76
- Girih.prototype.removeTileAt = function( index ) {
77
- this.tiles.splice( index, 1 );
78
- };
79
-
80
- /**
81
- * Find that tile (index) which contains the given position. First match will be returned.
82
- *
83
- * @name locateContainingTile
84
- * @param {Vertex} position
85
- * @return {number} The index of the containing tile or -1 if none was found.
86
- **/
87
- Girih.prototype.locateConatiningTile = function( position ) {
88
- for( var i in this.tiles ) {
89
- if( this.tiles[i].containsVert( position ) )
90
- return i;
91
- }
92
- return -1;
93
- };
94
-
95
-
96
- // +---------------------------------------------------------------------------------
97
- // | Turn the tile the mouse is hovering over.
98
- // | The turnCount is ab abstract number: -1 for one turn left, +1 for one turn right.
99
- // +-------------------------------
100
- Girih.prototype.turnTile = function( tileIndex, turnCount ) {
101
- if( tileIndex == -1 ) // TODO: still required?
102
- return;
103
- var tile = this.tiles[tileIndex];
104
- tile.rotate( turnCount * Math.PI*2/tile.symmetry );
105
- // pb.redraw();
106
- };
107
-
108
-
109
- // +---------------------------------------------------------------------------------
110
- // | Move that tile the mouse is hovering over.
111
- // | The move amounts are abstract numbers, 1 indicating one unit along each axis.
112
- // +-------------------------------
113
- GirihTile.prototype.handleMoveTile = function( tileIndex, moveXAmount, moveYAmount ) {
114
- if( tileIndex == -1 ) // TODO: still required?
115
- return;
116
- var tile = tiles[tileIndex];
117
- tile.move( { x: moveXAmount*10, y : moveYAmount*10 } );
118
- // pb.redraw();
119
- };
120
-
121
-
122
- // +---------------------------------------------------------------------------------
123
- // | Find all possible adjadent tiles and their locations (type, rotation and offset).
124
- // +-------------------------------
125
- Girih.prototype.findAdjacentTiles = function( tileIndex, edgeIndex ) {
126
- var adjTiles = [];
127
- if( tileIndex == -1 || edgeIndex == -1 ) // TODO: still required
128
- return [];
129
-
130
- var template = null;
131
- for( var i in this.TILE_TEMPLATES ) {
132
- template = this.TILE_TEMPLATES[ i ].clone();
133
- // Find all rotations and positions for that tile to match
134
- var foundTiles = this.tiles[tileIndex].transformTileToAdjacencies(
135
- edgeIndex,
136
- template
137
- );
138
- if( foundTiles.length != 0 ) {
139
- adjTiles = adjTiles.concat( foundTiles );
140
- }
141
- }
142
- // Set pointer to save range.
143
- // previewTilePointer = Math.min( adjTiles.length-1, previewTiilePointer );
144
- return adjTiles;
145
- };
146
-
147
- _context.Girih = Girih;
148
-
149
- })(window);
150
-
151
-
@@ -1,419 +0,0 @@
1
- /**
2
- * @class
3
- * @classdesc This is a general tile superclass. All other tile classes extends this one.
4
- *
5
- * Rule:
6
- * * the outer and the inner sub polygons must be inside the main polygon's bounds.
7
- *
8
- * @requires Bounds
9
- * @requires Polyon
10
- * @requires Vertex
11
- *
12
- * @author Ikaros Kappler
13
- * @date 2013-11-27
14
- * @modified 2014-04-05 Ikaros Kappler (member array outerTilePolygons added).
15
- * @modified 2015-03-19 Ikaros Kappler (added toSVG()).
16
- * @modified 2020-10-30 Refactored the this super class to work with PlotBoilerplate.
17
- * @version 2.0.0-alpha
18
- * @name GirihTile
19
- **/
20
-
21
- import { Polygon } from "../Polygon";
22
-
23
-
24
- /**
25
- * @constructor
26
- * @abstract class
27
- * @param {Vertex} position - The position of the tile.
28
- * @param {number} size - The edge size (usually IKRS.Girih.DEFAULT_EDGE_LENGTH).
29
- * @param {string} tileType - One of GirihTile.TILE_TYPE_*.
30
- **/
31
- var GirihTile = function( position,
32
- size,
33
- tileType
34
- ) {
35
-
36
- Polygon.call( this, [], false ); // ..., vertices, isOpen
37
-
38
- // if( typeof angle == "undefined" )
39
- //angle = 0.0;
40
- if( typeof tileType == "unknown" )
41
- tileType = GirihTile.TYPE_UNKNOWN;
42
-
43
- this.size = size;
44
- this.position = position;
45
- this.rotation = 0.0; // angle;
46
- this.symmetry = 10;
47
- this.uniqueSymmetries = 10;
48
-
49
- // An array of polygons.
50
- // The inner tile polygons are those that do not share edges with the outer
51
- // tile bounds (vertices are OK).
52
- this.innerTilePolygons = [];
53
-
54
- // A second array of polygons.
55
- // The outer tile polygons are those that make up the whole tile area
56
- // _together with the inner tile polygons (!)_; the union of the
57
- // inner tile polygons and the outer tile polygons covers exactly
58
- // the whole tile polygon.
59
- // The intersection of both sets is empty.
60
- // Outer tile polygon share at least one (partial) edge with the complete
61
- // tile polygon (length > 0).
62
- this.outerTilePolygons = [];
63
- this.imageProperties = null;
64
-
65
- this.tileType = tileType;
66
- this.epsilon = 0.001;
67
-
68
- };
69
-
70
- GirihTile.TYPE_UNKNOWN = "UNKNOWN";
71
- GirihTile.TYPE_DECAGON = "DECAGON";
72
- GirihTile.TYPE_PENTAGON = "PENTAGON";
73
- GirihTile.TYPE_IRREGULAR_HEXAGON = "IRREGULAR_HEXAGON";
74
- GirihTile.TYPE_RHOMBUS = "RHOMBUS";
75
- GirihTile.TYPE_BOW_TIE = "BOW_TIE";
76
- // This is not part of the actual girih tile set!
77
- GirihTile.TYPE_PENROSE_RHOMBUS = "PENROSE_RHOMBUS";
78
-
79
-
80
- // Prepare the tile alignment matrix:
81
- // [ actual_tile ] x [ edge_index ] x [ successor_index ] = tile_align
82
- // GirihTile.TILE_ALIGN = Array();
83
- GirihTile.DEFAULT_EDGE_LENGTH = 58;
84
-
85
-
86
- /**
87
- * @abstract Subclasses must override this.
88
- */
89
- GirihTile.prototype.clone = function() {
90
- throw "Subclasses must override the clone() function.";
91
- };
92
-
93
- /**
94
- * @param {XYCoords} amount
95
- */
96
- GirihTile.prototype.move = function( amount ) {
97
- Polygon.prototype.move.call( this, amount );
98
- for( var i in this.innerTilePolygons )
99
- this.innerTilePolygons[i].move( amount );
100
- for( var i in this.outerTilePolygons )
101
- this.outerTilePolygons[i].move( amount );
102
- this.position.add( amount );
103
- };
104
-
105
- // Find the adjacent tile (given by the template tile)
106
- // Note that the tile itself will be modified (rotated and moved to the correct position).
107
- GirihTile.prototype.findAdjacentTilePosition = function( edgeIndex, tile ) {
108
- var edgeA = new Line( this.vertices[ edgeIndex % this.vertices.length ],
109
- this.vertices[ (edgeIndex+1) % this.vertices.length ] );
110
- // Find adjacent edge
111
- for( var i = 0; i < tile.vertices.length; i++ ) {
112
- var edgeB = new Line( tile.vertices[ i % tile.vertices.length ].clone(),
113
- tile.vertices[ (i+1) % tile.vertices.length ].clone() );
114
- // Goal: edgeA.a==edgeB.b && edgeA.b==edgeB.a
115
- // So move edgeB
116
- var offset = edgeB.b.difference(edgeA.a);
117
- edgeB.add( offset );
118
- if( edgeB.a.distance(edgeA.b) < this.epsilon ) {
119
- return { edgeIndex : i, offset : offset };
120
- }
121
- }
122
- return null;
123
- };
124
-
125
-
126
- // +---------------------------------------------------------------------------------
127
- // | Apply adjacent tile position to `neighbourTile`.
128
- // +-------------------------------
129
- GirihTile.prototype.transformTileToAdjacencies = function( // baseTile,
130
- baseEdgeIndex,
131
- neighbourTile ) {
132
- // Find a rotation for that tile to match
133
- var i = 0;
134
- var foundAlignments = [];
135
- var positionedTile = null;
136
- while( i < neighbourTile.uniqueSymmetries ) {
137
- positionedTile = this.transformTilePositionToAdjacency( /* baseTile,*/ baseEdgeIndex, neighbourTile );
138
- if( positionedTile != null ) {
139
- // console.log('Found?', adjacency );
140
- positionedTile = positionedTile.clone();
141
- // positionedTile.rotate( (Math.PI*2)/positionedTile.symmetry );
142
- foundAlignments.push( positionedTile );
143
- } // else {
144
- neighbourTile.rotate( (Math.PI*2)/neighbourTile.symmetry );
145
- // }
146
- i++
147
- }
148
- return foundAlignments;
149
- };
150
-
151
-
152
- // +---------------------------------------------------------------------------------
153
- // | Apply adjacent tile position to `neighbourTile`.
154
- // +-------------------------------
155
- GirihTile.prototype.transformTilePositionToAdjacency = function( // baseTile,
156
- baseEdgeIndex,
157
- neighbourTile ) {
158
- // Find the position for that tile to match (might not exist)
159
- // { edgeIndex:number, offset:XYCoords }
160
- var adjacency = this.findAdjacentTilePosition( baseEdgeIndex, neighbourTile );
161
- if( adjacency != null ) {
162
- neighbourTile.move( adjacency.offset );
163
- return neighbourTile;
164
- }
165
- return null;
166
- };
167
-
168
-
169
- /**
170
- * This function applies MOD to the index.
171
- **/
172
- GirihTile.prototype.getInnerTilePolygonAt = function( index ) {
173
- if( index < 0 )
174
- return this.innerTilePolygons[ this.innerTilePolygons.length - (Math.abs(index)%this.innerTilePolygons.length) ];
175
- else
176
- return this.innerTilePolygons[ index % this.innerTilePolygons.length ];
177
- };
178
-
179
- /**
180
- * This function applies MOD to the index.
181
- **/
182
- GirihTile.prototype.getOuterTilePolygonAt = function( index ) {
183
- if( index < 0 )
184
- return this.outerTilePolygons[ this.outerTilePolygons.length - (Math.abs(index)%this.outerTilePolygons.length) ];
185
- else
186
- return this.outerTilePolygons[ index % this.outerTilePolygons.length ];
187
- };
188
-
189
-
190
- GirihTile.prototype.getTranslatedVertex = function( index ) {
191
- // Rotate around the absolut center!
192
- // (the position is applied later)
193
- return this.translateVertex( this.vertices[index % this.vertices.length ] );
194
- };
195
-
196
- // Note: this function behaves a bitdifferent than the genuine Polygon.rotate function!
197
- // Polygon has the default center of rotation at (0,0).
198
- // The GirihTile rotates around its center (position) by default.
199
- GirihTile.prototype.rotate = function( angle, center ) {
200
- if( typeof center === "undefined" )
201
- center = this.position;
202
- Polygon.prototype.rotate.call( this, angle, center );
203
- for( var i in this.innerTilePolygons ) {
204
- this.innerTilePolygons[i].rotate( angle, center );
205
- }
206
- for( var i in this.outerTilePolygons ) {
207
- this.outerTilePolygons[i].rotate( angle, center );
208
- }
209
- this.rotation += angle;
210
- return this;
211
- };
212
-
213
-
214
- /**
215
- * This is a special get* function that modulates the index and also
216
- * allows negative values.
217
- *
218
- * For k >= 0:
219
- * - getVertexAt( vertices.length ) == getVertexAt( 0 )
220
- * - getVertexAt( vertices.length + k ) == getVertexAt( k )
221
- * - getVertexAt( -k ) == getVertexAt( vertices.length -k )
222
- *
223
- * So this function always returns a point for any index.
224
- **/
225
- // THIS IS NOW PART OF THE POLYGON CLASS
226
- /* GirihTile.prototype.getVertexAt = function( index ) {
227
- return this.vertices[ index % this.vertices.length ];
228
- } */
229
-
230
- /**
231
- * This function checks if the passed point is within this tile's polygon.
232
- *
233
- * @param point The point to be checked.
234
- * @retrn true|false
235
- **/
236
- // THIS IS NOW PART OF THE POLYGON CLASS
237
- /*
238
- GirihTile.prototype.containsPoint = function( point ) {
239
- // Thanks to
240
- // http://stackoverflow.com/questions/2212604/javascript-check-mouse-clicked-inside-the-circle-or-polygon/2212851#2212851
241
- var i, j = 0;
242
- var c = false;
243
- for (i = 0, j = this.polygon.vertices.length-1; i < this.polygon.vertices.length; j = i++) {
244
- vertI = this.getTranslatedVertex( i );
245
- vertJ = this.getTranslatedVertex( j );
246
- if ( ((vertI.y>point.y) != (vertJ.y>point.y)) &&
247
- (point.x < (vertJ.x-vertI.x) * (point.y-vertI.y) / (vertJ.y-vertI.y) + vertI.x) )
248
- c = !c;
249
- }
250
- return c;
251
-
252
- } */
253
-
254
- /**
255
- * This function locates the closest tile edge (polygon edge)
256
- * to the passed point.
257
- *
258
- * Currently the edge distance to a point is measured by the
259
- * euclidian distance from the edge's middle point.
260
- *
261
- * @param point The point to detect the closest edge for.
262
- * @param tolerance The tolerance (=max distance) the detected edge
263
- * must be inside.
264
- * @return the edge index (index of the start vertice) or -1 if not
265
- * found.
266
- **/
267
- GirihTile.prototype.locateEdgeAtPoint = function( point,
268
- tolerance
269
- ) {
270
- if( this.vertices.length == 0 )
271
- return -1;
272
-
273
- var middle = new Vertex( 0, 0 );
274
- var tmpDistance = 0;
275
- var resultDistance = tolerance*2; // definitely outside the tolerance :)
276
- var resultIndex = -1;
277
- for( var i = 0; i < this.vertices.length; i++ ) {
278
-
279
- // var vertI = this.getTranslatedVertex( i );
280
- // var vertJ = this.getTranslatedVertex( i+1 );
281
-
282
- var vertI = this.getVertexAt( i );
283
- var vertJ = this.getVertexAt( i+1 );
284
-
285
- // Create a point in the middle of the edge
286
- middle.x = vertI.x + (vertJ.x - vertI.x)/2.0;
287
- middle.y = vertI.y + (vertJ.y - vertI.y)/2.0;
288
- tmpDistance = middle.distance(point);
289
- if( tmpDistance <= tolerance && (resultIndex == -1 || tmpDistance < resultDistance) ) {
290
- resultDistance = tmpDistance;
291
- resultIndex = i;
292
- }
293
-
294
- }
295
-
296
- return resultIndex;
297
-
298
- }
299
-
300
- /**
301
- * Find the adjacent edge from this tile's polygon.
302
- *
303
- * This function will check all egdges and return the one with
304
- * the minimal distance (its index).
305
- *
306
- * Only forward edges (i -> i+1) are detected. If you wish backward
307
- * edges to be detected too, swap the point parameters pointA and
308
- * pointB.
309
- *
310
- * @param pointA The first point of the desired edge.
311
- * @param pointB The second point the desired edge.
312
- * @param tolerance The tolerance of the detection (radius).
313
- * @return The index of the edge's first vertex (if detected) or
314
- * -1 if not edge inside the tolerance was found.
315
- *
316
- * @pre tolerance >= 0
317
- **/
318
- GirihTile.prototype.locateAdjacentEdge = function( pointA,
319
- pointB,
320
- tolerance
321
- ) {
322
-
323
- if( this.polygon.vertices.length == 0 )
324
- return -1;
325
-
326
- var result = -1;
327
- var resultDistance = 2*tolerance+1; // Definitely larger than the tolerance :)
328
- //var tmpDistance;
329
- for( var i = 0; i <= this.polygon.vertices.length; i++ ) {
330
-
331
- var vertCur = this.getTranslatedVertex( i ); // this.getVertexAt( i );
332
- var vertSuc = this.getTranslatedVertex( i+1 ); // this.getVertexAt( i+1 );
333
-
334
- // Current edge matches?
335
- var avgDistanceFwd = (vertCur.distanceTo(pointA) + vertSuc.distanceTo(pointB))/2.0;
336
- //var avgDistanceBwd = (vertSuc.distanceTo(pointA) + vertCur.distanceTo(pointB))/2.0;
337
-
338
- // Measure only in one direction. Otherwise the return value would be ambigous.
339
- if( avgDistanceFwd < tolerance &&
340
- (result == -1 || (result != -1 && avgDistanceFwd < resultDistance))
341
- ) {
342
- // Check ALL edges to find the minimum
343
- result = i;
344
- resultDistance = avgDistanceFwd;
345
- }
346
- }
347
-
348
-
349
- return result;
350
-
351
- };
352
-
353
- GirihTile.prototype.toSVG = function( options,
354
- polygonStyle,
355
- buffer
356
- ) {
357
-
358
- var returnBuffer = false;
359
- if( typeof buffer == "undefined" || !buffer ) {
360
- buffer = [];
361
- returnBuffer = true;
362
- }
363
-
364
- // Export outer shape?
365
- for( var i = 0; i < this.innerTilePolygons.length; i++ ) {
366
- this._polygonToSVG( this.innerTilePolygons[i],
367
- options,
368
- polygonStyle,
369
- buffer );
370
- }
371
- if( returnBuffer )
372
- return buffer;
373
- else
374
- return buffer.join( "" );
375
- };
376
-
377
- GirihTile.prototype._polygonToSVG = function( polygon,
378
- options,
379
- polygonStyle,
380
- buffer
381
- ) {
382
- if( typeof options != "undefined" && typeof options.indent != "undefined" )
383
- buffer.push( options.indent );
384
-
385
- buffer.push( "<polygon points=\"" );
386
- var vert;
387
- for( var i = 0; i < polygon.vertices.length; i++ ) {
388
- vert = this._translateVertex( polygon.getVertexAt(i) ); // getTranslatedVertex(i);
389
- if( i > 0 )
390
- buffer.push( " " );
391
- buffer.push( vert.x );
392
- buffer.push( "," );
393
- buffer.push( vert.y );
394
- }
395
- buffer.push( "\"" );
396
-
397
- if( typeof polygonStyle != "undefined" ) {
398
- buffer.push( " style=\"" );
399
- buffer.push( polygonStyle );
400
- buffer.push( "\"" );
401
- }
402
-
403
- buffer.push( " />\n" );
404
- };
405
-
406
- // TODO: Move this to Polygon?
407
- /* GirihTile.prototype.computeBounds = function() {
408
- return Bounds.computeFromVertices( this.vertices );
409
- }; */
410
-
411
- /* GirihTile.prototype.translateVertex = function( vertex ) {
412
- return vertex.clone().rotate( this.angle, new Vertex(0,0) ).add( this.position );
413
- }; */
414
-
415
- GirihTile.prototype.addVertex = function( vertex ) {
416
- this.vertices.push( vertex );
417
- };
418
-
419
- GirihTile.prototype.constructor = GirihTile;