[Baypiggies] Hi all -can anyone convert this code to python---many thanks

Russell Whitaker whitaker at google.com
Thu Dec 14 22:33:23 CET 2006


On 12/14/06, Mike Cheponis <mac at wireless.com> wrote:
> As I see it, the correct answer is to wrap this C function so it's callable from Python.
>
> That way, no recoding, maximum performance.
>
> -Mike
>
>
> p.s. I'll send a bill later.  You gotta know exactly where to tap the hammer...
>

Charles Proteus Steinmetz!  A classic piece of engineering lore:

http://en.wikipedia.org/wiki/Steinmetz%2C_Charles_Proteus

:)

Russell

>
>
> On Thu, 14 Dec 2006, Sharon Kazemi wrote:
>
> > Date: Thu, 14 Dec 2006 10:16:31 -0800
> > From: Sharon Kazemi <sharonk at gisc.berkeley.edu>
> > To: baypiggies at python.org
> > Subject: [Baypiggies] Hi all -can anyone convert this code to python---many
> >     thanks
> >
> > Hi all,
> >
> > have below code that needs to be recoded into Python for use in ESRI ArcGIS
> > software.
> > I would greatly appreciate any assistance.
> > Thanks
> > Sheri
> >
> > /*  The Inner Loop of the Douglas-Peucker line generalization
> > algorithm is the process of finding, for a section of a polyline,
> > the vertex that is furthest from the line segment joining the
> > two endpoints.  The method coded below in C (or C++) is the most
> > efficient, in terms of operation counts, that I have seen.  */
> > /*  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  */
> >
> > long FurthestFromSegment ( /* Return index of furthest point.  */
> >    long    startindex,    /* Index of start vertex in arrays.  */
> >    long    endindex,      /* Index of end vertex in arrays.  */
> >    double *x         ,    /* Array, abscissae of polyline vertices. */
> >    double *y         ,    /* Array, ordinates of polyline vertices. */
> >    double *distMaxSquare  /* Return square of maximum distance.  */
> >                         )
> >  /*
> >   This function, given a section of a polyline in arrays,
> >    will return the index of the intermediate node that is furthest
> >    from the segment joining the two endpoints of the section,
> >    and the square of the distance from the segment.
> >
> >   If no intermediate point exists, then the returned index will
> >    be the index of the start vertex and the returned distance
> >    squared will be -1.0 .  Caution:  Do not calculate the square
> >    root of this returned value without ruling out the possibility
> >    that it may have defaulted to -1.0 .  In a normal
> >    Douglas-Peucker application, you should never have to calculate
> >    the square root of this output value, and you should never
> >    need to invoke this function without intermediate points.
> >  */
> > {
> >      /*
> >       The variable names below assume we find
> >         the distance of point "A" from segment "BC" .
> >      */
> >    long index, outindex ;
> >    double distSquare, bcSquare ;
> >    double cx, cy, bx, by, ax, ay ;
> >    double bcx, bcy, bax, bay, cax, cay ;
> >
> >    *distMaxSquare  =  -1.0 ;
> >    if ( endindex  <  startindex + 2 )    return startindex ;
> >    outindex  =  startindex ;
> >    bx  =  x[startindex] ;
> >    by  =  y[startindex] ;
> >    cx  =  x[endindex] ;
> >    cy  =  y[endindex] ;
> >      /* Find vector BC and the Square of its length.  */
> >    bcx  =  cx - bx ;
> >    bcy  =  cy - by ;
> >    bcSquare  =  bcx * bcx  +  bcy * bcy ;
> >      /* The inner loop:  */
> >    for ( index = startindex + 1 ; index < endindex ; index++ )
> >    {
> >          /* Find vector BA .  */
> >        ax  =  x[index] ;
> >        ay  =  y[index] ;
> >        bax  =  ax - bx ;
> >        bay  =  ay - by ;
> >          /* Do scalar product and check sign.  */
> >        if ( bcx * bax  +  bcy * bay    <=    0.0 )
> >        {
> >              /* Closest point on segment is B; */
> >              /*   find its distance (squared) from A .  */
> >            distSquare   =   bax * bax  +  bay * bay ;
> >        }
> >        else
> >        {
> >              /* Find vector CA .  */
> >            cax  =  ax - cx ;
> >            cay  =  ay - cy ;
> >              /* Do scalar product and check sign.  */
> >            if ( bcx * cax  +  bcy * cay    >=    0.0 )
> >            {
> >                  /* Closest point on segment is C; */
> >                  /*   find its distance (squared) from A .  */
> >                distSquare   =   cax * cax  +  cay * cay ;
> >            }
> >            else
> >            {
> >                  /* Closest point on segment is between B and C; */
> >                  /*    Use perpendicular distance formula.  */
> >                distSquare    =    cax * bay  -  cay * bax ;
> >                distSquare    =    distSquare * distSquare / bcSquare ;
> >                      /* Note that if bcSquare be zero, the first
> >                          of the three branches will be selected,
> >                          so division by zero will not occur here. */
> >            }
> >        }
> >
> >        if ( distSquare > *distMaxSquare )
> >        {
> >            outindex  =  index ;
> >            *distMaxSquare  =  distSquare ;
> >        }
> >    }
> >      /*
> >         Note that in the inner loop above, if we follow
> >         the most common path where the perpendicular
> >         distance is the one to calculate, then for each
> >         intermediate vertex the float operation count is
> >         1 divide, 7 multiplies, 5 subtracts, 1 add, and 2 compares.
> >      */
> >
> >    return outindex ;
> > }
> >
> > Sharon Kazemi
> > Visiting Scholar/GIS Analyst
> > Geographic Information Science Center
> > 412 Wurster Hall
> > University of California Berkeley
> > Berkeley, CA 94720-1820
> > Phone: +1-510-642-2812
> > Fax: +1-510-643-3412
> > Email: sharonk at gisc.berkeley.edu
> > http://www.gisc.berkeley.edu/
> >
> >
> >
> > -----Original Message-----
> > From: baypiggies-bounces at python.org
> > [mailto:baypiggies-bounces at python.org]On Behalf Of
> > baypiggies-request at python.org
> > Sent: Thursday, December 14, 2006 3:00 AM
> > To: baypiggies at python.org
> > Subject: Baypiggies Digest, Vol 14, Issue 16
> >
> >
> > Send Baypiggies mailing list submissions to
> >       baypiggies at python.org
> >
> > To subscribe or unsubscribe via the World Wide Web, visit
> >       http://mail.python.org/mailman/listinfo/baypiggies
> > or, via email, send a message with subject or body 'help' to
> >       baypiggies-request at python.org
> >
> > You can reach the person managing the list at
> >       baypiggies-owner at python.org
> >
> > When replying, please edit your Subject line so it is more specific
> > than "Re: Contents of Baypiggies digest..."
> >
> >
> > Today's Topics:
> >
> >   1. Re:  Dec. 14 Meeting "Programming Productivity: What     Really
> >      Matters?" (Anna Ravenscroft)
> >   2. Re:  Dec. 14 Meeting "Programming Productivity: What     Really
> >      Matters?" (Shannon -jj Behrens)
> >   3. Re:  Dec. 14 Meeting "Programming Productivity: What Really
> >      Matters?" (Dennis Reinhardt)
> >   4. Re:  Dec. 14 Meeting "Programming Productivity: What     Really
> >      Matters?" (Anna Ravenscroft)
> >   5. Re:  Dec. 14 Meeting "Programming Productivity: What     Really
> >      Matters?" (Marilyn Davis)
> >   6. Re:  Dec. 14 Meeting "Programming Productivity: What     Really
> >      Matters?" (Anna Ravenscroft)
> >   7. Re:  Dec. 14 Meeting "Programming Productivity: What     Really
> >      Matters?" (Alex Martelli)
> >
> >
> > ----------------------------------------------------------------------
> >
> > Message: 1
> > Date: Wed, 13 Dec 2006 17:22:03 -0800
> > From: "Anna Ravenscroft" <annaraven at gmail.com>
> > Subject: Re: [Baypiggies] Dec. 14 Meeting "Programming Productivity:
> >       What    Really Matters?"
> > To: "Mike Cheponis" <mac at wireless.com>
> > Cc: Python <baypiggies at python.org>
> > Message-ID:
> >       <cb361a610612131722v7c6fef90ha4504a604b9b5246 at mail.gmail.com>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> >
> > On 12/13/06, Mike Cheponis <mac at wireless.com> wrote:
> >> "Social Time" is really just "Random Mapping".
> >>
> >> So, if nobody stands up during "Mapping" you get all "Social Time".  Also,
> > those that don't "map" are, by default, in the "Social" mapping...
> >>
> >> Don't worry, the meetings aren't nearly as formal as our discussions
> > _about_ the meetings are(!).
> >>
> >> -Mike
> >
> > I've been to the meetings. Social TIme != mapping.
> >
> > I don't have time or energy to wait for the formal "mapping" to get
> > over with before I can socialize with people. I have a final tomorrow
> > and expect to be pretty exhausted and wanting to go to bed early. I
> > was looking forward to some generic, informal socializing.
> >
> > OR can we have some freeform socializing BEFORE the official part of
> > the meeting - that way those who want (and have the energy) to do the
> > mapping can stay for that?
> >
> > Anna
> >
> >
> > ------------------------------
> >
> > Message: 2
> > Date: Wed, 13 Dec 2006 18:09:35 -0800
> > From: "Shannon -jj Behrens" <jjinux at gmail.com>
> > Subject: Re: [Baypiggies] Dec. 14 Meeting "Programming Productivity:
> >       What    Really Matters?"
> > To: "Anna Ravenscroft" <annaraven at gmail.com>
> > Cc: Python <baypiggies at python.org>, Mike Cheponis <mac at wireless.com>
> > Message-ID:
> >       <c41f67b90612131809q37612254i1007ffe3e5fb7667 at mail.gmail.com>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> >
> > On 12/13/06, Anna Ravenscroft <annaraven at gmail.com> wrote:
> >> On 12/13/06, Mike Cheponis <mac at wireless.com> wrote:
> >>> "Social Time" is really just "Random Mapping".
> >>>
> >>> So, if nobody stands up during "Mapping" you get all "Social Time".
> > Also, those that don't "map" are, by default, in the "Social" mapping...
> >>>
> >>> Don't worry, the meetings aren't nearly as formal as our discussions
> > _about_ the meetings are(!).
> >>>
> >>> -Mike
> >>
> >> I've been to the meetings. Social TIme != mapping.
> >>
> >> I don't have time or energy to wait for the formal "mapping" to get
> >> over with before I can socialize with people. I have a final tomorrow
> >> and expect to be pretty exhausted and wanting to go to bed early. I
> >> was looking forward to some generic, informal socializing.
> >>
> >> OR can we have some freeform socializing BEFORE the official part of
> >> the meeting - that way those who want (and have the energy) to do the
> >> mapping can stay for that?
> >
> > It sounds like we have a pretty vocal contingent of people who want 30
> > minutes of informal socializing followed by an hour for the actual
> > talk.  That's fine by me.
> >
> > -jj
> >
> > --
> > http://jjinux.blogspot.com/
> >
> >
> > ------------------------------
> >
> > Message: 3
> > Date: Wed, 13 Dec 2006 18:17:51 -0800
> > From: Dennis Reinhardt <DennisR at dair.com>
> > Subject: Re: [Baypiggies] Dec. 14 Meeting "Programming Productivity:
> >       What Really Matters?"
> > To: Python <baypiggies at python.org>
> > Message-ID: <5.1.0.14.0.20061213173953.023a51d0 at localhost>
> > Content-Type: text/plain; charset="us-ascii"; format=flowed
> >
> > At 05:22 PM 12/13/2006, Anna Ravenscroft wrote:
> >
> >> OR can we have some freeform socializing BEFORE the official part of
> >> the meeting -
> >
> > Anna,
> >
> > I have regularly attended the pre-dinner meetings Brian has organized (at
> > least the ones at IronPort).  They may well be the social time you are
> > looking for and in the time frame you ask for.
> >
> > If one looks at the agenda template we have had this year, it looks like:
> >
> >         7:00 - 7:30 unstructured pre-meeting
> >         7:30 - 9:00 meeting program
> >
> > Nothing has prevented people from socializing in the 7:00 - 7:30
> > pre-meeting time frame.  By my observation, not that much socialization
> > gets done then.  Whatever limiters there are in socializing in the 7:00 to
> > 7:30 time frame are likely to affect tomorrow's meeting as well.  Suppose
> > we revise the schedule to read
> >
> >         7:00 - x:yz social
> >         x:yz - 9:00 program
> >
> > I don't think moving the 7:00 earlier is that easy without checking the
> > room schedule or someone from Google taking responsibility for being
> > there.  Could happen but the fact is that we already have an time preceding
> > every meeting where completely unstructured socialization is possible.
> >
> > Suppose we set x:yz to 7:40, allowing JJ's presentation to take the entire
> > 80 minutes.  IMO, we have run that experiment as well and it is called
> > starting the meeting 10 minutes late.  I have not seen the demand for that.
> >
> > The major alternative here is set x:yz to 9:00 and shut down JJ's talk
> > entirely.  My sense is that JJ has a great talk planned and while meet and
> > greet was preferred to no meeting at all, JJ's unabridged talk and
> > free-for-all discussion (i.e. what passes for socialization for some of us)
> > is a preferred use of the time available.
> >
> > If you have not attended the pre-meeting dinners, I can recommend them as a
> > good way to socialize.
> >
> > Dennis
> >
> >
> >  ---------------------------------
> > | Dennis    | DennisR at dair.com    |
> > | Reinhardt | http://www.dair.com |
> >  ---------------------------------
> >
> >
> >
> > ------------------------------
> >
> > Message: 4
> > Date: Wed, 13 Dec 2006 18:57:16 -0800
> > From: "Anna Ravenscroft" <annaraven at gmail.com>
> > Subject: Re: [Baypiggies] Dec. 14 Meeting "Programming Productivity:
> >       What    Really Matters?"
> > To: "Dennis Reinhardt" <DennisR at dair.com>
> > Cc: Python <baypiggies at python.org>
> > Message-ID:
> >       <cb361a610612131857r7a3a18c5u20344f1f13398cb7 at mail.gmail.com>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> >
> > Okay - let me describe what I mean by "socializing".
> >
> > To me, socializing is not:
> >
> > "mapping" (mapping is a formal structure grouping up people and the
> > grouping process seems to take forever.)
> >
> > dinner (getting stuck next to someone I've never met and have nothing
> > in common with and having to make smalltalk with them for the next
> > hour is my idea of hell.)
> >
> > extending the Q&A session after a presentation - leaving those of us
> > who have heard enough stuck with the choice of being *rude* or waiting
> > patiently in hopes that eventually we can stand up and go talk to
> > someone we have been wanting to talk with - which usually happens
> > about 5 minutes before we're kicked out of the room...
> >
> > Milling around in the lobby of google waiting to fill out a badge and
> > be shepherded up to a room just in time for the presentation to start.
> > Not everyone is there, and we're usually rather distracted.
> >
> > Socializing - what I'm asking for - is a chance to talk to people, _by
> > choice_ -- not by enforced proximity or structured format -- including
> > the chance to walk around and talk to more than one person. Having
> > snacks and beverages is nice.
> >
> > I would like a chance to socialize.
> >
> > Cordially,
> > Anna
> >
> >
> > ------------------------------
> >
> > Message: 5
> > Date: Wed, 13 Dec 2006 21:56:50 -0800
> > From: Marilyn Davis <marilyn at deliberate.com>
> > Subject: Re: [Baypiggies] Dec. 14 Meeting "Programming Productivity:
> >       What    Really Matters?"
> > To: baypiggies at python.org
> > Message-ID: <20061214055653.9296D1E4006 at bag.python.org>
> > Content-Type: text/plain; charset="ISO-8859-1"
> >
> >
> > ----- On Wednesday, December 13, 2006 annaraven at gmail.com wrote:
> >
> >> Okay - let me describe what I mean by "socializing".
> >>
> >> To me, socializing is not:
> >>
> >> "mapping" (mapping is a formal structure grouping up people and the
> >> grouping process seems to take forever.)
> >>
> >> dinner (getting stuck next to someone I've never met and have nothing
> >> in common with and having to make smalltalk with them for the next
> >> hour is my idea of hell.)
> >>
> >> extending the Q&A session after a presentation - leaving those of us
> >> who have heard enough stuck with the choice of being *rude* or waiting
> >> patiently in hopes that eventually we can stand up and go talk to
> >> someone we have been wanting to talk with - which usually happens
> >> about 5 minutes before we're kicked out of the room...
> >>
> >> Milling around in the lobby of google waiting to fill out a badge and
> >> be shepherded up to a room just in time for the presentation to start.
> >> Not everyone is there, and we're usually rather distracted.
> >
> > Yeh.  We are not allowed in early, as far as I know.  The lobby is not the
> > right thing.  We're not there yet.
> >
> > Google is providing snacks?  How do the snacks get snacked upon if the
> > program starts when people first arrive?
> >
> > So far, it seems to me, this little disagreement we are having is divided
> > against the gender axis.  Just commenting, I don't have any judgement or
> > conclusion about it, I just find it interesting.
> >
> > I'm looking forward to whatever part I'm able to get to.
> >
> > Marilyn
> >
> >>
> >> Socializing - what I'm asking for - is a chance to talk to people, _by
> >> choice_ -- not by enforced proximity or structured format -- including
> >> the chance to walk around and talk to more than one person. Having
> >> snacks and beverages is nice.
> >>
> >> I would like a chance to socialize.
> >>
> >> Cordially,
> >> Anna
> >> _______________________________________________
> >> Baypiggies mailing list
> >> Baypiggies at python.org
> >> http://mail.python.org/mailman/listinfo/baypiggies
> >
> >
> >
> >
> > ------------------------------
> >
> > Message: 6
> > Date: Wed, 13 Dec 2006 22:06:25 -0800
> > From: "Anna Ravenscroft" <annaraven at gmail.com>
> > Subject: Re: [Baypiggies] Dec. 14 Meeting "Programming Productivity:
> >       What    Really Matters?"
> > To: "Marilyn Davis" <marilyn at deliberate.com>
> > Cc: baypiggies at python.org
> > Message-ID:
> >       <cb361a610612132206i163aad6frfebd13274094cdac at mail.gmail.com>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> >
> > On 12/13/06, Marilyn Davis <marilyn at deliberate.com> wrote:
> >>
> >> ----- On Wednesday, December 13, 2006 annaraven at gmail.com wrote:
> >>
> >> Yeh.  We are not allowed in early, as far as I know.  The lobby is not the
> > right thing.  We're not there yet.
> >>
> >> Google is providing snacks?  How do the snacks get snacked upon if the
> > program starts when people first arrive?
> >>
> >> So far, it seems to me, this little disagreement we are having is divided
> > against the gender axis.  Just commenting, I don't have any judgement or
> > conclusion about it, I just find it interesting.
> >>
> >
> > The main disagreement I really see is a different definition of
> > socializing. Which is why I posted my definition so we could have the
> > discussion be more clear. Some people apparently consider the lobby
> > milling or the mapping to be socializing. That's okay for them to have
> > that definition - but it's not what I was asking for when I asked for
> > a chance to socialize, and so I figured it would be easier to discuss
> > if we had a definition on the table. (whether for people to agree or
> > disagree with - at least we're not assuming what it means.) Once we
> > agree on what it means to "socialize" we can agree on whether we want
> > a socializing time.
> >
> >> I'm looking forward to whatever part I'm able to get to.
> >
> > Me too. I'm sure the presentation will be great. I hope I get a chance
> > to chat with you. I haven't had much opportunity for that.
> >
> > --
> > cordially,
> > Anna
> > --
> > It is fate, but call it Italy if it pleases you, Vicar!
> >
> >
> > ------------------------------
> >
> > Message: 7
> > Date: Wed, 13 Dec 2006 22:54:46 -0800
> > From: "Alex Martelli" <aleax at google.com>
> > Subject: Re: [Baypiggies] Dec. 14 Meeting "Programming Productivity:
> >       What    Really Matters?"
> > To: "Marilyn Davis" <marilyn at deliberate.com>
> > Cc: baypiggies at python.org
> > Message-ID:
> >       <55dc209b0612132254y6ea79c01h257c2d515fbe6fd6 at mail.gmail.com>
> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> >
> > On 12/13/06, Marilyn Davis <marilyn at deliberate.com> wrote:
> >   ...
> >> So far, it seems to me, this little disagreement we are having is divided
> > against the gender axis.  Just commenting, I don't have any judgement or
> > conclusion about it, I just find it interesting.
> >
> > OK, so let me weigh in...: I _know_ I'm going to be seriously tired
> > tomorrow night, except (perhaps, with some luck:-) very early on, as
> > I'm going to have a long and intense workday before it; so, from my
> > subjective POV the tradeoff is -- am I going to be dozing at the end
> > of the presentation (if we have socialtime _before_), or am I going to
> > be dozing through socialtime (if we have it _after_).  Overall, I'd
> > (marginally) prefer the first option.
> >
> > Sorry to spoil the nice gender-axis alignment, but then, I tend to do
> > that (I guess that, according to our great State's great governor,
> > this makes me a "girlyman":-).
> >
> >
> >> I'm looking forward to whatever part I'm able to get to.
> >
> > Likewise, except s/get to/be awake for/ :-).
> >
> >
> > Alex
> >
> >
> > ------------------------------
> >
> > _______________________________________________
> > Baypiggies mailing list
> > Baypiggies at python.org
> > http://mail.python.org/mailman/listinfo/baypiggies
> >
> >
> > End of Baypiggies Digest, Vol 14, Issue 16
> > ******************************************
> >
> >
> >
> > _______________________________________________
> > Baypiggies mailing list
> > Baypiggies at python.org
> > http://mail.python.org/mailman/listinfo/baypiggies
> >
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> http://mail.python.org/mailman/listinfo/baypiggies
>


-- 
Russell Whitaker
Sysops Tools Team Lead
http://www.corp.google.com/~whitaker/
"From the point of view of any orthodoxy, myth might be defined as
'other people's
religion'... to which an equivalent definition of religion might be
'misunderstood mythology'."
- Joseph Campbell, "The Hero with a Thousand Faces"


More information about the Baypiggies mailing list