Exemple #1
0
/***********************************************************************
  findcrossing-- decides which edge exit point from cell is on and changes
  value of edge. 
  Returns 1 if only 2 crossings found ( don't want to check this Cell again);
  0 otherwise.
****************************************************************************/
static int findcrossing(struct cell *current, double level,
			struct Cell_head Cell, struct line_pnts *Points,
			int *ncrossing)
{
    int i, j;
    int numcross;		/* number of crossings found in this Cell */
    int edgehit[4];		/* hit flag for each edge of Cell */
    int cellhit = 0;
    double mid;

    numcross = 0;
    for (i = 0; i < 4; i++) {
	edgehit[i] = 0;
	edgehit[i] = checkedge(current->z[i], current->z[(i + 1) % 4], level);
	if (edgehit[i])
	    numcross++;
    }
    if (numcross == 2) {
	cellhit = 1;
	edgehit[current->edge] = 0;
	for (j = 0; j < 4; j++) {
	    if (edgehit[j]) {
		current->edge = j;
		getpoint(current, level, Cell, Points);
		break;
	    }
	}
    }
    else if (numcross == 4) {
	if (current->edge == 0)
	    cellhit = 1;

	mid =
	    (current->z[0] + current->z[1] + current->z[2] +
	     current->z[3]) / 4;
	if (checkedge(mid, current->z[current->edge], level))
	    current->edge = (current->edge == 0) ? 3 : current->edge - 1;
	else
	    current->edge = (current->edge == 3) ? 0 : current->edge + 1;
	getpoint(current, level, Cell, Points);

	if (current->edge == 0)
	    cellhit = 1;

    }
    else {
	if (1 == numcross) {
	    G_debug(1, "%d crossings in cell %d, %d",
		    numcross, current->r, current->c);
	    (*ncrossing)++;
	}

	cellhit = 1;
    }
    return cellhit;
}
Exemple #2
0
/*
 * Handle a mill by dealing with the removal of an opponent's piece.
 * Prompts the user for a piece to remove, checks its legality, and
 * removes it. Return the removed piece, recursing until a piece is
 * removed.
 */
point *
mill_handler(scrgame *sg, char *move, int count)
{
  point *p = NULL;

  if (count == 0) {
    update_msgbox(sg->msg_w,
		  "You've formed a mill, enter opponent piece to remove.");
  }
  getmove(sg, move, 3);
  if ((p = getpoint(sg->game, move))) {
    if (p->v != statechar(sg->game) && p->v != EMPTY) {
      if (inmill(p)) {
	/* We can only break an opponent's mill if there are no other
	   pieces to remove. We could keep a list of each player's
	   pieces, but this implies the headache of always updating
	   it. Alternatively, we can just iterate through at most 21
	   points, until we find an opponent piece not in a mill, or
	   nothing. */
	int r = 0;
	int c = 0;
	int opp = 0;
	if (sg->game->state == WHITE) {
	  opp = BLACKC;
	} else {
	  opp = WHITEC;
	}
	for (r = 0; r < 3; r++) {
	  for (c = 0; c < 7; c++) {
	    if (sg->game->board[r][c]->v == opp && !inmill(sg->game->board[r][c])) {
	      update_msgbox(sg->msg_w,
			    "It is possible to remove a piece not in a mill; do so.");
	      return mill_handler(sg, move, 1);
	    }
	  }
	}
	/* By this point, we've iterated through all of the opponent's
	   pieces without encountering one not in a mill. Allow the
	   desired piece to be removed. */
      }
      p->v = EMPTY;
      /* Decrement the opponent's pieces */
      sg->game->pieces[sg->game->state ^ BLACK]--;
      return p;
    } else if (p->v == EMPTY) {
      update_msgbox(sg->msg_w,
		    "You tried clearing an empty position. Please try again.");
      return mill_handler(sg, move, 1);
    } else {
      update_msgbox(sg->msg_w,
		    "You tried removing your own piece. Please try again.");
      return mill_handler(sg, move, 1);
    }
  } else {
    update_msgbox(sg->msg_w, "Invalid coordinates. Please try again.");
    return mill_handler(sg, move, 1);
  }
}
Exemple #3
0
void get_file(void) {
  int i,x,y,no_p;
  
  Splaytree=init();
  fscanf(stdin,"%d",&no_p);
  for (i=1; i<=no_p; i++) {
    fscanf(stdin,"%d %d\n",&x,&y);
    getpoint(x,y);
  }
}
Exemple #4
0
/*
 * Move point p to the given position
 */
point *
jumppiece(point *p, game *g, const char *position)
{
  point *ptr = getpoint(g, position);
  if (ptr && ptr->v == EMPTY) {
    ptr->v = p->v;
    p->v = EMPTY;
    return ptr;
  }
  return NULL;
}
Exemple #5
0
void TOGLImage::show()
{
	GLubyte *data;
	data = (GLubyte*)malloc(sizeof(GLubyte)*(w*h));

	int i = 0;
	for(int y=1;y<=h;y++)
		for(int x=1;x<=w;x++,i++)
			data[i]=(int)(getpoint(x,h-y+1)*255/max);

	glRasterPos2f(-w/2,-h/2);
	glDrawPixels(w, h, GL_LUMINANCE, GL_UNSIGNED_BYTE, data);
}
Exemple #6
0
/*
 * Phases two and three of the game
 */
point *
phasetwothree(scrgame *sg)
{
  point *p = NULL;
  char coords[6];
  while (sg->game->pieces[WHITE] >= 3 && sg->game->pieces[BLACK] >= 3) {
    if (sg->game->pieces[sg->game->state] > 3 && surrounded(sg->game)) {
      update_scorebox(sg->score_w, sg->game);
      update_board(sg->board_w, sg->game);
      return NULL;
    }
    getmove(sg, coords, 0);
    if (!(p = getpoint(sg->game, coords))) {
      update_msgbox(sg->msg_w, "Something went wrong...");
      continue;
    }
    if (p->v != statechar(sg->game)) {
      update_msgbox(sg->msg_w, "Please move your own piece.");
      continue;
    }
    if (sg->game->pieces[sg->game->state] == 3) {
      if (!(p = jumppiece(p, sg->game, &coords[2]))) {
	update_msgbox(sg->msg_w,
		      "That location is already occupied. Please try again");
	continue;
      }
    } else if (!(p = movepiece(p, &coords[2]))) {
      update_msgbox(sg->msg_w,
		    "That location is already occupied. Please try again");
      continue;
    }
    if (inmill(p)) {
      /* We should redraw the board now so that the player can see the
	 piece he just played */
      update_scorebox(sg->score_w, sg->game);
      update_board(sg->board_w, sg->game);
      update_msgbox(sg->msg_w, "");
      mill_handler(sg, coords, 0);
    }
    sg->game->state ^= BLACK;
    if (sg->game->pieces[BLACK] == 3 || sg->game->pieces[WHITE] == 3) {
      sg->game->phase = 3;
    }
    update_scorebox(sg->score_w, sg->game);
    update_board(sg->board_w, sg->game);
    update_msgbox(sg->msg_w, "");
  }
  return p;
}
Exemple #7
0
/*
 * Place a piece corresponding to the current player at the coordinates coords.
 */
point *
placepiece(const scrgame *sg, const char *coords)
{
  point *p = NULL;
  if ((p = getpoint(sg->game, coords))) {
    if (p->v == EMPTY) {
      p->v = statechar(sg->game);
      return p;
    } else {
      update_msgbox(sg->msg_w, "That location is already occupied, please try again.");
      return NULL;
    }
  } else {
    update_msgbox(sg->msg_w, "Invalid coordinates. Please try again.");
    return NULL;
  }
}
Exemple #8
0
void GameMain::main()
{
	getTime();

	jump();

	mapScroll();

	playerDrop();

	movingRange();

	if (!m_gameStartFlg && !doCountdown(START_TIME))return;
	else if (!m_gameStartFlg && doCountdown(START_TIME))m_gameStartFlg = true;

	createMarioLove();

	marioLoveMove();

	deleteMarioLove();

	getpoint();
}
Exemple #9
0
int main(void)
{
	struct point p1, p2;
	struct rect r;
	int value[4]; /* 一个矩形需要两个点,两个坐标决定一个点,共4个坐标 */
	int i, type;
	char s[MAXSIZE];

	i = 0;
	while ((type = getpoint(s)) != EOF) {
		if (type == NUMBER)
			value[i++] = aToi(s);
		if (i == 4) {
			i = 0;
			p1 = makepoint(value[0], value[1]);
			p2 = makepoint(value[2], value[3]);
			r.p1 = p1;
			r.p2 = p2;
			drawrect(r);
		}
	}
	return 0;
}
int main()
{  
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
            getpoint(points+i);
    }
      
    getminy(n);
    
    qsort ( points+1, n-1, sizeof(*points), comparepolar);  
   
   
    push(points[0]);
    push(points[1]);
    
    for(int i=2;i<n;i++)
    {
            while(ccw(stack[top-1],stack[top],points[i])<=0&&top>0)
            {                          
           //   printf("stack-->");putpoint(stack[top]);printf("\n");
                                                              top--;
            }
            //printf("stack<--");putpoint(points[i]);printf("\n");
            push(points[i]);
    }
    int t=top;
    while(t>=0)
    {
              putpoint(stack[t]);
              printf("\n");
              t--;
    }
    fflush(stdin);
    getchar();   
}
inline void getcut(){
  sort( li + 1 , li + 1 + n , cmp ); m = 1;
  for( int i = 2 ; i <= n ; i ++ )
    if( dc( li[ i ].angle - li[ m ].angle ) != 0 )
      li[ ++ m ] = li[ i ];
  deq[ 1 ] = li[ 1 ]; deq[ 2 ] = li[ 2 ];
  int bot = 1 , top = 2;
  for( int i = 3 ; i <= m ; i ++ ){
    while( bot < top && dc( cross( li[ i ].a , li[ i ].b , getpoint( deq[ top ] , deq[ top - 1 ] ) ) ) < 0 ) top -- ;
    while( bot < top && dc( cross( li[ i ].a , li[ i ].b , getpoint( deq[ bot ] , deq[ bot + 1 ] ) ) ) < 0 ) bot ++ ;
    deq[ ++ top ] = li[ i ] ;
  }
  while( bot < top && dc( cross( deq[ bot ].a , deq[ bot ].b , getpoint( deq[ top ] , deq[ top - 1 ] ) ) ) < 0 ) top --;
  while( bot < top && dc( cross( deq[ top ].a , deq[ top ].b , getpoint( deq[ bot ] , deq[ bot + 1 ] ) ) ) < 0 ) bot ++;
  cnt = 0;
  if( bot == top ) return;
  for( int i = bot ; i < top ; i ++ ) p[ ++ cnt ] = getpoint( deq[ i ] , deq[ i + 1 ] );
  if( top - 1 > bot ) p[ ++ cnt ] = getpoint( deq[ bot ] , deq[ top ] );
}
Exemple #12
0
/*
 * Prompts the user for a move with getinput, sanitizes it, and makes
 * the move. It stores the move in *move, you can specify the maximum
 * length l of the move to take, this should be at most the length of
 * move. If mill is less than three or more than five, move should
 * hold at least 5 characters. Returns pointer to the move.
 */
char *
getmove(scrgame *sg, char *move, int l)
{
  int length, pieces, index, twmm = 0;
  /* Do we only have 3 pieces, i.e. are we in skipping mode? */
  pieces = sg->game->pieces[(int) sg->game->state];
  if (l < 3 || 5 < l) {
    if (sg->game->type == TWMM) {
      /* We need to add one to our length to make up for the
       * possibility of ne/nw/se/sw over n/e/s/w */
      twmm = 1;
    }
    switch (sg->game->phase)
    {
    case 1:
      /* In piece placing mode */
      length = 3;
      break;

    case 2:
      /* Of form d3s or d3sw */
      length = 4 + twmm;
      break;

    case 3:
      if (pieces == 3) {
	/* Of form d3a1 */
	length = 5;
      } else {
	/* Of form d3s or d3sw */
	length = 4 + twmm;
      }
      break;

    default:
      length = 0;
      /* NOTREACHED */
    }
  } else {
    length = l;
  }
  move = getinput(sg, move, length);
  move = lower(move);
  if (!validcoords(sg->game, move) ||
      /* Check the length to make sure we're not in mill mode */
      (pieces == 3 && length != 3 && !validcoords(sg->game, &move[2]))) {
    update_msgbox(sg->msg_w, "Invalid coordinates");
    return getmove(sg, move, length);
  }
  /* If we'e in piece sliding stage. The length check makes sure we're
     not in mill mode. */
  if (sg->game->phase != 1 && pieces != 3 && length != 3) {
    index = dirtoindex(&move[2]);
    if (index == -1) {
      update_msgbox(sg->msg_w, "Invalid direction");
      return getmove(sg, move, length);
    } else if (!(getpoint(sg->game, /* We already checked that move[2]
				       is safe */
			  move)->n[index])) {
      update_msgbox(sg->msg_w, "Impossible to move in that direction");
      return getmove(sg, move, length);
    }
  }
  move[length - 1] = '\0';
  return move;
}
Exemple #13
0
int fido_brev(char *tillpers,char *adr,struct Mote *motpek) {
        int length=0,x=0,editret,chrs;
        struct FidoDomain *fd;
        struct FidoText *komft,ft;
        struct MinNode *first, *last;
        char *foo,tmpfrom[100],fullpath[100],filnamn[20],subject[80],msgid[50],tkn;
        if(!(Servermem->inne[nodnr].grupper & Servermem->fidodata.mailgroups) &&
                Servermem->inne[nodnr].status < Servermem->fidodata.mailstatus) {
                puttekn("\n\n\rDu har ingen rätt att skicka FidoNet NetMail.\n\r",-1);
                return(0);
        }
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&ft,0,sizeof(struct FidoText));
        if(!tillpers) { /* Det handlar om en kommentar */
                if(motpek) { /* Det är en personlig kommentar */
                        strcpy(fullpath,motpek->dir);
                        sprintf(filnamn,"%d.msg",senast_text_nr - motpek->renumber_offset);
                        AddPart(fullpath,filnamn,99);
                        komft = ReadFidoTextTags(fullpath,RFT_HeaderOnly,TRUE,TAG_DONE);
                        if(!komft) {
                                puttekn("\n\n\rTexten finns inte.\n\r",-1);
                                return(0);
                        }
                        strcpy(ft.touser,komft->fromuser);
                        ft.tozone = komft->fromzone;
                        ft.tonet = komft->fromnet;
                        ft.tonode = komft->fromnode;
                        ft.topoint = komft->frompoint;
                        strcpy(subject,komft->subject);
                        strcpy(msgid,komft->msgid);
                        FreeFidoText(komft);
                } else { /* Det är en kommentar av ett brev */
                        strcpy(tmpfrom,brevread.from);
                        foo=strchr(tmpfrom,'(');
                        if(!foo) {
                                puttekn("\n\n\rDen kommenterade texten saknar adress!\n\r",-1);
                                return(0);
                        }
                        *(foo-1)='\0';
                        foo++;
                        strcpy(ft.touser,tmpfrom);
                        ft.tozone=getzone(foo);
                        ft.tonet=getnet(foo);
                        ft.tonode=getnode(foo);
                        ft.topoint=getpoint(foo);
                        strcpy(subject,brevread.subject);
                        strcpy(msgid,brevread.messageid);

                }
        } else { /* Det är ett helt nytt brev */
                strcpy(ft.touser,tillpers);
                sprattgok(ft.touser);
                ft.tozone=getzone(adr);
                ft.tonet=getnet(adr);
                ft.tonode=getnode(adr);
                ft.topoint=getpoint(adr);
        }
        fd = getfidodomain(0,ft.tozone);
        if(!fd) {
                puttekn("\n\n\rDu kan inte skriva brev till den zonen.\n\r",-1);
                return(0);
        }
        if(!tillpers && !motpek) {
                foo = strchr(brevread.to,'(')+1;
                ft.fromzone = getzone(foo);
                ft.fromnet = getnet(foo);
                ft.fromnode = getnode(foo);
                ft.frompoint = getpoint(foo);
        } else {
                ft.fromzone = fd->zone;
                ft.fromnet = fd->net;
                ft.fromnode = fd->node;
                ft.frompoint = fd->point;
        }
        ft.attribut = FIDOT_PRIVATE | FIDOT_LOCAL;
        makefidousername(ft.fromuser,inloggad);
        makefidodate(ft.date);
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Fido-nätbrev,  %s\n\r",ft.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s (%d:%d/%d.%d)\r\n",ft.fromuser,ft.fromzone,ft.fromnet,ft.fromnode,ft.frompoint);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s (%d:%d/%d.%d)\n\r",ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
        puttekn(outbuffer,-1);
        puttekn("Ärende: ",-1);
        if(!tillpers) {
                if(!strncmp(subject,"Re:",3)) strcpy(ft.subject,subject);
                else sprintf(ft.subject,"Re: %s",subject);
                puttekn(ft.subject,-1);
        } else {
                if(getstring(EKO,40,NULL)) return(1);
                if(!inmat[0]) {
                        eka('\n');
                        return(0);
                }
                strcpy(ft.subject,inmat);
        }
        puttekn("\r\n",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(ft.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);
        crashmail = FALSE;
        editret = edittext(NULL);
        if(editret==1) return(1);
        if(editret==2) return(0);
        if(crashmail) ft.attribut |= FIDOT_CRASH;
        Servermem->inne[nodnr].skrivit++;
        Servermem->info.skrivna++;
        Statstr.write++;
        puttekn("\n\n\rTill vilken teckenuppsättning ska brevet konverteras?\r\n\n",-1);
        puttekn("1: ISO Latin 8-bitars tecken (Default)\n\r",-1);
        puttekn("2: IBM PC 8-bitars tecken\r\n",-1);
        puttekn("3: Macintosh 8-bitars tecken\r\n",-1);
        puttekn("4: Svenska 7-bitars tecken\r\n\n",-1);
        puttekn("Val: ",-1);
        for(;;) {
                tkn=gettekn();
                if(tkn==13 || tkn==10) tkn='1';
                if(tkn >= '1' && tkn <= '4') break;
        }
        sprintf(outbuffer,"%c\r\n\n",tkn);
        puttekn(outbuffer,-1);
        switch(tkn) {
                case '1' : chrs=CHRS_LATIN1; break;
                case '2' : chrs=CHRS_CP437; break;
                case '3' : chrs=CHRS_MAC; break;
                case '4' : chrs=CHRS_SIS7; break;
        }
        NewList((struct List *)&ft.text);
        first =  edit_list.mlh_Head;
        last = edit_list.mlh_TailPred;
        ft.text.mlh_Head = first;
        ft.text.mlh_TailPred = last;
        last->mln_Succ = (struct MinNode *)&ft.text.mlh_Tail;
        first->mln_Pred = (struct MinNode *)&ft.text;
        if(tillpers) x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                                      WFT_Domain,fd->domain,
                                                      WFT_CharSet,chrs,
                                                      TAG_DONE);
        else x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                            WFT_Domain,fd->domain,
                                            WFT_Reply,msgid,
                                            WFT_CharSet,chrs,
                                            TAG_DONE);
        sprintf(outbuffer,"Brevet fick nummer %d\r\n\n",x);
        puttekn(outbuffer,-1);
        if(Servermem->cfg.logmask & LOG_BREV) {
                strcpy(tmpfrom,getusername(inloggad));
                sprintf(outbuffer,"%s skickar brev %d till %s (%d:%d/%d.%d)",tmpfrom,x,ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
                logevent(outbuffer);
        }
        puttekn("Vill du ha en kopia av brevet i din egen brevlåda? ",-1);
        if(jaellernej('j','n',2)) savefidocopy(&ft,inloggad);
        while(first=(struct MinNode *)RemHead((struct List *)&ft.text)) FreeMem(first,sizeof(struct EditLine));
        NewList((struct List *)&edit_list);
        return(0);
}
Exemple #14
0
static int genpoints (int attr) {
    poly_t *pp;
    int zip, npanxxloc, ctbna;
    short county, blk;
    char state, blks;
    char *s;
    item_t *itemmem, *itemp;
    int itemi;
    int *indp;
    edge_t *e1p, *e2p;
    int edgepi;
    vertex_t *v1p, *v2p, *v3p;
    int xyi;

    for (
        pp = (poly_t *) dtflatten (polydict); pp;
        pp = (poly_t *) dtlink (polydict, pp)
    ) {
        if (pp->edgepl == 0)
            continue;
        e1p = pp->edgeps[0];
        if (e1p->p0p == pp) {
            blks = e1p->blksl;
            blk = e1p->blkl;
            ctbna = e1p->ctbnal;
            county = e1p->countyl;
            state = e1p->statel;
            zip = e1p->zipl;
            npanxxloc = e1p->npanxxlocl;
        } else {
            blks = e1p->blksr;
            blk = e1p->blkr;
            ctbna = e1p->ctbnar;
            county = e1p->countyr;
            state = e1p->stater;
            zip = e1p->zipr;
            npanxxloc = e1p->npanxxlocr;
        }
        s = NULL;
        switch (attr) {
        case T_EATTR_BLKS:
            if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0))
                s = sfprints (
                    "%02d%03d%06d%03d%c", state, county, ctbna, blk, blks
                );
            break;
        case T_EATTR_BLK:
            if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0))
                s = sfprints ("%02d%03d%06d%03d", state, county, ctbna, blk);
            break;
        case T_EATTR_BLKG:
            if ((state > 0) && (county > 0) && (ctbna > 0) && (blk > 0))
                s = sfprints (
                    "%02d%03d%06d%d", state, county, ctbna, blk / 100
                );
            break;
        case T_EATTR_CTBNA:
            if ((state > 0) && (county > 0) && (ctbna > 0))
                s = sfprints ("%02d%03d%06d", state, county, ctbna);
            break;
        case T_EATTR_COUNTY:
            if ((state > 0) && (county > 0))
                s = sfprints ("%02d%03d", state, county);
            break;
        case T_EATTR_STATE:
            if ((state > 0))
                s = sfprints ("%02d", state);
            break;
        case T_EATTR_ZIP:
            if ((zip > 0))
                s = sfprints ("%05d", zip);
            break;
        case T_EATTR_NPANXXLOC:
            if ((npanxxloc > -1))
                s = sfprints ("%d", npanxxloc);
            break;
        case T_EATTR_COUNTRY:
            s = "USA";
            break;
        }
        if (!s)
            continue;
        if (!(itemmem = malloc (sizeof (item_t)))) {
            SUwarning (1, "genpoints", "malloc failed for itemmem");
            return -1;
        }
        itemmem->name = strdup (s);
        if (!(itemp = dtinsert (itemdict, itemmem))) {
            SUwarning (1, "genpoints", "dtinsert failed for itemp");
            return -1;
        }
        if (itemp == itemmem) {
            itemp->pointn = 0, itemp->pointm = POINTINCR;
            if (!(itemp->points = malloc (sizeof (point_t) * itemp->pointm))) {
                SUwarning (1, "genpoints", "malloc failed for points");
                return -1;
            }
            itemp->indn = 0, itemp->indm = INDINCR;
            if (!(itemp->inds = malloc (sizeof (int) * itemp->indm))) {
                SUwarning (1, "genpoints", "malloc failed for inds");
                return -1;
            }
            itemp->trin = 0, itemp->trim = TRIINCR;
            if (!(itemp->tris = malloc (sizeof (tri_t) * itemp->trim))) {
                SUwarning (1, "genpoints", "malloc failed for tris");
                return -1;
            }
        }
        orderedges (pp);
        for (v1p = NULL, edgepi = 0; edgepi < pp->edgepl; edgepi++) {
            e1p = pp->edgeps[edgepi];
            if (!v1p) {
                if (!(indp = getind (itemp, 0))) {
                    SUwarning (1, "genpoints", "getind failed");
                    return -1;
                }
                if (e1p->p0p == pp)
                    v1p = e1p->v0p, v2p = e1p->v1p;
                else
                    v1p = e1p->v1p, v2p = e1p->v0p;
                v3p = v1p;
            }
            (*indp)++;
            if (!getpoint (itemp, v1p->xy)) {
                SUwarning (1, "genpoints", "getpoint failed (1)");
                return -1;
            }
            if (v1p == e1p->v0p) {
                for (xyi = 0; xyi < e1p->xyn; xyi++) {
                    (*indp)++;
                    if (!getpoint (itemp, e1p->xys[xyi])) {
                        SUwarning (1, "genpoints", "getpoint failed (2)");
                        return -1;
                    }
                }
            } else {
                for (xyi = e1p->xyn - 1; xyi >= 0; xyi--) {
                    (*indp)++;
                    if (!getpoint (itemp, e1p->xys[xyi])) {
                        SUwarning (1, "genpoints", "getpoint failed (3)");
                        return -1;
                    }
                }
            }
            v1p = NULL;
            if (edgepi + 1 < pp->edgepl) {
                e2p = pp->edgeps[edgepi + 1];
                if (e2p->v0p == v2p)
                    v1p = e2p->v0p, v2p = e2p->v1p;
                else if (e2p->v1p == v2p)
                    v1p = e2p->v1p, v2p = e2p->v0p;
            }
            if (!v1p) {
                (*indp)++;
                if (!getpoint (itemp, v2p->xy)) {
                    SUwarning (1, "genpoints", "getpoint failed (4)");
                    return -1;
                }
                if (savemask & 8) {
                    if (v2p->xy.x != v3p->xy.x || v2p->xy.y != v3p->xy.y) {
                        (*indp)++;
                        if (!getpoint (itemp, v3p->xy)) {
                            SUwarning (1, "genpoints", "getpoint failed (5)");
                            return -1;
                        }
                    }
                }
            }
        }
    }
    itempn = dtsize (itemdict);
    if (!(itemps = malloc (sizeof (item_t *) * itempn))) {
        SUwarning (1, "genpoints", "malloc failed for itemps");
        return -1;
    }
    for (
        itemi = 0, itemp = (item_t *) dtflatten (itemdict); itemp;
        itemp = (item_t *) dtlink (itemdict, itemp)
    )
        itemps[itemi++] = itemp;
    return 0;
}
Exemple #15
0
 void menu_file_pick(GtkMenuItem *menuitem, gpointer user_data){
   GtkWidget *widget = GTK_WIDGET(user_data);
   struct point_2d p = getpoint(widget);
   fprintf(stderr, "point = (%f,%f)\n", p.x, p.y);
 }
Exemple #16
0
void contour(double levels[],
	     int nlevels,
	     struct Map_info Map,
	     DCELL ** z, struct Cell_head Cell, int n_cut)
{
    int nrow, ncol;		/* number of rows and columns in current region */
    int startrow, startcol;	/* start row and col of current line */
    int n, i, j;		/* loop counters */
    double level;		/* current contour level */
    char **hit;			/* array of flags--1 if Cell has been hit;  */

    /*  0 if Cell is still to be checked */
    struct line_pnts *Points;
    struct line_cats *Cats;
    int outside;		/* 1 if line is exiting region; 0 otherwise */
    struct cell current;
    int p1, p2;			/* indexes to end points of cell edges */

    int ncrossing;		/* number of found crossing */

    Points = Vect_new_line_struct();
    Cats = Vect_new_cats_struct();

    nrow = Cell.rows;
    ncol = Cell.cols;

    hit = (char **)G_malloc((nrow - 1) * sizeof(char *));
    for (i = 0; i < nrow - 1; i++)
	hit[i] = (char *)G_malloc((ncol - 1) * sizeof(char));

    ncrossing = 0;

    G_message(_n("Writing vector contour (one level)...", 
        "Writing vector contours (total levels %d)...", nlevels), nlevels);

    for (n = 0; n < nlevels; n++) {
	level = levels[n];
	G_percent(n+1, nlevels, 2);	/* print progress */

	/* initialize hit array */
	for (i = 0; i < nrow - 1; i++) {
	    for (j = 0; j < ncol - 1; j++) {
		hit[i][j] = 0;
	    }
	}
	/* check each cell of top and bottom borders  */
	for (startrow = 0; startrow < nrow; startrow += (nrow - 2)) {
	    for (startcol = 0; startcol <= ncol - 2; startcol++) {

		/* look for starting point of new line */
		if (!hit[startrow][startcol]) {
		    current.r = startrow;
		    current.c = startcol;
		    outside = getnewcell(&current, nrow, ncol, z);

		    /* is this top or bottom? */
		    if (startrow == 0)	/* top */
			current.edge = 0;
		    else	/* bottom edge */
			current.edge = 2;
		    p1 = current.edge;
		    p2 = current.edge + 1;

		    if (checkedge(current.z[p1], current.z[p2], level)) {
			getpoint(&current, level, Cell, Points);
			/* while not off an edge, follow line */
			while (!outside) {
			    hit[current.r][current.c] +=
				findcrossing(&current, level, Cell, Points,
					     &ncrossing);
			    newedge(&current);
			    outside = getnewcell(&current, nrow, ncol, z);
			}
			if ((n_cut <= 0) || ((Points->n_points) > n_cut)) {
			    Vect_reset_cats(Cats);
			    Vect_cat_set(Cats, 1, n + 1);
			    Vect_write_line(&Map, GV_LINE, Points, Cats);
			}
			Vect_reset_line(Points);
		    }		/* if checkedge */
		}		/* if ! hit */
	    }			/* for columns */
	}			/* for rows */

	/* check right and left borders (each row of first and last column) */
	for (startcol = 0; startcol < ncol; startcol += (ncol - 2)) {
	    for (startrow = 0; startrow <= nrow - 2; startrow++) {
		/* look for starting point of new line */
		if (!hit[startrow][startcol]) {
		    current.r = startrow;
		    current.c = startcol;
		    outside = getnewcell(&current, nrow, ncol, z);

		    /* is this left or right edge? */
		    if (startcol == 0)	/* left */
			current.edge = 3;
		    else	/* right edge */
			current.edge = 1;
		    p1 = current.edge;
		    p2 = (current.edge + 1) % 4;
		    if (checkedge(current.z[p1], current.z[p2], level)) {
			getpoint(&current, level, Cell, Points);
			/* while not off an edge, follow line */
			while (!outside) {
			    hit[current.r][current.c] +=
				findcrossing(&current, level, Cell, Points,
					     &ncrossing);
			    newedge(&current);
			    outside = getnewcell(&current, nrow, ncol, z);
			}
			if ((n_cut <= 0) || ((Points->n_points) > n_cut)) {
			    Vect_reset_cats(Cats);
			    Vect_cat_set(Cats, 1, n + 1);
			    Vect_write_line(&Map, GV_LINE, Points, Cats);
			}
			Vect_reset_line(Points);
		    }		/* if checkedge */
		}		/* if ! hit */
	    }			/* for rows */
	}			/* for columns */

	/* check each interior Cell */
	for (startrow = 1; startrow <= nrow - 3; startrow++) {
	    for (startcol = 1; startcol <= ncol - 3; startcol++) {
		/* look for starting point of new line */
		if (!hit[startrow][startcol]) {
		    current.r = startrow;
		    current.c = startcol;
		    current.edge = 0;
		    outside = getnewcell(&current, nrow, ncol, z);
		    if (!outside &&
			checkedge(current.z[0], current.z[1], level)) {
			getpoint(&current, level, Cell, Points);
			hit[current.r][current.c] +=
			    findcrossing(&current, level, Cell, Points,
					 &ncrossing);
			newedge(&current);
			outside = getnewcell(&current, nrow, ncol, z);

			/* while not back to starting point, follow line */
			while (!outside &&
			       ((current.edge != 0) ||
				((current.r != startrow) ||
				 (current.c != startcol)))) {
			    hit[current.r][current.c] +=
				findcrossing(&current, level, Cell, Points,
					     &ncrossing);
			    newedge(&current);
			    outside = getnewcell(&current, nrow, ncol, z);
			}
			if ((n_cut <= 0) || ((Points->n_points) > n_cut)) {
			    Vect_reset_cats(Cats);
			    Vect_cat_set(Cats, 1, n + 1);
			    Vect_write_line(&Map, GV_LINE, Points, Cats);
			}
			Vect_reset_line(Points);
		    }		/* if checkedge */
		}		/* if ! hit */
	    }			/* for rows */
	}			/* for columns */
    }				/* for levels */

    if (ncrossing > 0) {
	G_warning(_n("%d crossing found", 
        "%d crossings found", 
        ncrossing), ncrossing);
    }

    Vect_destroy_line_struct(Points);
    Vect_destroy_cats_struct(Cats);
}