11import * as ast from "./ast" ;
2- import { NUMBER_KINDS } from "../constants/consts" ;
2+ import { NUMBER_KINDS , SCALE_OP } from "../constants/consts" ;
33import {
44 FUNC_ARG_SIZE ,
55 CAST_SIZE ,
66 PAD_SIZE ,
7+ PROPTO_SIZE
78} from "../constants/variableconsts" ;
89import { quad , coord } from "../constants/types" ;
10+ import { mainModule } from "process" ;
11+ import { createContext } from "vm" ;
912
1013export function findCenter ( q : quad ) : coord {
1114 return {
@@ -67,7 +70,7 @@ export function makeAtCenter(
6770 } ;
6871}
6972
70- export function addCoords ( node : ast . ASTNode , boundary : quad ) : ast . ASTNode {
73+ export function addCoords ( node : ast . ASTNode , boundary : quad , preboxed : Boolean = false ) : ast . ASTNode {
7174 switch ( node . kind ) {
7275 case "transform" : {
7376 let node_ = < ast . ASTTransform > node ;
@@ -85,7 +88,29 @@ export function addCoords(node: ast.ASTNode, boundary: quad): ast.ASTNode {
8588 bound . bl . y -= PAD_SIZE ;
8689 bound . br . x -= PAD_SIZE ;
8790 bound . br . y -= PAD_SIZE ;
88- node_ . node = addCoords ( node_ . node , bound ) ;
91+ node_ . node = addCoords ( node_ . node , bound , true ) ;
92+ return node_ ;
93+ }
94+ case "scale" : {
95+ let node_ = < ast . ASTScale > node ;
96+ node_ . boundary = makeAtCenter (
97+ findCenter ( boundary ) ,
98+ node . hor_len ! ,
99+ node . ver_len !
100+ ) ;
101+ let size = Math . max ( 0.2 * CAST_SIZE * ( node_ . coefficient . expr . length + 3 ) + PAD_SIZE ,
102+ FUNC_ARG_SIZE ) ;
103+
104+ let bound : quad = JSON . parse ( JSON . stringify ( boundary ) ) ;
105+ bound . tl . x += PAD_SIZE + size ;
106+ bound . tl . y += PAD_SIZE ;
107+ bound . tr . x -= PAD_SIZE ;
108+ bound . tr . y += PAD_SIZE ;
109+ bound . bl . x += PAD_SIZE + size ;
110+ bound . bl . y -= PAD_SIZE ;
111+ bound . br . x -= PAD_SIZE ;
112+ bound . br . y -= PAD_SIZE ;
113+ node_ . node = addCoords ( node_ . node , bound , true ) ;
89114 return node_ ;
90115 }
91116 case "const" : {
@@ -130,41 +155,42 @@ export function addCoords(node: ast.ASTNode, boundary: quad): ast.ASTNode {
130155 node . ver_len !
131156 ) ;
132157 // console.log("stack node bound: ", node_.boundary);
158+ let ADJ_SIZE = preboxed ? 0 : PAD_SIZE ;
133159 let l_bound = {
134160 tl : {
135- x : node_ . boundary . tl . x + PAD_SIZE ,
136- y : node_ . boundary . tl . y + PAD_SIZE ,
161+ x : node_ . boundary . tl . x + ADJ_SIZE ,
162+ y : node_ . boundary . tl . y + ADJ_SIZE ,
137163 } ,
138164 tr : {
139- x : node_ . boundary . tr . x - PAD_SIZE ,
140- y : node_ . boundary . tr . y + PAD_SIZE ,
165+ x : node_ . boundary . tr . x - ADJ_SIZE ,
166+ y : node_ . boundary . tr . y + ADJ_SIZE ,
141167 } ,
142168 bl : {
143- x : node_ . boundary . tl . x + PAD_SIZE ,
144- y : node_ . boundary . tl . y + l_ver + PAD_SIZE ,
169+ x : node_ . boundary . tl . x + ADJ_SIZE ,
170+ y : node_ . boundary . tl . y + l_ver + ADJ_SIZE ,
145171 } ,
146172 br : {
147- x : node_ . boundary . tr . x - PAD_SIZE ,
148- y : node_ . boundary . tr . y + l_ver + PAD_SIZE ,
173+ x : node_ . boundary . tr . x - ADJ_SIZE ,
174+ y : node_ . boundary . tr . y + l_ver + ADJ_SIZE ,
149175 } ,
150176 } as quad ;
151177 // console.log("l_bound: ", l_bound);
152178 let r_bound = {
153179 bl : {
154- x : node_ . boundary . bl . x + PAD_SIZE ,
155- y : node_ . boundary . bl . y - PAD_SIZE ,
180+ x : node_ . boundary . bl . x + ADJ_SIZE ,
181+ y : node_ . boundary . bl . y - ADJ_SIZE ,
156182 } ,
157183 br : {
158- x : node_ . boundary . br . x - PAD_SIZE ,
159- y : node_ . boundary . br . y - PAD_SIZE ,
184+ x : node_ . boundary . br . x - ADJ_SIZE ,
185+ y : node_ . boundary . br . y - ADJ_SIZE ,
160186 } ,
161187 tl : {
162- x : node_ . boundary . tl . x + PAD_SIZE ,
163- y : node_ . boundary . bl . y - r_ver - PAD_SIZE ,
188+ x : node_ . boundary . tl . x + ADJ_SIZE ,
189+ y : node_ . boundary . bl . y - r_ver - ADJ_SIZE ,
164190 } ,
165191 tr : {
166- x : node_ . boundary . tr . x - PAD_SIZE ,
167- y : node_ . boundary . br . y - r_ver - PAD_SIZE ,
192+ x : node_ . boundary . tr . x - ADJ_SIZE ,
193+ y : node_ . boundary . br . y - r_ver - ADJ_SIZE ,
168194 } ,
169195 } as quad ;
170196 // console.log("r_bound: ", r_bound);
@@ -181,41 +207,42 @@ export function addCoords(node: ast.ASTNode, boundary: quad): ast.ASTNode {
181207 node . hor_len ! ,
182208 node . ver_len !
183209 ) ;
210+ let ADJ_SIZE = preboxed ? 0 : PAD_SIZE ;
184211 let l_bound = {
185212 tl : {
186- x : node_ . boundary . tl . x + PAD_SIZE ,
187- y : node_ . boundary . tl . y + PAD_SIZE ,
213+ x : node_ . boundary . tl . x + ADJ_SIZE ,
214+ y : node_ . boundary . tl . y + ADJ_SIZE ,
188215 } ,
189216 tr : {
190- x : node_ . boundary . tl . x + l_hor + PAD_SIZE ,
191- y : node_ . boundary . tl . y + PAD_SIZE ,
217+ x : node_ . boundary . tl . x + l_hor + ADJ_SIZE ,
218+ y : node_ . boundary . tl . y + ADJ_SIZE ,
192219 } ,
193220 bl : {
194- x : node_ . boundary . bl . x + PAD_SIZE ,
195- y : node_ . boundary . bl . y - PAD_SIZE ,
221+ x : node_ . boundary . bl . x + ADJ_SIZE ,
222+ y : node_ . boundary . bl . y - ADJ_SIZE ,
196223 } ,
197224 br : {
198- x : node_ . boundary . tl . x + l_hor + PAD_SIZE ,
199- y : node_ . boundary . bl . y - PAD_SIZE ,
225+ x : node_ . boundary . tl . x + l_hor + ADJ_SIZE ,
226+ y : node_ . boundary . bl . y - ADJ_SIZE ,
200227 } ,
201228 } as quad ;
202229 // console.log("l_bound: ", l_bound);
203230 let r_bound = {
204231 tl : {
205- x : node_ . boundary . tr . x - r_hor - PAD_SIZE ,
206- y : node_ . boundary . tr . y + PAD_SIZE ,
232+ x : node_ . boundary . tr . x - r_hor - ADJ_SIZE ,
233+ y : node_ . boundary . tr . y + ADJ_SIZE ,
207234 } ,
208235 tr : {
209- x : node_ . boundary . tr . x - PAD_SIZE ,
210- y : node_ . boundary . tr . y + PAD_SIZE ,
236+ x : node_ . boundary . tr . x - ADJ_SIZE ,
237+ y : node_ . boundary . tr . y + ADJ_SIZE ,
211238 } ,
212239 bl : {
213- x : node_ . boundary . br . x - r_hor - PAD_SIZE ,
214- y : node_ . boundary . bl . y - PAD_SIZE ,
240+ x : node_ . boundary . br . x - r_hor - ADJ_SIZE ,
241+ y : node_ . boundary . bl . y - ADJ_SIZE ,
215242 } ,
216243 br : {
217- x : node_ . boundary . br . x - PAD_SIZE ,
218- y : node_ . boundary . br . y - PAD_SIZE ,
244+ x : node_ . boundary . br . x - ADJ_SIZE ,
245+ y : node_ . boundary . br . y - ADJ_SIZE ,
219246 } ,
220247 } as quad ;
221248 // console.log("r_bound: ", r_bound);
@@ -309,7 +336,7 @@ export function addCoords(node: ast.ASTNode, boundary: quad): ast.ASTNode {
309336 bound . bl . y -= PAD_SIZE ;
310337 bound . br . x -= CAST_SIZE ;
311338 bound . br . y -= PAD_SIZE ;
312- node_ . node = addCoords ( node_ . node , bound ) ;
339+ node_ . node = addCoords ( node_ . node , bound , true ) ;
313340 return node_ ;
314341 }
315342 case "function" : {
@@ -392,8 +419,8 @@ export function addCoords(node: ast.ASTNode, boundary: quad): ast.ASTNode {
392419 y : node_ . boundary . br . y - PAD_SIZE ,
393420 } ,
394421 } as quad ;
395- node_ . l = addCoords ( node_ . l , l_bound ) ;
396- node_ . r = addCoords ( node_ . r , r_bound ) ;
422+ node_ . l = addCoords ( node_ . l , l_bound , true ) ;
423+ node_ . r = addCoords ( node_ . r , r_bound , true ) ;
397424 return node_ ;
398425 }
399426 default : {
0 commit comments