Re: Summary (was Re: asserts and pagebreaks)

Subject: Re: Summary (was Re: asserts and pagebreaks)
From: Jesper Skov (
Date: Mon May 22 2000 - 16:59:10 CDT

>>>>> "Mike" == Mike Nordell <> writes:

Mike> Jesper Skov wrote:
>> Part of the problem is that Mike and myself don't quite understand
>> what's going on in that function. I read a bit more on it, and now
>> at least understand why the RUN_JUSTAFTER is necessary.

Mike> Please, share your insight on why is it needed. With my
Mike> ignorance I still think a method "isInside()" should be wnought,
Mike> so I'd really like to know _why_ this is needed.

isInside may do the trick, I don't know. Haven't looked at that yet.

[This is why I think it's necessary. May be wrong..]

But the JUSTAFTER is necessary (in the current implementation) to
catch the case (or cases like it):

 ..., Run n-2 (text), Run n-1 (text), Run n (pageBreak),
 Run 0 (text)

When scanning along the list, the function needs to return the coords
for Run n-1 in the above. That's now done by having a Run guess at if
the following Run is the last on the line/page - in which case we
terminate the search.

You suggested having a Run return either "inside" or "outside". That's
not quite enough, I think - and probably the reason for the current

I've been pondering a rewrite where the Runs return "inside" or
"I'm-past-the-point-you-are-looking-for". In the latter case, return
the previous (text) Run coords.

Now, it's basically the same semantics, but I like that approach
better because the loop can keep a variable with the last
known-to-be-valid-for-IP Run and return it if getting past the
position that is searched for.

In pseudo (python-like) syntax:

 lv = NULL # last valid entry
 p = head
 while p:
   iWhere = p->containsOffset
   if iWhere == INSIDE:
     return p
   if p->canContainPoint():
     lv = p
   if iWhere == PAST_POINT:
     if lv:
       # we have a valid last Run on the line. Depending on bEOL
       # decide whether to return lv or p coords
       # no valid Runs and we're past the point
       # terminate loop to magic loop/code below
   p = p->next

 # magic code that now lives below the first loop in the current
 # implementation

Also, I changed the code to print out exit point of the
function. Majority of calls return at 'return p' and 'if lv' in the
above. Probably obvious, but in the current implementation it means
that the block's list of Runs is iterated over in its entire length
twice at each call while you are typing (i.e., cursor at the end of a

Probably doesn't amount to much performance wise, but it'd be nice
with a clean and fast implementation since we're around here anyway :)

I'm pretty naggered and haven't actually looked at the code since
yesterday, so I may have missed something obvious.


This archive was generated by hypermail 2b25 : Mon May 22 2000 - 17:06:06 CDT