Skip to content

Optimize S2Cell::GetDistance #467

@jmr

Description

@jmr

@ericveach Do you remember what you had in mind with

This could be optimized to be at least 5x faster by pruning the set of possible closest vertex/edge pairs using the faces and (u,v) ranges of both cells.

?

s2geometry/src/s2/s2cell.cc

Lines 508 to 526 in a538e02

// Otherwise, the minimum distance always occurs between a vertex of one
// cell and an edge of the other cell (including the edge endpoints). This
// represents a total of 32 possible (vertex, edge) pairs.
//
// TODO(ericv): This could be optimized to be at least 5x faster by pruning
// the set of possible closest vertex/edge pairs using the faces and (u,v)
// ranges of both cells.
S2Point va[4], vb[4];
for (int i = 0; i < 4; ++i) {
va[i] = GetVertex(i);
vb[i] = target.GetVertex(i);
}
S1ChordAngle min_dist = S1ChordAngle::Infinity();
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
S2::UpdateMinDistance(va[i], vb[j], vb[(j + 1) & 3], &min_dist);
S2::UpdateMinDistance(vb[i], va[j], va[(j + 1) & 3], &min_dist);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions