Skip to content

Commit 5a5f1a6

Browse files
committed
merge ap7 fixes
1 parent 1670c2a commit 5a5f1a6

File tree

6 files changed

+176
-111
lines changed

6 files changed

+176
-111
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
All changes are by Kevin Sahr, unless otherwise noted.
55

6-
## [8.2] - 2024-06-05
6+
## [8.2] - 2024-06-15
77
### Fixed
88
- bug binning some points that are very close to certain icosahedron edges into odd aperture 7 resolutions
9+
- failure when performing a TRANSFORM operation with input files other than lat/lon
910

1011
## [8.1b] - 2024-01-10
1112
### Added

src/lib/dglib/include/dglib/DgIDGGutil.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,18 @@ class DgQuadEdgeCells {
214214
public:
215215

216216
DgQuadEdgeCells (int quadNumIn, bool isType0In, int loneVertIn,
217-
int upQuadIn, int rightQuadIn)
217+
int upQuadIn, int downQuadIn, int rightQuadIn, int leftQuadIn)
218218
: isType0_ (isType0In), quadNum_ (quadNumIn), loneVert_ (loneVertIn),
219-
upQuad_ (upQuadIn), rightQuad_ (rightQuadIn) { }
219+
upQuad_ (upQuadIn), downQuad_ (downQuadIn), rightQuad_ (rightQuadIn),
220+
leftQuad_ (leftQuadIn) { }
220221

221222
bool isType0 (void) const { return isType0_; }
222223
int quadNum (void) const { return quadNum_; }
223224
int loneVert (void) const { return loneVert_; }
224225
int upQuad (void) const { return upQuad_; }
226+
int downQuad (void) const { return downQuad_; }
225227
int rightQuad (void) const { return rightQuad_; }
228+
int leftQuad (void) const { return leftQuad_; }
226229

227230
private:
228231

@@ -231,8 +234,9 @@ class DgQuadEdgeCells {
231234
int quadNum_;
232235
int loneVert_;
233236
int upQuad_;
237+
int downQuad_;
234238
int rightQuad_;
235-
239+
int leftQuad_;
236240
};
237241

238242
////////////////////////////////////////////////////////////////////////////////

src/lib/dglib/lib/DgIDGGBase.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ DgGridMetric DgIDGGBase::gridMetric (void) const { return dggs()->gridMetri
5757
////////////////////////////////////////////////////////////////////////////////
5858
const DgQuadEdgeCells DgIDGGBase::edgeTable_[12] = {
5959

60-
DgQuadEdgeCells(0, true, 0, 0, 0), // quad 0 should never occur
61-
DgQuadEdgeCells(1, true, 0, 2, 6),
62-
DgQuadEdgeCells(2, true, 0, 3, 7),
63-
DgQuadEdgeCells(3, true, 0, 4, 8),
64-
DgQuadEdgeCells(4, true, 0, 5, 9),
65-
DgQuadEdgeCells(5, true, 0, 1, 10),
66-
DgQuadEdgeCells(6, false, 11, 2, 7),
67-
DgQuadEdgeCells(7, false, 11, 3, 8),
68-
DgQuadEdgeCells(8, false, 11, 4, 9),
69-
DgQuadEdgeCells(9, false, 11, 5, 10),
70-
DgQuadEdgeCells(10, false, 11, 1, 6),
71-
DgQuadEdgeCells(11, false, 11, 0, 0) // quad 11 should never occur
60+
DgQuadEdgeCells(0, true, 0, 0, 0, 0, 0), // quad 0 should never occur
61+
DgQuadEdgeCells(1, true, 0, 2, 10, 6, 5),
62+
DgQuadEdgeCells(2, true, 0, 3, 6, 7, 1),
63+
DgQuadEdgeCells(3, true, 0, 4, 7, 8, 2),
64+
DgQuadEdgeCells(4, true, 0, 5, 8, 9, 3),
65+
DgQuadEdgeCells(5, true, 0, 1, 9, 10, 4),
66+
DgQuadEdgeCells(6, false, 11, 2, 10, 7, 1),
67+
DgQuadEdgeCells(7, false, 11, 3, 6, 8, 2),
68+
DgQuadEdgeCells(8, false, 11, 4, 7, 9, 3),
69+
DgQuadEdgeCells(9, false, 11, 5, 8, 10, 4),
70+
DgQuadEdgeCells(10, false, 11, 1, 9, 6, 5),
71+
DgQuadEdgeCells(11, false, 11, 0, 0, 0, 0) // quad 11 should never occur
7272

7373
};
7474

src/lib/dglib/lib/DgIDGGutil.cpp

+118-55
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ dgcout << "\nDgQ2DDtoIConverter::convertTypedAddress loc: " << *loc << endl;
319319

320320
IDGG().grid2D().convert(loc);
321321

322+
//dgcout << "XX " << addIn << " " << *loc << endl;
323+
322324
#if DGDEBUG
323325
dgcout << " ---> A. " << *loc << endl;
324326
#endif
@@ -328,83 +330,144 @@ dgcout << " ---> A. " << *loc << endl;
328330

329331
int quadNum = addIn.quadNum();
330332

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-
345333
#if DGDEBUG
346334
dgcout << " ---> B. " << coord << endl;
347335
#endif
348336

349337
long long int maxI = IDGG().maxI();
350338
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;
360378
tmp.setX(tmp.x() - nudge);
361379
tmp.setY(tmp.y() - nudge);
380+
}
362381

382+
if (overage) {
383+
// nudge the incoming point and try again
363384
loc = IDGG().ccFrame().makeLocation(tmp);
364385
IDGG().grid2D().convert(loc);
365386
coord = *IDGG().grid2D().getAddress(*loc);
366387
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);
367401
}
368402

369403
#if DGDEBUG
370404
dgcout << " ---> C. " << coord << endl;
371405
#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()) {
386420
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();
397421
coord = DgIVec2D(0, 0);
398-
} else {
422+
} else { // TypeI
399423
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
401430
}
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+
}
408471

409472
#if DGDEBUG
410473
dgcout << " ---> D. " << coord << endl;

src/lib/dglib/lib/DgInLocTextFile.cpp

+1-15
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,8 @@ DgInLocTextFile::DgInLocTextFile (const DgRFBase& rfIn, const string* fileNameIn
4242
: DgInLocStreamFile (rfIn, fileNameIn, false, failLevel),
4343
forcePolyLine_ (false), forceCells_ (false)
4444
{
45-
// the rf needs to be lat/lon
45+
// create lat/lon rf (may be NULL)
4646
degRF_ = dynamic_cast<const DgGeoSphDegRF*>(&rfIn);
47-
if (!degRF_) {
48-
report("DgInLocTextFile::DgInLocTextFile(): RF " + rfIn.name() +
49-
" is not longitude/latitude", DgBase::Fatal);
50-
}
51-
52-
/* not needed since must be lat/lon
53-
// test for override of vecAddress
54-
DgAddressBase* dummy = rfIn.vecAddress(DgDVec2D(M_ZERO, M_ZERO));
55-
if (!dummy) {
56-
report("DgInLocTextFile::DgInLocTextFile(): RF " + rfIn.name() +
57-
" must override the vecAddress() method", DgBase::Fatal);
58-
}
59-
delete dummy;
60-
*/
6147

6248
} // DgInLocTextFile::DgInLocTextFile
6349

0 commit comments

Comments
 (0)