Loading ...
Sorry, an error occurred while loading the content.

How do you detect points on the map border?

Expand Messages
  • L. Lee Saunders
    Hello, When programming a drawing command or an entity altering command (like FPATH or FRX) how could you add the ability to detect if nodes or segments
    Message 1 of 2 , Feb 2 7:43 AM
    • 0 Attachment
      Hello,
       
      When programming a drawing command or an entity altering command (like FPATH or FRX) how could you add the ability to detect if nodes or segments between nodes are on the map border?
       
      Lee
    • Peter Olsson
      Here is the code used in CC2/CC3 drawtools to find the map border: //////////////////// Restrict to MAP BORDER //////////////////////////////////////// static
      Message 2 of 2 , Feb 2 1:37 PM
      • 0 Attachment

        Here is the code used in CC2/CC3 drawtools to find the map border:

         

        //////////////////// Restrict to MAP BORDER ////////////////////////////////////////

         

        static int MapBorderLayerID;

         

        void TestMapBorderLine(GLINE2 *Line,  GLINE2 *Limit, GPOINT2 *MidPt)

        {

          // TRUE if ”vertical” line on left or right side

          if((Line->p1.x<MidPt->x) ^ (Line->p2.x>MidPt->x))

          {

            // TRUE if both above and below the center

            if((Line->p1.y<MidPt->y) ^ (Line->p2.y<MidPt->y))

            {

              // Vänster sida och större än limit?

              if(Line->p1.x<MidPt->x && max(Line->p1.x, Line->p2.x)>Limit->p1.x)

                Limit->p1.x=max(Line->p1.x, Line->p2.x);

         

              // Höger sida och mindre än limit?

              if(Line->p1.x>MidPt->x && min(Line->p1.x, Line->p2.x)<Limit->p2.x)

                Limit->p2.x=min(Line->p1.x, Line->p2.x);

            }

          }

         

          // TRUE if ”horizontal” line above or below center

          if((Line->p1.y<MidPt->y) ^ (Line->p2.y>MidPt->y))

          {

            // TRUE if both on left and right side

            if((Line->p1.x<MidPt->x) ^ (Line->p2.x<MidPt->x))

            {

              // Under och större än limit?

              if(Line->p1.y<MidPt->y && max(Line->p1.y, Line->p2.y)>Limit->p1.y)

                Limit->p1.y=max(Line->p1.y, Line->p2.y);

         

              // Över och mindre än limit?

              if(Line->p1.y>MidPt->y && min(Line->p1.y, Line->p2.y)<Limit->p2.y)

                Limit->p2.y=min(Line->p1.y, Line->p2.y);

            }

          }

        }

         

         

        DWORD XPCALL FindMapBorders(hDLIST hDList, pENTREC pEntRec, GLINE2 *Limit, GPOINT2 *MidPt)

        {

          GLINE2 Line;

          int i;

         

          if(pEntRec->CStuff.ELayer==MapBorderLayerID)

            switch(pEntRec->CStuff.EType)

            {

              case ET_PATH2:

                if(pEntRec->Path.Path.SmType==SM_NO)

                {

                  i=(pEntRec->Path.Path.Flags & NL_CLS) ? pEntRec->Path.Path.Count-1 : 0;

                  Line.p1=pEntRec->Path.Path.Nodes[i];

                  for(i=(i+1)%pEntRec->Path.Path.Count; i<pEntRec->Path.Path.Count; i++)

                  {

                    Line.p2=pEntRec->Path.Path.Nodes[i];

                    TestMapBorderLine(&Line, Limit, MidPt);

                    Line.p1=Line.p2;

                  }

                }

                break;

         

              case ET_LINE2:

                TestMapBorderLine(&pEntRec->Line.Line, Limit, MidPt);

                break;

            }

          return 0;

        }

         

        DWORD XPCALL ExtentsOnLayer(hDLIST hDList, pENTREC pEntRec, PARM parm1, BOOL *Found)

        {

          if(pEntRec->CStuff.ELayer==MapBorderLayerID)

          {

            EXCheck(pEntRec);

            *Found=TRUE;

          }

         

          return 0;

        }

         

        BOOL FigureOutMapBorderLimit(GLINE2 *Limit)

        {

          BOOL ThereIsABorder=FALSE;

          GLINE3 Ext;

          GPOINT2 MidPt;

         

          MapBorderLayerID=GetLayerNr(BORDER_LAYER);

         

          BgnPExtents();

          DLScan(NULL, ExtentsOnLayer, DLS_UNLK, NULL, &ThereIsABorder);

          EndPExtents(&Ext);

         

          if(!ThereIsABorder)

            return FALSE;

         

          Limit->p1=*(GPOINT2 *)&Ext.p1;

          Limit->p2=*(GPOINT2 *)&Ext.p2;

         

          MidPt.x=(Ext.p1.x+Ext.p2.x)/2;

          MidPt.y=(Ext.p1.y+Ext.p2.y)/2;

         

          DLScan(NULL, FindMapBorders, DLS_UNLK, Limit, &MidPt);

         

          return TRUE;

        }

         

         

        To limit a point to be in the area:

         

        int RestrictPointToBox(GPOINT2 *Pt, GLINE2 *Limit)

        {

          int Restricted=0;

         

          if(Pt->x<Limit->p1.x)

          {

            Pt->x=Limit->p1.x;

            Restricted|=1;

          }

          if(Pt->y<Limit->p1.y)

          {

            Pt->y=Limit->p1.y;

            Restricted|=2;

          }

          if(Pt->x>Limit->p2.x)

          {

            Pt->x=Limit->p2.x;

            Restricted|=4;

          }

          if(Pt->y>Limit->p2.y)

          {

            Pt->y=Limit->p2.y;

            Restricted|=8;

          }

         

          return Restricted;

        }

         


        From: cc2-dev-l@yahoogroups.com [mailto:cc2-dev-l@yahoogroups.com] On Behalf Of L. Lee Saunders
        Sent: Thursday, February 02, 2006 4:43 PM
        To: cc2-dev-l@yahoogroups.com
        Subject: [cc2-dev-l] How do you detect points on the map border?

         

        Hello,

         

        When programming a drawing command or an entity altering command (like FPATH or FRX) how could you add the ability to detect if nodes or segments between nodes are on the map border?

         

        Lee


      Your message has been successfully submitted and would be delivered to recipients shortly.