Esempio n. 1
0
void Duck::detectBoundaries()
{
    //If we're outside the screen's x range...
    if (!IN_RANGE(sprite.GetPosition().x, buffer[LEFT], buffer[RIGHT])) {
        sprite.SetX(buffer[sprite.GetPosition().x < buffer[LEFT] ? LEFT : RIGHT]);
        velocity.x *= -1;
    }

    //If we're outside the screen's y range...
    if (state == DuckState::FLYING_AROUND) {  //The ducks ignore up and down boundaries if flying in or out
        float temp = SCREEN.GetHeight()*.6;
        if (!IN_RANGE(sprite.GetPosition().y, buffer[UP], temp)) {
            sprite.SetY(sprite.GetPosition().y < temp ? buffer[UP] : temp);
            velocity.y *= -1;
        }
    }
}
Esempio n. 2
0
void opengl_depth_buffer_set_pixel(struct opengl_depth_buffer_t *db, int x, int y, float depth_val)
{
	/* Invalid X coordinate */
	if (!IN_RANGE(x, 0, db->width - 1))
	{
		warning("%s: invalid X coordinate", __FUNCTION__);
		return;
	}

	/* Invalid Y coordinate */
	if (!IN_RANGE(y, 0, db->height - 1))
	{
		warning("%s: invalid Y coordinate", __FUNCTION__);
		return;
	}

	db->buffer[y * db->width + x] = depth_val;
}
//REMEMBER BGR FORMAT
void OpenCVItemProcessing::ImageProcess_ColorMask(Mat image)
{
	image.forEach<Pixel>([](Pixel& pixel,const int* position)->void
	{
		if (IN_RANGE(pixel.z, r_min, r_max) && IN_RANGE(pixel.y, g_min, g_max) && IN_RANGE(pixel.x, b_min, b_max))
		{
			pixel.x = 255;
			pixel.y = 255;
			pixel.z = 255;
		}
		else
		{
			pixel.x = 0;
			pixel.y = 0;
			pixel.z = 0;
		}
	});
}
Esempio n. 4
0
static int uri_parse_authority(const char *authority, struct uri *uri) {
  const char *portsep;
  const char *host_start, *host_end;
  char *tail;

  /* We do not support "user:pass@" userinfo. The proxy has no use for it. */
  if (strchr(authority, '@') != NULL)
    return -1;

  /* Find the beginning and end of the host. */
  host_start = authority;

  if (*host_start == '[') {
    /* IPv6 address in brackets. */
    host_start++;
    host_end = strchr(host_start, ']');

    if (host_end == NULL)
      return -1;

    portsep = host_end + 1;

    if (!(*portsep == ':' || *portsep == '\0'))
      return -1;

  } else {
    portsep = strrchr(authority, ':');

    if (portsep == NULL)
      portsep = strchr(authority, '\0');
    host_end = portsep;
  }

  /* Get the port number. */
  if (*portsep == ':' && *(portsep + 1) != '\0') {
    long n;

    errno = 0;
    n = parse_long(portsep + 1, &tail);
    if (errno || *tail || (tail == (portsep + 1)) || !IN_RANGE(n, 1, 65535))
      return -1;
    uri->port = n;
  } else {
    uri->port = -1;
  }

  /* Get the host. */
  uri->host = mkstr(host_start, host_end);
  if (percent_decode(uri->host) < 0) {
    free(uri->host);
    uri->host = NULL;
    return -1;
  }

  return 1;
}
Esempio n. 5
0
/* select the frames in this layer that occur within the bounds specified */
void borderselect_gplayer_frames (bGPDlayer *gpl, float min, float max, short select_mode)
{
	bGPDframe *gpf;
	
	/* only select those frames which are in bounds */
	for (gpf= gpl->frames.first; gpf; gpf= gpf->next) {
		if (IN_RANGE(gpf->framenum, min, max))
			gpframe_select(gpf, select_mode);
	}
}
Esempio n. 6
0
void MenuStage::OnMouseButtonPress(uint32 x, uint32 y, bool left)
{
    if (IN_RANGE(x,y, WIDTH-350, WIDTH, 50, 50+80))
    {
        sApplication->SetStage(STAGE_GAMESETTINGS, 100);
        return;
    }
    else if (IN_RANGE(x,y, WIDTH-350, WIDTH, 160, 160+80))
    {
        sNetwork->Connect(sConfig->HostName.c_str(), sConfig->NetworkPort);
        sApplication->SetStage(STAGE_GAMESETTINGS);
        return;
    }
    else if (IN_RANGE(x,y, WIDTH-350, WIDTH, 270, 270+80))
    {
        exit(0);
        return;
    }
}
/* Register strerror handle. */
PJ_DEF(pj_status_t) pj_register_strerror( pj_status_t start,
					  pj_status_t space,
					  pj_error_callback f)
{
    unsigned i;

    /* Check arguments. */
    PJ_ASSERT_RETURN(start && space && f, PJ_EINVAL);

    /* Check if there aren't too many handlers registered. */
    PJ_ASSERT_RETURN(err_msg_hnd_cnt < PJ_ARRAY_SIZE(err_msg_hnd),
		     PJ_ETOOMANY);

    /* Start error must be greater than PJ_ERRNO_START_USER */
    PJ_ASSERT_RETURN(start >= PJ_ERRNO_START_USER, PJ_EEXISTS);

    /* Check that no existing handler has covered the specified range. */
    for (i=0; i<err_msg_hnd_cnt; ++i) {
	if (IN_RANGE(start, err_msg_hnd[i].begin, err_msg_hnd[i].end) ||
	    IN_RANGE(start+space-1, err_msg_hnd[i].begin, err_msg_hnd[i].end))
	{
	    if (err_msg_hnd[i].begin == start && 
		err_msg_hnd[i].end == (start+space) &&
		err_msg_hnd[i].strerror == f)
	    {
		/* The same range and handler has already been registered */
		return PJ_SUCCESS;
	    }

	    return PJ_EEXISTS;
	}
    }

    /* Register the handler. */
    err_msg_hnd[err_msg_hnd_cnt].begin = start;
    err_msg_hnd[err_msg_hnd_cnt].end = start + space;
    err_msg_hnd[err_msg_hnd_cnt].strerror = f;

    ++err_msg_hnd_cnt;

    return PJ_SUCCESS;
}
static inline int
register_no_elim_operand_1 (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
#line 513 "../.././gcc/config/i386/predicates.md"
{
  if (GET_CODE (op) == SUBREG)
    op = SUBREG_REG (op);
  return !(op == arg_pointer_rtx
	   || op == frame_pointer_rtx
	   || IN_RANGE (REGNO (op),
			FIRST_PSEUDO_REGISTER, LAST_VIRTUAL_REGISTER));
}
Esempio n. 9
0
/*
 * mincore -- interpose on libc mincore(2)
 *
 * Return 0 only for specified regions, otherwise return -1 with
 * errno = ENOMEM.
 */
int
mincore(void *addr, size_t length, unsigned char *vec)
{
	for (int i = 0; i < Nregions; i++) {
		if (IN_RANGE(addr, length, Mincore[i].addr, Mincore[i].len))
			return 0;
	}

	errno = ENOMEM;
	return -1;
}
Esempio n. 10
0
struct vi_mod_t *vi_net_get_mod(struct vi_net_t *net, int node_index)
{
	struct vi_net_node_t *node;

	/* Check bounds */
	if (!IN_RANGE(node_index, 0, net->node_list->count - 1))
		panic("%s: node index out of bounds", __FUNCTION__);

	/* Return */
	node = list_get(net->node_list, node_index);
	return node->mod;
}
Esempio n. 11
0
// /proc/eink_fb/hardware_fb (read-only)
//
static int read_hardwarefb_count(unsigned long addr, unsigned char *data, int count)
{
    int result = 0;
    
    if ( scratchfb && data && IN_RANGE((addr + count), 0, scratchfb_size) )
    {
        EINKFB_MEMCPYK(data, &scratchfb[addr], count);
        result = 1;
    }
    
    return ( result );
}
Esempio n. 12
0
void dir_entry_set_owner(struct dir_t *dir, int x, int y, int z, int node)
{
	struct dir_entry_t *dir_entry;

	/* Set owner */
	assert(node == DIR_ENTRY_OWNER_NONE || IN_RANGE(node, 0, dir->num_nodes - 1));
	dir_entry = dir_entry_get(dir, x, y, z);
	dir_entry->owner = node;

	/* Trace */
	mem_trace("mem.set_owner dir=\"%s\" x=%d y=%d z=%d owner=%d\n",
		dir->name, x, y, z, node);
}
Esempio n. 13
0
/* select the frames in this layer that occur within the bounds specified */
void ED_masklayer_frames_select_border(MaskLayer *masklay, float min, float max, short select_mode)
{
	MaskLayerShape *masklay_shape;

	if (masklay == NULL)
		return;

	/* only select those frames which are in bounds */
	for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = masklay_shape->next) {
		if (IN_RANGE(masklay_shape->frame, min, max))
			masklayshape_select(masklay_shape, select_mode);
	}
}
Esempio n. 14
0
struct si2bin_arg_t *si2bin_arg_create_vector_register(int id)
{
	struct si2bin_arg_t *arg;

	arg = si2bin_arg_create();
	arg->type = si2bin_arg_vector_register;
	arg->value.vector_register.id = id;

	if (!IN_RANGE(arg->value.vector_register.id, 0, 255))
		si2bin_yyerror_fmt("vector register out of range: v%d", id);

	return arg;
}
Esempio n. 15
0
static void gc_start(void) {
    scm_val v = NIL, *p ;

    STACK_INIT() ;

    for (p = stack_start; p != (scm_val *)&p; p += stack_dir)
        if (IN_RANGE(*p)) GRAY(*p) ;

    FOREACH(v, roots) {
        scm_val r = *(scm_val *)(CAR(v).p) ;
        v.c->flags = FL_GC_BLACK ;
        if (PTR_AND_NO_FLAG(r, FL_GC_GRAY)) GRAY(r) ;
    }
Esempio n. 16
0
struct frm_arg_t *frm_arg_create_scalar_register(char *name)
{
	struct frm_arg_t *arg;

	arg = frm_arg_create();
	arg->type = frm_arg_scalar_register;

	assert(name[0] == 'R');
	arg->value.scalar_register.id = atoi(name + 1);
	if (!IN_RANGE(arg->value.scalar_register.id, 0, 62))
		frm2bin_yyerror_fmt("register out of range: %s", name);

	return arg;
}
Esempio n. 17
0
STDMETHODIMP ArrayPtrVariant<I, B>::Item(VARIANT v, I **pRet)
{
	long i = SysStatsUtils::VariantToInteger(&v);

	if (IN_RANGE(i))
	{
		*pRet = coll[i];
		(*pRet)->AddRef();
	}
	else
		*pRet = NULL;

	return S_OK;
}
Esempio n. 18
0
static void frm_uop_add_src_idep(struct frm_uop_t *uop, struct frm_inst_t *inst, int src_idx)
{
	int sel, rel, chan, neg, abs;

	assert(uop->idep_count < FRM_UOP_MAX_IDEP);
	frm_inst_get_op_src(inst, src_idx, &sel, &rel, &chan, &neg, &abs);

	/* sel = 0..127: Value in GPR */
	if (IN_RANGE(sel, 0, 127))
		uop->idep[uop->idep_count++] = FRM_UOP_DEP_REG(sel);

	/* sel = ALU_SRC_PV */
	else if (sel == 254)
		uop->idep[uop->idep_count++] = FRM_UOP_DEP_PV;

	/* sel = ALU_SRC_PS */
	else if (sel == 255)
		uop->idep[uop->idep_count++] = FRM_UOP_DEP_PS;

	/* sel = 219..222: QA, QA.pop, QB, QB.pop */
	else if (IN_RANGE(sel, 219, 222))
		uop->idep[uop->idep_count++] = FRM_UOP_DEP_LDS;
}
Esempio n. 19
0
bool CSound::SetVolume( size_t nVolume  ) // region between 0 and 1000
{
	ASSERT(IN_RANGE(nVolume, 0, 1000));
	StrUtils::FormatString( m_sDeviceCommand, "setaudio %s volume to %u", m_sDeviceAlias.c_str(), nVolume );
	
	bool result = (0 == mciSendStringA( m_sDeviceCommand.c_str(), NULL, 0, 0));

	if (result)
	{
		on_volume_chnaged(nVolume);
	}
	
	return result;
}
Esempio n. 20
0
/* Parse a dotted-decimal string into an uint8_t array - return -1 on error */
static int ipToArray(const char* text, uint8_t dest[], int maxOctets, Boolean isMask)
{

    char* text_;
    char* text__;
    char* subtoken;
    char* stash = NULL;
    char* endptr;
    long octet;

    int count = 0;
    int result = 0;

    memset(&dest[0], 0, maxOctets * sizeof(uint8_t));

    text_=strdup(text);

    for(text__=text_;;text__=NULL) {

	if(count > maxOctets) {
	    result = -1;
	    goto end;
	}

	subtoken = strtok_r(text__,".",&stash);

	if(subtoken == NULL)
		goto end;

	errno = 0;
	octet=strtol(subtoken,&endptr,10);
	if(errno!=0 || !IN_RANGE(octet,0,255)) {
	    result = -1;
	    goto end;

	}

	dest[count++] = (uint8_t)octet;

	/* If we're parsing a mask and an octet is less than 0xFF, whole rest is zeros */
	if(isMask && octet < 255)
		goto end;
    }

    end:

    free(text_);
    return result;

}
Esempio n. 21
0
void vi_net_attach_mod(struct vi_net_t *net,
	struct vi_mod_t *mod, int node_index)
{
	struct vi_net_node_t *node;

	/* Check bounds */
	if (!IN_RANGE(node_index, 0, net->node_list->count - 1))
		panic("%s: node index out of bounds", __FUNCTION__);

	/* Attach */
	node = list_get(net->node_list, node_index);
	assert(node);
	node->mod = mod;
}
Esempio n. 22
0
/*
 * This function is limited to finding intersections between
 * horizontal and vertical lines!
 *
 * The original implementation is more general but obstacle
 * polygons only consists of horizontal and vertical lines,
 * and this is more numerically stable.
 */
bool Obstacles::lineLineIntersection(LineSegment a, LineSegment b, Vector2 *intersection) {
	assert(a.start.x == a.end.x || a.start.y == a.end.y);
	assert(b.start.x == b.end.x || b.start.y == b.end.y);

	if (a.start.x > a.end.x) SWAP(a.start.x, a.end.x);
	if (a.start.y > a.end.y) SWAP(a.start.y, a.end.y);
	if (b.start.x > b.end.x) SWAP(b.start.x, b.end.x);
	if (b.start.y > b.end.y) SWAP(b.start.y, b.end.y);

	if (a.start.x == a.end.x && b.start.y == b.end.y && IN_RANGE(a.start.x, b.start.x, b.end.x) && IN_RANGE(b.start.y, a.start.y, a.end.y)) {
		// A is vertical, B is horizontal
		*intersection = Vector2(a.start.x, b.start.y);
		return true;
	}

	if (a.start.y == a.end.y && b.start.x == b.end.x && IN_RANGE(a.start.y, b.start.y, b.end.y) && IN_RANGE(b.start.x, a.start.x, a.end.x)) {
		// A is horizontal, B is vertical
		*intersection = Vector2(b.start.x, a.start.y);
		return true;
	}

	return false;
}
Esempio n. 23
0
uint32_t ti89t_get_long(uint32_t adr) 
{
	// RAM access
	if(IN_BOUNDS(0x000000, adr, 0x03ffff) ||
	   IN_BOUNDS(0x200000, adr, 0x23ffff) ||
	   IN_BOUNDS(0x400000, adr, 0x43ffff))
	{
		return get_l(tihw.ram, adr, 0x03ffff);
	}

	// FLASH access
    else if(IN_BOUNDS(0x800000, adr, 0xbfffff))			
	{
		// use FlashReadLong due to Epson Device ID
		return FlashReadLong(adr);
	}

	// memory-mapped I/O
    else if(IN_BOUNDS(0x600000, adr, 0x6fffff))
	{
       return io_get_long(adr);
	}

	// memory-mapped I/O (hw2)
	else if(IN_RANGE(adr, 0x700000, IO2_SIZE_TI89T))
	{
		return io2_get_long(adr);
	}

	// memory-mapped I/O (hw3)
	else if(IN_RANGE(adr, 0x710000, IO3_SIZE_TI89T))
	{
		return io3_get_long(adr);
	}

    return 0x14141414;
}
Esempio n. 24
0
uint8_t* ti89t_get_real_addr(uint32_t adr)
{
	// RAM access
	if(IN_BOUNDS(0x000000, adr, 0x03ffff) ||
	   IN_BOUNDS(0x200000, adr, 0x23ffff) ||
	   IN_BOUNDS(0x400000, adr, 0x43ffff))
	{
		return get_p(tihw.ram, adr, 0x03ffff);
	}

	// FLASH access
    else if(IN_BOUNDS(0x800000, adr, 0xbfffff))			
	{
		return get_p(tihw.rom, adr, ROM_SIZE_TI89T - 1);
	}

	// memory-mapped I/O
    else if(IN_BOUNDS(0x600000, adr, 0x6fffff))
	{
		return get_p(tihw.io, adr, IO1_SIZE_TI89T - 1);
	}

	// memory-mapped I/O (hw2)
	else if(IN_RANGE(adr, 0x700000, IO2_SIZE_TI89T))
	{
		return get_p(tihw.io2, adr, IO2_SIZE_TI89T - 1);
	}

	// memory-mapped I/O (hw3)
	else if(IN_RANGE(adr, 0x710000, IO3_SIZE_TI89T))
	{
		return get_p(tihw.io3, adr, IO3_SIZE_TI89T - 1);
	}

	return tihw.unused;
}
Esempio n. 25
0
void ti89t_put_byte(uint32_t adr, uint8_t arg) 
{
	// RAM access
	if(IN_BOUNDS(0x000000, adr, 0x03ffff) ||
	   IN_BOUNDS(0x200000, adr, 0x23ffff) ||
	   IN_BOUNDS(0x400000, adr, 0x43ffff))
	{
		put_b(tihw.ram, adr, 0x03ffff, arg);
	}

	// FLASH access
    else if(IN_BOUNDS(0x800000, adr, 0xbfffff))
	{
		FlashWriteByte(adr, arg);
	}

	// memory-mapped I/O
    else if(IN_BOUNDS(0x600000, adr, 0x6fffff))			
	{
		io_put_byte(adr, arg);
	}

	// memory-mapped I/O (hw2)
	else if(IN_RANGE(adr, 0x700000, IO2_SIZE_TI89T))
	{
		io2_put_byte(adr, arg);
	}

	// memory-mapped I/O (hw3)
	else if(IN_RANGE(adr, 0x710000, IO3_SIZE_TI89T))
	{
		io3_put_byte(adr, arg);
	}

    return;
}
Esempio n. 26
0
uint8_t ti89t_get_byte(uint32_t adr) 
{
	// RAM access
	if(IN_BOUNDS(0x000000, adr, 0x03ffff) ||
	   IN_BOUNDS(0x200000, adr, 0x23ffff) ||
	   IN_BOUNDS(0x400000, adr, 0x43ffff))
	{
		return get_b(tihw.ram, adr, 0x03ffff);
	}

	// FLASH access
    else if(IN_BOUNDS(0x800000, adr, 0xbfffff))			
	{
		return FlashReadByte(adr);
	}

	// memory-mapped I/O
    else if(IN_BOUNDS(0x600000, adr, 0x6fffff))
	{
       return io_get_byte(adr);
	}

	// memory-mapped I/O (hw2)
	else if(IN_RANGE(adr, 0x700000, IO2_SIZE_TI89T))
	{
		return io2_get_byte(adr);
	}

	// memory-mapped I/O (hw3)
	else if(IN_RANGE(adr, 0x710000, IO3_SIZE_TI89T))
	{
		return io3_get_byte(adr);
	}

    return 0x14;
}
Esempio n. 27
0
/**
* Korean IM helper function to tell whether a character typed will produce
* a vowel.
*
* @see im_event_ko
*/
static int im_event_ko_isvowel(CHARMAP* cm, wchar_t c)
{
  STATE_MACHINE *start, *next;
  const wchar_t* unicode;
  int section;

  /* Determine the starting state based on the charmap's active section */
  section = cm->section;
  if(!IN_RANGE(0, section, (int)ARRAYLEN(cm->sections))) section = 0;
  start = &cm->sections[section];

  next = sm_search_shallow(start, (char)c);
  unicode = next ? next->output : NULL;

  return (unicode && wcslen(unicode) == 1 && 0x314F <= unicode[0] && unicode[0] <= 0x3163);
}
Esempio n. 28
0
int 
univ_to_local(Sint *year, Sint *month, Sint *day, 
	      Sint *hour, Sint *minute, Sint *second)
{
    time_t the_clock;
    struct tm *tm;
#ifdef HAVE_LOCALTIME_R
    struct tm tmbuf;
#endif
    
    if (!(IN_RANGE(BASEYEAR, *year, INT_MAX - 1) &&
          IN_RANGE(1, *month, 12) &&
          IN_RANGE(1, *day, (mdays[*month] + 
                             (*month == 2 
                              && (*year % 4 == 0) 
                              && (*year % 100 != 0 || *year % 400 == 0)))) &&
          IN_RANGE(0, *hour, 23) &&
          IN_RANGE(0, *minute, 59) &&
          IN_RANGE(0, *second, 59))) {
      return 0;
    }
    
    the_clock = *second + 60 * (*minute + 60 * (*hour + 24 *
                                            gregday(*year, *month, *day)));
#ifdef HAVE_POSIX2TIME
    /*
     * Addition from OpenSource - affects FreeBSD.
     * No valid test case /PaN
     *
     * leap-second correction performed
     * if system is configured so;
     * do nothing if not
     * See FreeBSD 6.x and 7.x
     * /usr/src/lib/libc/stdtime/localtime.c
     * for the details
     */
    the_clock = posix2time(the_clock);
#endif

#ifdef HAVE_LOCALTIME_R
    tm = localtime_r(&the_clock, &tmbuf);
#else
    tm = localtime(&the_clock);
#endif
    if (tm) {
	*year   = tm->tm_year + 1900;
	*month  = tm->tm_mon +1;
	*day    = tm->tm_mday;
	*hour   = tm->tm_hour;
	*minute = tm->tm_min;
	*second = tm->tm_sec;
	return 1;
    }
    return 0;
}
Esempio n. 29
0
struct si2bin_arg_t *si2bin_arg_create_literal(int value)
{
	struct si2bin_arg_t *arg;
	arg = si2bin_arg_create();
	arg->value.literal.val = value;

	/* Detect the special case where the literal constant is in range
	 * [-16..64]. Some instructions can encode these values more
	 * efficiently. Some others even only allow for these values. */
	if (IN_RANGE(value, -16, 64))
		arg->type = si2bin_arg_literal_reduced;
	else
		arg->type = si2bin_arg_literal;
	
	return arg;
}
Esempio n. 30
0
int fslepdc_read_temperature(void)
{
    int temp = fslepdc_temperature;
    
    // If the override temperature is not in range...
    //
    if ( !IN_RANGE(fslepdc_temperature, EINKFB_TEMP_MIN, EINKFB_TEMP_MAX) )
    {
        // ...then get the temperature from the PMIC in the
        // specified way.
        //
        temp = fslepdc_pmic_get_temperature();
    }
    
    return ( temp );
}