Closed mlptownsend closed 2 years ago
I think this is expected.
// Returns true if the region completely contains the given cell, otherwise
// either the region does not contain the cell or the containment relationship
// could not be determined.
virtual bool Contains(const S2Cell& cell) const = 0;
The cap will be tight to the corner of some cell, and containment won't be determinable due to numerical instability.
What's the S2ChordAngle
of each vertex vs the cap center vs the chord angle of the cap?
Yeah, you're right. It's throwing it out on the first vertex here.
3.9874261770344996 3.9874261770344992
It's just a floating point comparison doing what floating point comparisons do then :)
// Test GetCapBound().
S2Cap cap = cellunion.GetCapBound();
S2Point center = cap.center();
S2Point centerN = center.Normalize();
S1ChordAngle centerAngle = cap.radius();
char buf[200];
sprintf(buf, "Cap: %.17f / %.17f", i, centerAngle.radians(), centerAngle.length2());
puts(buf);
memset(buf, 0, 200);
for(int i = 0; i < input.size(); ++i) {
S2CellId c = input[i];
S2Point pc = c.ToPoint().Normalize();
S1ChordAngle vsCenter = S1ChordAngle(centerN, pc);
sprintf(buf, "V%i to Center: %.17f / %.17f", i, vsCenter.radians(), vsCenter.length2());
puts(buf);
memset(buf, 0, 200);
}
int j = 0;
for (S2CellId id : cellunion) {
S2Point pc = id.ToPoint().Normalize();
S1ChordAngle vsCenter = S1ChordAngle(centerN, pc);
sprintf(buf, "CU-V%i to Center: %.17f / %.17f", j++, vsCenter.radians(), vsCenter.length2());
puts(buf);
memset(buf, 0, 200);
EXPECT_TRUE(cap.Contains(S2Cell(id)));
}
Cap: 3.02940076358108490 / 3.98742617703449920
V0 to Center: 1.65004457710871555 / 2.15833065217771214
V1 to Center: 1.65004457710871555 / 2.15833065217771214
V2 to Center: 2.48244445722154428 / 3.58102839999664058
V3 to Center: 2.38355502666034313 / 3.45237307025370832
V4 to Center: 2.46511237321986565 / 3.55956214577003571
V5 to Center: 2.49691898001032797 / 3.59859182265260014
V6 to Center: 1.49154807648107801 / 1.84166934782228831
V7 to Center: 1.97582029277483429 / 2.78808157489446717
V8 to Center: 1.61375148565650628 / 2.08588390065200446
V9 to Center: 1.71782752487735846 / 2.29300402551243909
V10 to Center: 1.74908418543264177 / 2.35468966472460828
V11 to Center: 1.80730572343033846 / 2.46862125917851971
V12 to Center: 1.77805633212831760 / 2.41155864239179873
V13 to Center: 1.55677094755307266 / 1.97195016115732824
V14 to Center: 1.57259255779997487 / 2.00359246007834280
V15 to Center: 1.72370218603139924 / 2.30462145414183794
V16 to Center: 1.71526038248314472 / 2.28792417784496394
V17 to Center: 1.81935529331584345 / 2.49201493524619533
V18 to Center: 1.82846267105155436 / 2.50964926478571382
V19 to Center: 1.77162414590865458 / 2.39896116095157685
V20 to Center: 1.98229513488767850 / 2.79996693571606503
V21 to Center: 1.95436458746768915 / 2.74846363702268803
V22 to Center: 1.87317742760410821 / 2.59558823850561549
V23 to Center: 1.86249494934561266 / 2.57515901289319471
V24 to Center: 1.86395037577228018 / 2.57794629176132251
V25 to Center: 1.91445497573352763 / 2.67386812164724130
V26 to Center: 1.92430074130738826 / 2.69237529307332757
V27 to Center: 2.14823728819093684 / 3.09176320900185253
V28 to Center: 2.17870527130146785 / 3.14230455884868665
V29 to Center: 1.89329355565500546 / 2.63387207078301078
V30 to Center: 1.16308599361227838 / 1.20698323233063198
V31 to Center: 1.10028088631957144 / 1.09330844884037659
V32 to Center: 0.88547208090139673 / 0.73415183910062098
V33 to Center: 1.10028088631957144 / 1.09330844884037659
V34 to Center: 0.11219189000871095 / 0.01257382296550170
CU-V0 to Center: 1.65004457710871555 / 2.15833065217771214
CU-V1 to Center: 1.65004457710871555 / 2.15833065217771214
CU-V2 to Center: 2.48244445722154428 / 3.58102839999664058
CU-V3 to Center: 2.49691898001032797 / 3.59859182265260014
~/src/s2geometry/src/s2/s2cell_union_test.cc:234: Failure
Value of: cap.Contains(S2Cell(id))
Actual: false
Expected: true
CU-V4 to Center: 1.49154807648107801 / 1.84166934782228831
CU-V5 to Center: 1.49154807648107801 / 1.84166934782228831
CU-V6 to Center: 0.11219189000871095 / 0.01257382296550170
Just chalk it up to that, thanks!
I managed to come up with a test case for S2CellUnion.Normalize that fails. At least it fails in v.0.9.0, as I couldn't get the latest to build properly in either Windows or Ubuntu.
I found this by repeatedly running the unmodified Normalize over and over until it broke down. Then I extracted the input and expected values and placed them in the existing logic.