Skip to content

Commit

Permalink
merge ap7 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sahrkm committed Jun 15, 2024
1 parent 1670c2a commit 5a5f1a6
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 111 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ All notable changes to this project will be documented in this file.

All changes are by Kevin Sahr, unless otherwise noted.

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

## [8.1b] - 2024-01-10
### Added
Expand Down
10 changes: 7 additions & 3 deletions src/lib/dglib/include/dglib/DgIDGGutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,18 @@ class DgQuadEdgeCells {
public:

DgQuadEdgeCells (int quadNumIn, bool isType0In, int loneVertIn,
int upQuadIn, int rightQuadIn)
int upQuadIn, int downQuadIn, int rightQuadIn, int leftQuadIn)
: isType0_ (isType0In), quadNum_ (quadNumIn), loneVert_ (loneVertIn),
upQuad_ (upQuadIn), rightQuad_ (rightQuadIn) { }
upQuad_ (upQuadIn), downQuad_ (downQuadIn), rightQuad_ (rightQuadIn),
leftQuad_ (leftQuadIn) { }

bool isType0 (void) const { return isType0_; }
int quadNum (void) const { return quadNum_; }
int loneVert (void) const { return loneVert_; }
int upQuad (void) const { return upQuad_; }
int downQuad (void) const { return downQuad_; }
int rightQuad (void) const { return rightQuad_; }
int leftQuad (void) const { return leftQuad_; }

private:

Expand All @@ -231,8 +234,9 @@ class DgQuadEdgeCells {
int quadNum_;
int loneVert_;
int upQuad_;
int downQuad_;
int rightQuad_;

int leftQuad_;
};

////////////////////////////////////////////////////////////////////////////////
Expand Down
24 changes: 12 additions & 12 deletions src/lib/dglib/lib/DgIDGGBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ DgGridMetric DgIDGGBase::gridMetric (void) const { return dggs()->gridMetri
////////////////////////////////////////////////////////////////////////////////
const DgQuadEdgeCells DgIDGGBase::edgeTable_[12] = {

DgQuadEdgeCells(0, true, 0, 0, 0), // quad 0 should never occur
DgQuadEdgeCells(1, true, 0, 2, 6),
DgQuadEdgeCells(2, true, 0, 3, 7),
DgQuadEdgeCells(3, true, 0, 4, 8),
DgQuadEdgeCells(4, true, 0, 5, 9),
DgQuadEdgeCells(5, true, 0, 1, 10),
DgQuadEdgeCells(6, false, 11, 2, 7),
DgQuadEdgeCells(7, false, 11, 3, 8),
DgQuadEdgeCells(8, false, 11, 4, 9),
DgQuadEdgeCells(9, false, 11, 5, 10),
DgQuadEdgeCells(10, false, 11, 1, 6),
DgQuadEdgeCells(11, false, 11, 0, 0) // quad 11 should never occur
DgQuadEdgeCells(0, true, 0, 0, 0, 0, 0), // quad 0 should never occur
DgQuadEdgeCells(1, true, 0, 2, 10, 6, 5),
DgQuadEdgeCells(2, true, 0, 3, 6, 7, 1),
DgQuadEdgeCells(3, true, 0, 4, 7, 8, 2),
DgQuadEdgeCells(4, true, 0, 5, 8, 9, 3),
DgQuadEdgeCells(5, true, 0, 1, 9, 10, 4),
DgQuadEdgeCells(6, false, 11, 2, 10, 7, 1),
DgQuadEdgeCells(7, false, 11, 3, 6, 8, 2),
DgQuadEdgeCells(8, false, 11, 4, 7, 9, 3),
DgQuadEdgeCells(9, false, 11, 5, 8, 10, 4),
DgQuadEdgeCells(10, false, 11, 1, 9, 6, 5),
DgQuadEdgeCells(11, false, 11, 0, 0, 0, 0) // quad 11 should never occur

};

Expand Down
173 changes: 118 additions & 55 deletions src/lib/dglib/lib/DgIDGGutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ dgcout << "\nDgQ2DDtoIConverter::convertTypedAddress loc: " << *loc << endl;

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

//dgcout << "XX " << addIn << " " << *loc << endl;

#if DGDEBUG
dgcout << " ---> A. " << *loc << endl;
#endif
Expand All @@ -328,83 +330,144 @@ dgcout << " ---> A. " << *loc << endl;

int quadNum = addIn.quadNum();

const long double nudge = 0.0000001L;
if (coord.i() < 0 || coord.j() < 0) // maybe round-off error?
{
DgDVec2D tmp(addIn.coord());

tmp.setX(tmp.x() + nudge);
tmp.setY(tmp.y() + nudge);

loc = IDGG().ccFrame().makeLocation(tmp);
IDGG().grid2D().convert(loc);
coord = *IDGG().grid2D().getAddress(*loc);
delete loc;
}

#if DGDEBUG
dgcout << " ---> B. " << coord << endl;
#endif

long long int maxI = IDGG().maxI();
long long int maxJ = IDGG().maxJ();
long long int edgeI = maxI + 1;
long long int edgeJ = maxJ + 1;
long long int maxOverageI = (IDGG().aperture() == 7 && IDGG().isClassI()) ? edgeI + 1 : edgeI;
long long int maxOverageJ = (IDGG().aperture() == 7 && IDGG().isClassI()) ? edgeJ + 1 : edgeJ;

if (coord.i() > maxOverageI || coord.j() > maxOverageJ) { // maybe round-off error?

DgDVec2D tmp(addIn.coord());

long long int topEdgeI = maxI + 1;
long long int topEdgeJ = maxJ + 1;
/*
long long int maxTopOverageI = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeI + 1 : topEdgeI;
long long int maxTopOverageJ = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeJ + 1 : topEdgeJ;
long long int minBottomI = (IDGG().aperture() == 7 && IDGG().isClassI()) ? -1 : 0;
long long int minBottomJ = (IDGG().aperture() == 7 && IDGG().isClassI()) ? -1 : 0;
*/
/*
long long int maxTopOverageI = (IDGG().aperture() == 7 && ! ? topEdgeI + 2 : topEdgeI;
long long int maxTopOverageJ = (IDGG().aperture() == 7) ? topEdgeJ + 2 : topEdgeJ;
*/
/*
long long int maxTopOverageI = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeI + 2 : topEdgeI;
long long int maxTopOverageJ = (IDGG().aperture() == 7 && IDGG().isClassI()) ? topEdgeJ + 2 : topEdgeJ;
*/

long long int maxTopOverageI = (IDGG().aperture() == 7) ? topEdgeI + 2 : topEdgeI;
long long int maxTopOverageJ = (IDGG().aperture() == 7) ? topEdgeJ + 2 : topEdgeJ;

long long int minBottomI = (IDGG().aperture() == 7) ? -2 : 0;
long long int minBottomJ = (IDGG().aperture() == 7) ? -2 : 0;

// if out of range check for possible round-off error
const long double nudge = 0.0000001L;
bool underI, underJ, overI, overJ;
underI = coord.i() < minBottomI;
underJ = coord.j() < minBottomJ;
overI = coord.i() > maxTopOverageI;
overJ = coord.j() > maxTopOverageJ;

DgDVec2D tmp(addIn.coord());
bool overage = false;
if (underI || underJ) {
overage = true;
tmp.setX(tmp.x() + nudge);
tmp.setY(tmp.y() + nudge);
} else if (overI || overJ) {
overage = true;
tmp.setX(tmp.x() - nudge);
tmp.setY(tmp.y() - nudge);
}

if (overage) {
// nudge the incoming point and try again
loc = IDGG().ccFrame().makeLocation(tmp);
IDGG().grid2D().convert(loc);
coord = *IDGG().grid2D().getAddress(*loc);
delete loc;

// reset the overage conditions
//underI = coord.i() < minBottomI;
//underJ = coord.j() < minBottomJ;
overI = coord.i() > maxTopOverageI;
overJ = coord.j() > maxTopOverageJ;

// are we good?
//if (underI || underJ || overI || overJ)
if (overI || overJ)

report("DgQ2DDtoIConverter::convertTypedAddress(): "
" coordinate out of range: " + (string) coord, DgBase::Fatal);
}

#if DGDEBUG
dgcout << " ---> C. " << coord << endl;
#endif

if (coord.i() < 0 || coord.j() < 0 ||
coord.i() > maxOverageI || coord.j() > maxOverageJ) {
report("DgQ2DDtoIConverter::convertTypedAddress(): "
" coordinate out of range: " + (string) coord, DgBase::Fatal);
} else if (coord.i() > maxI || coord.j() > maxJ) {
const DgQuadEdgeCells& ec = IDGG().edgeTable(quadNum);

if (ec.isType0()) {
if (coord.j() > maxI) {
if (coord.i() == 0) {
quadNum = ec.loneVert();
coord = DgIVec2D(0, 0);
} else {
// we'll reuse the booleans above set to based on the actual quad i,j ranges
//underI = coord.i() < 0;
//underJ = coord.j() < 0;
overI = coord.i() > maxI;
overJ = coord.j() > maxJ;
//int numOver = underI + underJ + overI + overJ; // works because bool is an int
//if (numOver) {
if (overI || overJ) {
const DgQuadEdgeCells& ec = IDGG().edgeTable(quadNum);

// special case first
if (overI && overJ) {
// must be upper right corner
if (ec.isType0()) {
quadNum = ec.upQuad();
coord = DgIVec2D((maxOverageI - edgeI), maxOverageI - coord.i());
}
} else { // i == edgeI
quadNum = ec.rightQuad();
coord.setI(0);
}
} else { // type 1
if (coord.i() > maxI) {
if (coord.j() == 0) {
quadNum = ec.loneVert();
coord = DgIVec2D(0, 0);
} else {
} else { // TypeI
quadNum = ec.rightQuad();
coord = DgIVec2D(maxOverageJ - coord.j(), (maxOverageJ - edgeJ));
coord = DgIVec2D(0, 0);
}
/*
} else if (underI) {
if (ec.isType0()) {
} else { // TypeI
}
} else { // j > maxJ
quadNum = ec.upQuad();
coord.setJ(0);
}
}
}
} else if (underJ) {
if (ec.isType0()) {
} else { // TypeI
}
*/
} else if (overI) {
if (ec.isType0()) {
quadNum = ec.rightQuad();
coord.setI(0);
} else { // TypeI
if (coord.j() == 0) {
quadNum = ec.loneVert();
coord = DgIVec2D(0, 0);
} else {
quadNum = ec.rightQuad();
// if we're here overI is true and overJ is false
coord = DgIVec2D(topEdgeJ - coord.j(), coord.i() - topEdgeI);
/*
coord = DgIVec2D(maxTopOverageJ - coord.j(), (maxTopOverageJ - topEdgeJ));
*/
}
}
} else if (overJ) {
if (ec.isType0()) {
if (coord.i() == 0) {
quadNum = ec.loneVert();
coord = DgIVec2D(0, 0);
} else {
quadNum = ec.upQuad();
coord = DgIVec2D(coord.j() - topEdgeJ, topEdgeI - coord.i());
/*
coord = DgIVec2D((maxTopOverageI - topEdgeI), maxTopOverageI - coord.i());
*/
}
} else { // TypeI
quadNum = ec.upQuad();
coord.setJ(0);
}
}
}

#if DGDEBUG
dgcout << " ---> D. " << coord << endl;
Expand Down
16 changes: 1 addition & 15 deletions src/lib/dglib/lib/DgInLocTextFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,8 @@ DgInLocTextFile::DgInLocTextFile (const DgRFBase& rfIn, const string* fileNameIn
: DgInLocStreamFile (rfIn, fileNameIn, false, failLevel),
forcePolyLine_ (false), forceCells_ (false)
{
// the rf needs to be lat/lon
// create lat/lon rf (may be NULL)
degRF_ = dynamic_cast<const DgGeoSphDegRF*>(&rfIn);
if (!degRF_) {
report("DgInLocTextFile::DgInLocTextFile(): RF " + rfIn.name() +
" is not longitude/latitude", DgBase::Fatal);
}

/* not needed since must be lat/lon
// test for override of vecAddress
DgAddressBase* dummy = rfIn.vecAddress(DgDVec2D(M_ZERO, M_ZERO));
if (!dummy) {
report("DgInLocTextFile::DgInLocTextFile(): RF " + rfIn.name() +
" must override the vecAddress() method", DgBase::Fatal);
}
delete dummy;
*/

} // DgInLocTextFile::DgInLocTextFile

Expand Down
Loading

0 comments on commit 5a5f1a6

Please sign in to comment.