1313//
1414// Regenerate: deno task gen-shape. Verify: deno task gen-shape:check.
1515
16- const CIRCLE_R = 0.34 ;
16+ let CIRCLE_R = 0.34 ;
1717// two staggered columns: left lowered, right raised (§9.3.2)
18- const INTERNAL : Array < [ number , number ] > = [
18+ let INTERNAL : Array < [ number , number ] > = [
1919 [ 0.3 , 0.24 ] ,
2020 [ 0.7 , 0.12 ] , // top pair
2121 [ 0.3 , 0.56 ] ,
@@ -25,21 +25,21 @@ const INTERNAL: Array<[number, number]> = [
2525] ;
2626
2727// point-supersampling density per circle's bounding square
28- const SAMPLES = 32 ;
28+ let SAMPLES = 32 ;
2929
30- const FONT_PATH = "vendor/font8x8_basic.h" ;
31- const OUT_PATH = "src/shape_vectors.h" ;
30+ let FONT_PATH = "vendor/font8x8_basic.h" ;
31+ let OUT_PATH = "src/shape_vectors.h" ;
3232
3333function loadFont ( ) : Uint8Array [ ] {
34- const text = new TextDecoder ( ) . decode ( Deno . readFileSync ( FONT_PATH ) ) ;
35- const glyphs : Uint8Array [ ] = [ ] ;
36- const glyph = / \{ ( [ ^ } ] * ) \} \s * , ? \s * \/ \/ \s * U \+ ( [ 0 - 9 A - F a - f ] + ) / g;
37- const rows = / 0 x ( [ 0 - 9 A - F a - f ] { 2 } ) / g;
38- for ( const match of text . matchAll ( glyph ) ) {
39- const cp = parseInt ( match [ 2 ] , 16 ) ;
40- const bytes = new Uint8Array ( 8 ) ;
34+ let text = new TextDecoder ( ) . decode ( Deno . readFileSync ( FONT_PATH ) ) ;
35+ let glyphs : Uint8Array [ ] = [ ] ;
36+ let glyph = / \{ ( [ ^ } ] * ) \} \s * , ? \s * \/ \/ \s * U \+ ( [ 0 - 9 A - F a - f ] + ) / g;
37+ let rows = / 0 x ( [ 0 - 9 A - F a - f ] { 2 } ) / g;
38+ for ( let match of text . matchAll ( glyph ) ) {
39+ let cp = parseInt ( match [ 2 ] , 16 ) ;
40+ let bytes = new Uint8Array ( 8 ) ;
4141 let i = 0 ;
42- for ( const b of match [ 1 ] . matchAll ( rows ) ) {
42+ for ( let b of match [ 1 ] . matchAll ( rows ) ) {
4343 if ( i < 8 ) {
4444 bytes [ i ++ ] = parseInt ( b [ 1 ] , 16 ) ;
4545 }
@@ -53,26 +53,26 @@ function loadFont(): Uint8Array[] {
5353}
5454
5555function ink ( font : Uint8Array , u : number , v : number ) : boolean {
56- const col = Math . floor ( u * 8 ) ;
57- const row = Math . floor ( v * 8 ) ;
56+ let col = Math . floor ( u * 8 ) ;
57+ let row = Math . floor ( v * 8 ) ;
5858 if ( col < 0 || col > 7 || row < 0 || row > 7 ) {
5959 return false ;
6060 }
6161 return ( font [ row ] & ( 1 << col ) ) !== 0 ;
6262}
6363
6464function shapeVector ( font : Uint8Array ) : number [ ] {
65- const vector : number [ ] = [ ] ;
66- for ( const [ cu , cv ] of INTERNAL ) {
65+ let vector : number [ ] = [ ] ;
66+ for ( let [ cu , cv ] of INTERNAL ) {
6767 let inside = 0 ;
6868 let inked = 0 ;
6969 for ( let sy = 0 ; sy < SAMPLES ; sy ++ ) {
7070 for ( let sx = 0 ; sx < SAMPLES ; sx ++ ) {
7171 // jittered grid point in the circle's bounding square
72- const u = cu - CIRCLE_R + ( ( sx + 0.5 ) / SAMPLES ) * 2 * CIRCLE_R ;
73- const v = cv - CIRCLE_R + ( ( sy + 0.5 ) / SAMPLES ) * 2 * CIRCLE_R ;
74- const du = u - cu ;
75- const dv = v - cv ;
72+ let u = cu - CIRCLE_R + ( ( sx + 0.5 ) / SAMPLES ) * 2 * CIRCLE_R ;
73+ let v = cv - CIRCLE_R + ( ( sy + 0.5 ) / SAMPLES ) * 2 * CIRCLE_R ;
74+ let du = u - cu ;
75+ let dv = v - cv ;
7676 if ( du * du + dv * dv > CIRCLE_R * CIRCLE_R ) {
7777 continue ;
7878 }
@@ -88,8 +88,8 @@ function shapeVector(font: Uint8Array): number[] {
8888}
8989
9090function normalize ( vectors : number [ ] [ ] ) : number [ ] [ ] {
91- const max = [ 0 , 0 , 0 , 0 , 0 , 0 ] ;
92- for ( const vector of vectors ) {
91+ let max = [ 0 , 0 , 0 , 0 , 0 , 0 ] ;
92+ for ( let vector of vectors ) {
9393 for ( let k = 0 ; k < 6 ; k ++ ) {
9494 if ( vector [ k ] > max [ k ] ) {
9595 max [ k ] = vector [ k ] ;
@@ -102,7 +102,7 @@ function normalize(vectors: number[][]): number[][] {
102102}
103103
104104function render ( vectors : number [ ] [ ] ) : string {
105- const lines : string [ ] = [ ] ;
105+ let lines : string [ ] = [ ] ;
106106 lines . push ( "/* GENERATED by tasks/gen-shape-vectors.ts — do not edit." ) ;
107107 lines . push ( " *" ) ;
108108 lines . push ( " * Shape vectors for the ascii art tier (Graphics Specification" ) ;
@@ -128,11 +128,11 @@ function render(vectors: number[][]): string {
128128 lines . push ( "" ) ;
129129 lines . push ( "#define SHAPE_VECTOR_COUNT 95" ) ;
130130 lines . push ( "" ) ;
131- lines . push ( "static const float SHAPE_VECTORS[95][6] = {" ) ;
131+ lines . push ( "static let float SHAPE_VECTORS[95][6] = {" ) ;
132132 for ( let i = 0 ; i < 95 ; i ++ ) {
133- const cp = 0x20 + i ;
134- const label = cp === 0x20 ? "space" : String . fromCharCode ( cp ) ;
135- const vals = vectors [ i ]
133+ let cp = 0x20 + i ;
134+ let label = cp === 0x20 ? "space" : String . fromCharCode ( cp ) ;
135+ let vals = vectors [ i ]
136136 . map ( (
137137 v ,
138138 ) => ( v === 0 ? "0" : v . toFixed ( 6 ) . replace ( / 0 + $ / , "" ) . replace ( / \. $ / , "" ) ) )
@@ -150,19 +150,19 @@ function render(vectors: number[][]): string {
150150
151151// Regenerate: deno task gen-shape. Verify: deno task gen-shape:check.
152152
153- const glyphs = loadFont ( ) ;
153+ let glyphs = loadFont ( ) ;
154154if ( glyphs . length < 0x7f ) {
155155 console . error ( `font parse failed: ${ glyphs . length } glyphs` ) ;
156156 Deno . exit ( 1 ) ;
157157}
158- const vectors = normalize (
158+ let vectors = normalize (
159159 Array . from ( { length : 95 } , ( _ , i ) => shapeVector ( glyphs [ 0x20 + i ] ) ) ,
160160) ;
161- const out = render ( vectors ) ;
161+ let out = render ( vectors ) ;
162162
163- const check = Deno . args . includes ( "--check" ) ;
163+ let check = Deno . args . includes ( "--check" ) ;
164164if ( check ) {
165- const existing = new TextDecoder ( ) . decode ( Deno . readFileSync ( OUT_PATH ) ) ;
165+ let existing = new TextDecoder ( ) . decode ( Deno . readFileSync ( OUT_PATH ) ) ;
166166 if ( existing !== out ) {
167167 console . error ( `${ OUT_PATH } is stale; run deno task gen-shape` ) ;
168168 Deno . exit ( 1 ) ;
0 commit comments