@@ -319,6 +319,8 @@ dgcout << "\nDgQ2DDtoIConverter::convertTypedAddress loc: " << *loc << endl;
319
319
320
320
IDGG ().grid2D ().convert (loc);
321
321
322
+ // dgcout << "XX " << addIn << " " << *loc << endl;
323
+
322
324
#if DGDEBUG
323
325
dgcout << " ---> A. " << *loc << endl;
324
326
#endif
@@ -328,83 +330,144 @@ dgcout << " ---> A. " << *loc << endl;
328
330
329
331
int quadNum = addIn.quadNum ();
330
332
331
- const long double nudge = 0 .0000001L ;
332
- if (coord.i () < 0 || coord.j () < 0 ) // maybe round-off error?
333
- {
334
- DgDVec2D tmp (addIn.coord ());
335
-
336
- tmp.setX (tmp.x () + nudge);
337
- tmp.setY (tmp.y () + nudge);
338
-
339
- loc = IDGG ().ccFrame ().makeLocation (tmp);
340
- IDGG ().grid2D ().convert (loc);
341
- coord = *IDGG ().grid2D ().getAddress (*loc);
342
- delete loc;
343
- }
344
-
345
333
#if DGDEBUG
346
334
dgcout << " ---> B. " << coord << endl;
347
335
#endif
348
336
349
337
long long int maxI = IDGG ().maxI ();
350
338
long long int maxJ = IDGG ().maxJ ();
351
- long long int edgeI = maxI + 1 ;
352
- long long int edgeJ = maxJ + 1 ;
353
- long long int maxOverageI = (IDGG ().aperture () == 7 && IDGG ().isClassI ()) ? edgeI + 1 : edgeI;
354
- long long int maxOverageJ = (IDGG ().aperture () == 7 && IDGG ().isClassI ()) ? edgeJ + 1 : edgeJ;
355
-
356
- if (coord.i () > maxOverageI || coord.j () > maxOverageJ) { // maybe round-off error?
357
-
358
- DgDVec2D tmp (addIn.coord ());
359
-
339
+ long long int topEdgeI = maxI + 1 ;
340
+ long long int topEdgeJ = maxJ + 1 ;
341
+ /*
342
+ long long int maxTopOverageI = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeI + 1 : topEdgeI;
343
+ long long int maxTopOverageJ = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeJ + 1 : topEdgeJ;
344
+ long long int minBottomI = (IDGG().aperture() == 7 && IDGG().isClassI()) ? -1 : 0;
345
+ long long int minBottomJ = (IDGG().aperture() == 7 && IDGG().isClassI()) ? -1 : 0;
346
+ */
347
+ /*
348
+ long long int maxTopOverageI = (IDGG().aperture() == 7 && ! ? topEdgeI + 2 : topEdgeI;
349
+ long long int maxTopOverageJ = (IDGG().aperture() == 7) ? topEdgeJ + 2 : topEdgeJ;
350
+ */
351
+ /*
352
+ long long int maxTopOverageI = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeI + 2 : topEdgeI;
353
+ long long int maxTopOverageJ = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeJ + 2 : topEdgeJ;
354
+ */
355
+
356
+ long long int maxTopOverageI = (IDGG ().aperture () == 7 ) ? topEdgeI + 2 : topEdgeI;
357
+ long long int maxTopOverageJ = (IDGG ().aperture () == 7 ) ? topEdgeJ + 2 : topEdgeJ;
358
+
359
+ long long int minBottomI = (IDGG ().aperture () == 7 ) ? -2 : 0 ;
360
+ long long int minBottomJ = (IDGG ().aperture () == 7 ) ? -2 : 0 ;
361
+
362
+ // if out of range check for possible round-off error
363
+ const long double nudge = 0 .0000001L ;
364
+ bool underI, underJ, overI, overJ;
365
+ underI = coord.i () < minBottomI;
366
+ underJ = coord.j () < minBottomJ;
367
+ overI = coord.i () > maxTopOverageI;
368
+ overJ = coord.j () > maxTopOverageJ;
369
+
370
+ DgDVec2D tmp (addIn.coord ());
371
+ bool overage = false ;
372
+ if (underI || underJ) {
373
+ overage = true ;
374
+ tmp.setX (tmp.x () + nudge);
375
+ tmp.setY (tmp.y () + nudge);
376
+ } else if (overI || overJ) {
377
+ overage = true ;
360
378
tmp.setX (tmp.x () - nudge);
361
379
tmp.setY (tmp.y () - nudge);
380
+ }
362
381
382
+ if (overage) {
383
+ // nudge the incoming point and try again
363
384
loc = IDGG ().ccFrame ().makeLocation (tmp);
364
385
IDGG ().grid2D ().convert (loc);
365
386
coord = *IDGG ().grid2D ().getAddress (*loc);
366
387
delete loc;
388
+
389
+ // reset the overage conditions
390
+ // underI = coord.i() < minBottomI;
391
+ // underJ = coord.j() < minBottomJ;
392
+ overI = coord.i () > maxTopOverageI;
393
+ overJ = coord.j () > maxTopOverageJ;
394
+
395
+ // are we good?
396
+ // if (underI || underJ || overI || overJ)
397
+ if (overI || overJ)
398
+
399
+ report (" DgQ2DDtoIConverter::convertTypedAddress(): "
400
+ " coordinate out of range: " + (string) coord, DgBase::Fatal);
367
401
}
368
402
369
403
#if DGDEBUG
370
404
dgcout << " ---> C. " << coord << endl;
371
405
#endif
372
-
373
- if ( coord.i () < 0 || coord. j () < 0 ||
374
- coord.i () > maxOverageI || coord. j () > maxOverageJ) {
375
- report ( " DgQ2DDtoIConverter::convertTypedAddress(): "
376
- " coordinate out of range: " + (string) coord, DgBase::Fatal) ;
377
- } else if (coord. i () > maxI || coord. j () > maxJ) {
378
- const DgQuadEdgeCells& ec = IDGG (). edgeTable (quadNum);
379
-
380
- if (ec. isType0 ()) {
381
- if (coord. j () > maxI) {
382
- if (coord. i () == 0 ) {
383
- quadNum = ec. loneVert ();
384
- coord = DgIVec2D ( 0 , 0 );
385
- } else {
406
+ // we'll reuse the booleans above set to based on the actual quad i,j ranges
407
+ // underI = coord.i() < 0;
408
+ // underJ = coord.j() < 0;
409
+ overI = coord. i () > maxI;
410
+ overJ = coord. j () > maxJ ;
411
+ // int numOver = underI + underJ + overI + overJ; // works because bool is an int
412
+ // if (numOver) {
413
+ if (overI || overJ) {
414
+ const DgQuadEdgeCells& ec = IDGG (). edgeTable (quadNum);
415
+
416
+ // special case first
417
+ if (overI && overJ) {
418
+ // must be upper right corner
419
+ if (ec. isType0 ()) {
386
420
quadNum = ec.upQuad ();
387
- coord = DgIVec2D ((maxOverageI - edgeI), maxOverageI - coord.i ());
388
- }
389
- } else { // i == edgeI
390
- quadNum = ec.rightQuad ();
391
- coord.setI (0 );
392
- }
393
- } else { // type 1
394
- if (coord.i () > maxI) {
395
- if (coord.j () == 0 ) {
396
- quadNum = ec.loneVert ();
397
421
coord = DgIVec2D (0 , 0 );
398
- } else {
422
+ } else { // TypeI
399
423
quadNum = ec.rightQuad ();
400
- coord = DgIVec2D (maxOverageJ - coord.j (), (maxOverageJ - edgeJ));
424
+ coord = DgIVec2D (0 , 0 );
425
+ }
426
+ /*
427
+ } else if (underI) {
428
+ if (ec.isType0()) {
429
+ } else { // TypeI
401
430
}
402
- } else { // j > maxJ
403
- quadNum = ec.upQuad ();
404
- coord.setJ (0 );
405
- }
406
- }
407
- }
431
+ } else if (underJ) {
432
+ if (ec.isType0()) {
433
+ } else { // TypeI
434
+ }
435
+ */
436
+ } else if (overI) {
437
+ if (ec.isType0 ()) {
438
+ quadNum = ec.rightQuad ();
439
+ coord.setI (0 );
440
+ } else { // TypeI
441
+ if (coord.j () == 0 ) {
442
+ quadNum = ec.loneVert ();
443
+ coord = DgIVec2D (0 , 0 );
444
+ } else {
445
+ quadNum = ec.rightQuad ();
446
+ // if we're here overI is true and overJ is false
447
+ coord = DgIVec2D (topEdgeJ - coord.j (), coord.i () - topEdgeI);
448
+ /*
449
+ coord = DgIVec2D(maxTopOverageJ - coord.j(), (maxTopOverageJ - topEdgeJ));
450
+ */
451
+ }
452
+ }
453
+ } else if (overJ) {
454
+ if (ec.isType0 ()) {
455
+ if (coord.i () == 0 ) {
456
+ quadNum = ec.loneVert ();
457
+ coord = DgIVec2D (0 , 0 );
458
+ } else {
459
+ quadNum = ec.upQuad ();
460
+ coord = DgIVec2D (coord.j () - topEdgeJ, topEdgeI - coord.i ());
461
+ /*
462
+ coord = DgIVec2D((maxTopOverageI - topEdgeI), maxTopOverageI - coord.i());
463
+ */
464
+ }
465
+ } else { // TypeI
466
+ quadNum = ec.upQuad ();
467
+ coord.setJ (0 );
468
+ }
469
+ }
470
+ }
408
471
409
472
#if DGDEBUG
410
473
dgcout << " ---> D. " << coord << endl;
0 commit comments