*/
public double activate(Region viewport) {
PagingDebugHelper.maybeCheckBlocks(root);
PagingDebugHelper.enterActivate();
Point toPreserve; // A point whose location should be preserved through paging.
Region active = getActiveRegion();
if (active == null) {
// Initialize
Point init = Traverser.locateStartWithin(root, viewport.getStart());
if (init == null) {
init = Traverser.locateEndWithin(root, viewport.getStart());
}
init(init);
expandTo(viewport);
// Preserve the start of the viewport. No particular reason.
toPreserve = start;
} else {
// Adjust from previous state.
switch (OverlapKind.compare(viewport, active)) {
case FULLY_AFTER:
Point newStart = Traverser.locateStartAfter(end, viewport.getStart());
shrinkToEnd();
moveActivePoint(newStart);
expandTo(viewport);
toPreserve = start;
break;
case FULLY_BEFORE:
Point newEnd = Traverser.locateEndBefore(start, viewport.getEnd());
shrinkToStart();
moveActivePoint(newEnd);
expandTo(viewport);
toPreserve = end;
break;