Beispiel #1
0
typename enable_if<is_concept_combinable<is_interval_set, is_interval_map, 
                                         SetT, Type>, SetT>::type&
between(SetT& in_between, const Type& object)
{
    typedef typename Type::const_iterator const_iterator;
    typedef typename SetT::iterator       set_iterator;
    in_between.clear();
    const_iterator it_ = object.begin(), pred_;
    set_iterator   prior_ = in_between.end();

    if(it_ != object.end())
        pred_ = it_++;

    while(it_ != object.end())
        prior_ = icl::insert(in_between, prior_, 
                             between((*pred_++).first, (*it_++).first));
    
    return in_between;
}
Beispiel #2
0
double CvFuzzyCurve::calcValue(double param) {
    int size = (int)points.size();
    double x1, y1, x2, y2, m, y;
    for (int i = 1; i < size; i++) {
        x1 = points[i-1].x;
        x2 = points[i].x;
        if (between(param, x1, x2)) {
            y1 = points[i-1].y;
            y2 = points[i].y;
            if (x2 == x1) {
                return y2;
            }
            m = (y2 - y1) / (x2 - x1);
            y = m * (param - x1) + y1;
            return y;
        }
    }
    return 0;
};
Beispiel #3
0
static bool resolveAddr(part_t* pPart, void* addr)
{
	if (!between((word_t)addr, 0x02000000, 0x03000000)) return false;
	addr = memCached(addr);
	if ((word_t)addr < (word_t)__end__)
	{
		pPart->name = "(kernel)";
		pPart->module = NULL;
		pPart->offset = (word_t)addr;
		return true;
	}
	module_t module = LdrResolveAddr(addr);
	if (!module) return false;

	pPart->name = GetRuntimeData(module)->name;
	pPart->module = module;
	pPart->offset = addr - module;
	return true;
}
Beispiel #4
0
_Point top(const Quadratic& quad, double startT, double endT) {
    Quadratic sub;
    sub_divide(quad, startT, endT, sub);
    _Point topPt = sub[0];
    if (topPt.y > sub[2].y || (topPt.y == sub[2].y && topPt.x > sub[2].x)) {
        topPt = sub[2];
    }
    if (!between(sub[0].y, sub[1].y, sub[2].y)) {
        double extremeT;
        if (findExtrema(sub[0].y, sub[1].y, sub[2].y, &extremeT)) {
            extremeT = startT + (endT - startT) * extremeT;
            _Point test;
            xy_at_t(quad, extremeT, test.x, test.y);
            if (topPt.y > test.y || (topPt.y == test.y && topPt.x > test.x)) {
                topPt = test;
            }
        }
    }
    return topPt;
}
Beispiel #5
0
bool piece::noVerticalObstr(string fromFR, string toFR, map<string, piece*>* board)
{
 char fromFile = fromFR.at(boardlayout::Findex);
 char fromRank = fromFR.at(boardlayout::Rindex);
 char toRank = toFR.at(boardlayout::Rindex);
 char lowRank = (fromRank < toRank) ? fromRank : toRank;
 char highRank = (fromRank < toRank) ? toRank : fromRank;

 for (char i = lowRank + 1; i < highRank; i++)
 {
  string between("00");
  between[0]=fromFile;
  between[1]=i;
    try {
      board -> at(between);
      return false;
    } catch (const std::out_of_range &err) {
    }
 }
  return true;
}
Beispiel #6
0
bool piece::noHorizontalObstr(string fromFR, string toFR, map<string, piece*> *board)
{
  char fromRank = fromFR.at(boardlayout::Rindex);
  char fromFile = fromFR.at(boardlayout::Findex);
  char toFile = toFR.at(boardlayout::Findex);
  char lowFile = (fromFile < toFile) ? fromFile : toFile;
  char highFile = (fromFile < toFile) ? toFile : fromFile;

  for (char i = lowFile + 1; i < highFile; i++)
  {
   string between("00");
   between[1]=fromRank;
   between[0]=i;
    try {
      board -> at(between);
      return false;
    } catch (const std::out_of_range &err) {
    }
  }
   return true;
}
double SkDLine::NearPointV(const SkDPoint& xy, double top, double bottom, double x) {
    if (!AlmostBequalUlps(xy.fX, x)) {
        return -1;
    }
    if (!AlmostBetweenUlps(top, xy.fY, bottom)) {
        return -1;
    }
    double t = (xy.fY - top) / (bottom - top);
    t = SkPinT(t);
    SkASSERT(between(0, t, 1));
    double realPtY = (1 - t) * top + t * bottom;
    SkDVector distU = {xy.fX - x, xy.fY - realPtY};
    double distSq = distU.fX * distU.fX + distU.fY * distU.fY;
    double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq instead ?
    double tiniest = SkTMin(SkTMin(x, top), bottom);
    double largest = SkTMax(SkTMax(x, top), bottom);
    largest = SkTMax(largest, -tiniest);
    if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance?
        return -1;
    }
    return t;
}
Beispiel #8
0
interval_db* node_mgr::findIntervalDb(const string* key, int lockDB) {
    DBID p_id(*key);

    // lock intervaldb
    pthread_rwlock_rdlock(&interval_lock);

    for (uint i = 0; i < dbs.size(); i++) {
        if (lockDB == WRLOCK)
            pthread_rwlock_wrlock(&(dbs[i]->dbLock));
        else
            pthread_rwlock_rdlock(&(dbs[i]->dbLock));

        //Unlock list so others can access
        pthread_rwlock_unlock(&interval_lock);

        const DBID *d_end_id = dbs[i]->h->getEndID();
        const DBID *d_start_id = dbs[i]->h->getStartID();
        // ownership => (begindID + 1) to endID  [both inclusive]
        if (between(d_start_id, d_end_id, &p_id) && dbs[i]->valid) {
            if (lockDB == NOLOCK)
                pthread_rwlock_unlock(&(dbs[i]->dbLock));
            delete d_end_id;
            delete d_start_id;
            return dbs[i];
        }
        delete d_end_id;
        delete d_start_id;

        // Release lock because you didn't find it
        pthread_rwlock_unlock(&(dbs[i]->dbLock));

        // Acquire list lock again
        pthread_rwlock_rdlock(&interval_lock);
    }

    // interval_lock is locked if it gets here, so unlock
    pthread_rwlock_unlock(&interval_lock);
    return NULL;
}
Beispiel #9
0
int main(int argc, char **argv) {
  char *prog = argv[0];
  char **arg = argv+1;
  int n, d;
  CF a[2], r;

  if (argc < 2) usage(prog);

  {
    unsigned i;
    for (i=0; i<2; i++) 
      if (parserat(arg[i], &n, &d)) 
	a[i] = new_rat(n, d);
      else 
	usage(prog);
  }

  r = between(a[0], a[1]);
  print_cf(r);

  return 0;
}
Beispiel #10
0
double SkDLine::NearPointH(const SkDPoint& xy, double left, double right, double y) {
    if (!AlmostBequalUlps(xy.fY, y)) {
        return -1;
    }
    if (!AlmostBetweenUlps(left, xy.fX, right)) {
        return -1;
    }
    double t = (xy.fX - left) / (right - left);
    t = SkPinT(t);
    SkASSERT(between(0, t, 1));
    double realPtX = (1 - t) * left + t * right;
    SkDVector distU = {xy.fY - y, xy.fX - realPtX};
    double distSq = distU.fX * distU.fX + distU.fY * distU.fY;
    double dist = sqrt(distSq); // OPTIMIZATION: can we compare against distSq instead ?
    double tiniest = SkTMin(SkTMin(y, left), right);
    double largest = SkTMax(SkTMax(y, left), right);
    largest = SkTMax(largest, -tiniest);
    if (!AlmostEqualUlps(largest, largest + dist)) { // is the dist within ULPS tolerance?
        return -1;
    }
    return t;
}
Beispiel #11
0
bool piece::noDiagonalObstr(string fromFR, string toFR, map<string, piece*> *board)
{
 char fromRank = fromFR.at(boardlayout::Rindex);
 char toRank = toFR.at(boardlayout::Rindex);
 char lowRank = (fromRank < toRank) ? fromRank : toRank;
 char highRank = (fromRank < toRank) ? toRank : fromRank;

 char fromFile = fromFR.at(boardlayout::Findex);
 char toFile = toFR.at(boardlayout::Findex);
 char lowFile = (fromFile < toFile) ? fromFile : toFile;
 char highFile = (fromFile < toFile) ? toFile : fromFile;

 bool isPositiveSlope = (toFile - fromFile) == (toRank - fromRank);

 string between("00");

 for (int i = 1; i < (highFile - lowFile); i++)
 {
  if (isPositiveSlope)
  {
   between[0] = lowFile + i;
   between[1] = lowRank + i;
   }
   else
   {
    between[0] = lowFile + i;
    between[1] = highRank - i;
   }

   try {
   board -> at (between);
   return false;
   } catch (const std::out_of_range &err) {
    }
 }
  return true;
}
Beispiel #12
0
//////////
//
// Creates a new node and inserts it between where node1 (*root) points to node2.
//
//////
	SNode* iNode_insert(SNode** root, s32 tnDirection)
	{
		s32			lnMirrorDirection;
		SNode*		n[_NODE_COUNT];
		SNode*		node1;
		SNode*		node2;
		SNode*		newNode;


		// Make sure our environment is sane
		if (!root || !between(tnDirection, _NODE_MIN, _NODE_MAX))
			return(NULL);

		// Initialize
		memset(&n[0], 0, sizeof(n));
		node1				= *root;
		node2				= node1->n[tnDirection];
		lnMirrorDirection	= gnNodeMirrors[tnDirection];

		// Create and populate our new node
		newNode = iNode_create(NULL, NULL, &n[0]);
		if (newNode)
		{
			// New points mirror-back to node1 and node2
			newNode->n[lnMirrorDirection]	= node1;		// newNode points to node1
			newNode->n[tnDirection]			= node2;		// newNode points to node2
			node1->n[tnDirection]			= newNode;		// node1 points to newNode

			// If there was really a node out there, hook it up
			if (node2)
				node2->n[lnMirrorDirection]	= newNode;		// node2 points to newNode
		}

		// Indicate our status
		return(newNode);
	}
Beispiel #13
0
int main (int argc, char **argv)
{
   int  retcode = 0;
   char opt;

   /* 
    * Unbuffer stdout 
    */
   setbuf (stdout, NULL);

   /* 
    * default configuration options 
    */
   opts.src_port = 31337;
   opts.low_port = 1;
   opts.high_port = 1024;
   opts.target = NULL;
   opts.timeout = 5;

   if (argc < 2) {
      fprintf (stderr, "usage: %s\n", argv[0]);
      fprintf (stderr, "\t-d target\n");
      fprintf (stderr, "\t-s source_port (default %d)\n", opts.src_port);
      fprintf (stderr, "\t-l low_port (default %d)\n", opts.low_port);
      fprintf (stderr, "\t-h high_port (default %d)\n", opts.high_port);
      fprintf (stderr, "\t-t timeout_in_seconds (default %d)\n",
	       opts.timeout);
      return 1;
   }

   /* 
    * parse command line options 
    */
   opterr = 0;
   while ((opt = getopt (argc, argv, "s:d:l:h:t:")) != -1) {
      switch (opt) {
      case 't':
	 opts.timeout = atoi (optarg);
	 break;
      case 's':
	 opts.src_port = atoi (optarg);
	 if (!(between (opts.src_port, 0, 65536))) {
	    fprintf (stderr, "source port must be between 1 and 65536\n");
	    return (1);
	 }
	 break;
      case 'd':
	 opts.target = strdup (optarg);
	 break;
      case 'l':
	 opts.low_port = atoi (optarg);
	 if (!(between (opts.low_port, 0, 65536))) {
	    fprintf (stderr, "low port must be between 1 and 65536\n");
	    return (1);
	 }
	 break;
      case 'h':
	 opts.high_port = atoi (optarg);
	 if (!(between (opts.high_port, 0, 65536))) {
	    fprintf (stderr, "high port must be between 1 and 65536\n");
	    return (1);
	 }
	 break;
      case '?':
	 fprintf (stderr, "invalid command line\n");
	 return 1;
      }
   }

   /* 
    * make sure the arguments are sane 
    */
   if (opts.low_port > opts.high_port) {
      fprintf (stderr, "low port must be <= high port\n");
      return 1;
   }
   if (1 > opts.low_port || 1 > opts.high_port) {
      fprintf (stderr, "port numbers must be >= 1");
      return 1;
   }
   if (!opts.target) {
      fprintf (stderr, "target must be specified.\n");
      return (1);
   }

   /* 
    * Fork to capture() and sendsyns() 
    */
   if (0 == (retcode = fork ())) {
      capture ();
   } else if (retcode == -1) {
      fprintf (stderr, " unable to fork ");
      return 1;
   } else {
      sendsyns ();
   }
   return 0;
}
Beispiel #14
0
static bool is_bounded_by_end_points(double a, double b, double c, double d) {
    return between(a, b, d) && between(a, c, d);
}
Beispiel #15
0
/*!
\brief Plays the proper door sfx for doors/gates/secretdoors
\param pi Door item (to call the cItem::playSFX() function of)
\param id Base ID of the door
\param close If true, the door will be closed, else opened
*/
static void doorsfx(pItem pi, uint16_t id, bool close)
{
	static const uint16_t OPENWOOD = 0x00EA;
	static const uint16_t OPENGATE = 0x00EB;
	static const uint16_t OPENSTEEL = 0x00EC;
	static const uint16_t OPENSECRET = 0x00ED;
	static const uint16_t CLOSEWOOD = 0x00F1;
	static const uint16_t CLOSEGATE = 0x00F2;
	static const uint16_t CLOSESTEEL = 0x00F3;
	static const uint16_t CLOSESECRET = 0x00F4;
	
	if ( close ) // Request close door sfx
	{
		// Close wooden / ratan door
		if ( between(id, 0x0695, 0x06C4) || between(id, 0x06D5, 0x06F4) )
			pi->playSFX(CLOSEWOOD);

		// Close gate
		if (	between(id, 0x0839, 0x0848) ||
			between(id, 0x084C, 0x085B) ||
			between(id, 0x0866, 0x0875) )
				pi->playSFX(CLOSEGATE);

		// Close metal
		if ( between(id, 0x0675, 0x0694) || between(id, 0x06C5, 0x06D4) )
			pi->playSFX(CLOSESTEEL);

		// Close secret
		if ( between(x, 0x0314, 0x0365) )
			pi->playSFX(CLOSESECRET);
	} else { // Request open door sfx
		// Open wooden / ratan door
		if ( between(id, 0x0695, 0x06C4) || between(id, 0x06D5, 0x06F4) )
			pi->playSFX(OPENWOOD);

		// Open gate
		if (	between(id, 0x0839, 0x0848) ||
			between(id, 0x084C, 0x085B) ||
			between(id, 0x0866, 0x0875) )
				pi->playSFX(OPENGATE);

		// Open metal
		if ( between(id, 0x0675, 0x0694) || between(id, 0x06C5, 0x06D4) )
			pi->playSFX(OPENSTEEL);

		// Open secret
		if ( between(x, 0x0314, 0x0365) )
			pi->playSFX(OPENSECRET);
	}
}
int intersect ( double xa, double ya, double xb, double yb, double xc, 
  double yc, double xd, double yd )

/******************************************************************************/
/*
  Purpose:

    INTERSECT is true if lines VA:VB and VC:VD intersect.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    05 May 2014

  Author:

    Original C version by Joseph ORourke.
    This C version by John Burkardt.

  Reference:

    Joseph ORourke,
    Computational Geometry in C,
    Cambridge, 1998,
    ISBN: 0521649765,
    LC: QA448.D38.

  Parameters:

    Input, double XA, YA, XB, YB, XC, YC, XD, YD, the X and Y 
    coordinates of the four vertices.

    Output, int INTERSECT, the value of the test.
*/
{
  int value;

  if ( intersect_prop ( xa, ya, xb, yb, xc, yc, xc, yd ) )
  {
    value = 1;
  }
  else if ( between ( xa, ya, xb, yb, xc, yc ) )
  {
    value = 1;
  }
  else if ( between ( xa, ya, xb, yb, xd, yd ) )
  {
    value = 1;
  }
  else if ( between ( xc, yc, xd, yd, xa, ya ) )
  {
    value = 1;
  }
  else if ( between ( xc, yc, xd, yd, xb, yb ) )
  {
    value = 1;
  }
  else
  {
    value = 0;
  }
  return value;
}
Beispiel #17
0
static unsigned int help(struct ip_conntrack *ct,
         		 struct ip_conntrack_expect *exp,
			 struct ip_nat_info *info,
			 enum ip_conntrack_info ctinfo,
			 unsigned int hooknum,
			 struct sk_buff **pskb)
{
	struct iphdr *iph = (*pskb)->nh.iph;
	struct tcphdr *tcph = (void *)iph + iph->ihl*4;
	unsigned int datalen;
	int dir;
	int score;
	struct ip_ct_sc_expect *exp_sc_info = &exp->help.exp_sc_info;

	/* Only mangle things once: original direction in POST_ROUTING
	   and reply direction on PRE_ROUTING. */
	dir = CTINFO2DIR(ctinfo);
	DEBUGP("nat_sc: help()\n");
	
#if 0
	if (!((hooknum == NF_IP_POST_ROUTING && dir == IP_CT_DIR_REPLY)
	      || (hooknum == NF_IP_PRE_ROUTING && dir == IP_CT_DIR_ORIGINAL))) {
#if 1
		DEBUGP("nat_sc: Not touching dir %s at hook %s\n",
		       dir == IP_CT_DIR_ORIGINAL ? "ORIG" : "REPLY",
		       hooknum == NF_IP_POST_ROUTING ? "POSTROUTING"
		       : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING"
		       : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???");
#endif
		return NF_ACCEPT;
	}
#endif

	datalen = (*pskb)->len - iph->ihl * 4 - tcph->doff * 4;
	score = 0;
	LOCK_BH(&ip_sc_lock);
	
	if (exp_sc_info->len) {
		/* If it's in the right range... */
		score += between(exp_sc_info->seq, ntohl(tcph->seq),
				 ntohl(tcph->seq) + datalen);
		score += between(exp_sc_info->seq + exp_sc_info->len,
				 ntohl(tcph->seq),
				 ntohl(tcph->seq) + datalen);
		if (score == 1) {
			/* Half a match?  This means a partial retransmisison.
			   It's a cracker being funky. */
			if (net_ratelimit()) {
				printk("SC_NAT: partial packet %u/%u in %u/%u\n",
				       exp_sc_info->seq, exp_sc_info->len,
				       ntohl(tcph->seq),
				       ntohl(tcph->seq) + datalen);
			}
			UNLOCK_BH(&ip_sc_lock);
			return NF_DROP;
		} else if (score == 2) {
			if (!sc_data_fixup(exp_sc_info, ct, datalen, pskb, ctinfo)) {
				UNLOCK_BH(&ip_sc_lock);
				return NF_DROP;
			}
			/* skb may have been reallocated */
			iph = (*pskb)->nh.iph;
			tcph = (void *)iph + iph->ihl*4;
		}
	}

	UNLOCK_BH(&ip_sc_lock);
	
	DEBUGP("nat_sc: ip_nat_seq_adjust()\n");
	ip_nat_seq_adjust(*pskb, ct, ctinfo);

	return NF_ACCEPT;
}
Beispiel #18
0
bool ends_are_extrema_in_x_or_y(const Cubic& c) {
    return (between(c[0].x, c[1].x, c[3].x) && between(c[0].x, c[2].x, c[3].x))
            || (between(c[0].y, c[1].y, c[3].y) && between(c[0].y, c[2].y, c[3].y));
}
Beispiel #19
0
bool SkDCubic::monotonicInY() const {
    return between(fPts[0].fY, fPts[1].fY, fPts[3].fY)
            && between(fPts[0].fY, fPts[2].fY, fPts[3].fY);
}
Beispiel #20
0
// Intersect the point (x,y) with the set of rectangles.  If the point lies outside of all obstacles, return true.
bool isValidPoint(double x, double y, const std::vector <Rectangle> &obstacles) {
    for (Rectangle rect : obstacles)
        if (between(rect.x, rect.width + rect.x, x) && between(rect.y, rect.height + rect.y, y))
            return false;
    return true;
}
Beispiel #21
0
static inline bool
between(fixed x, double a, double b)
{
  return between(x, fixed(a), fixed(b));
}
Beispiel #22
0
static void ack_received(FRAME frame, int link)
{
    FRAME tempFrame;
    int first, second, third, fourth;

    // PRINT ACKOWLEDGEMENT MESSAGE
    printf("\n\t\t\t\t\tACK RECEIVED\n");
    printf("\t\t\t\t\tIN LINK:%d\n", link);
    printf("\t\t\t\t\tSEQ NO:\t%d\n", frame.seq);

    // ENSURE ACK NUMBER IS BETWEEN ACK EXPECTED AND NEXT FRAME TO SEND
    if (between(ackExpected[link - 1], frame.seq, nextFrameToSend[link - 1]))
    {

        // LOOP UNTIL ACKEXPECTED IS ONE MORE THAN THE SEQNUM OF THE ACK
        while (between(ackExpected[link - 1], frame.seq, nextFrameToSend[link - 1]))
        {
            // STOP THE TIMER FOR THAT FRAME TO PREVENT A TIMEOUT
            CNET_stop_timer(timers[link - 1][ackExpected[link - 1]]);
            // INCREMENT ACKEXPECTED AND DECREASE NUMBER IN WINDOW
            inc(&ackExpected[link - 1]);
            numInWindow[link - 1] -= 1;
        }
    }
    else
    {
        // ERRORS SHOULD ALL BE CAUGHT BEFORE THIS
        // STILL CHECK REGARDLESS, AS A FAILSAFE
        printf("\n\t\t\t\t\tERROR: OUTSIDE WINDOW BOUNDS\n");
    }

    // ENSURE WINDOW SIZE IS VALID AND BUFFER IS NOT EMPTY
    while (numInWindow[link - 1] < MAX_SEQ && numInBuffer[link - 1] > 0)
    {
        // ADD FRAMES FROM THE BUFFER TO THE WINDOW
        printf("\t\t\t\t\tSENDING FRAME FROM BUFFER\n");

        // REMOVE FRAME FROM THE FRONT OF THE BUFFER
        tempFrame = buffer[link - 1][bufferBounds[link - 1][0]];
        inc(&bufferBounds[link - 1][0]);
        numInBuffer[link - 1] -= 1;

        // STORE THE FRAME FROM THE BUFFER IN THE WINDOW
        tempFrame.seq = nextFrameToSend[link - 1];
        window[link - 1][nextFrameToSend[link - 1]] = tempFrame;
        numInWindow[link - 1] += 1;

        // TRANSMIT THE FRAME FROM THE BUFFER (NOW IN THE WINDOW)
        tempFrame.link = get_route(tempFrame.destNode);
        transmit_frame(tempFrame);
        inc(&nextFrameToSend[link - 1]);
    }

    // IF ALL LINK WINDOWS NOT FULL AND ALL BUFFER'S EMPTY
    // THIS KEEPS EFFICIECNY AS HIGH AS POSSIBLE
    first  = ( numInBuffer[0] == 0 ) && ( numInWindow[0] < MAX_SEQ );
    second = ( numInBuffer[1] == 0 ) && ( numInWindow[1] < MAX_SEQ );
    third  = ( numInBuffer[2] == 0 ) && ( numInWindow[2] < MAX_SEQ );
    fourth = ( numInBuffer[3] == 0 ) && ( numInWindow[3] < MAX_SEQ );

    // REENABLE APPLICATION LAYER TO GENERATE MESSAGES AGAIN
    if ( first && second && third && fourth )
    {
        CHECK(CNET_enable_application(ALLNODES));
        for ( int ii = 0; ii < nodeinfo.nlinks; ii++ )
            CNET_set_LED(ii, "green" );
    }

            
    print_buffers(link);
}
Beispiel #23
0
/* extract pixel descriptors (pixel-wise HOG)
*/
float_layers* extract_desc( image_t* _img, const desc_params_t* params, int nt )
{
  // verify parameters
  assert(between(0,params->presmooth_sigma,3));
  assert(between(0,params->mid_smoothing,3));
  assert(between(0,params->post_smoothing,3));
  assert(between(0.05,params->hog_sigmoid,0.8));
  assert(between(0,params->ninth_dim,1));
  assert(between(0,params->norm_pixels,1));
  
  UBYTE_image* img = image_to_arraytype(_img);  // could be optimized but well
  const int npix = img->tx*img->ty;
  //hash_image(img)D(img->tx)D(img->ty)
  
  // pre-smooth image
  assert( params->presmooth_sigma>=0 );
  if( params->presmooth_sigma>0 )
    _smooth_gaussian( img, params->presmooth_sigma, img, nt );
  //hash_image(img)
  
  // extract HOG
  float_layers grad = {NEWA(float,npix*2),img->tx,img->ty,2};
  _compute_grad_101( img, 0, &grad, nt );
  //hash_cube(&grad)
  float_layers* hog = NEW(float_layers);
  *hog = {NEWA(float,9*npix),img->tx,img->ty,8};
  _compute_hog( &grad, 1, hog, nt );
  free(grad.pixels);
  free_image(img);
  //hash_layers(hog)
  
  // mid smoothing
  assert( params->mid_smoothing>=0 );
  if( params->mid_smoothing )
    smooth_hog_gaussian( hog, params->mid_smoothing, nt );
  //hash_layers(hog)
  
  // apply non-linearity
  assert( params->hog_sigmoid>=0 );
  if( params->hog_sigmoid ) {
    float_array hog_ravel = {hog->pixels,npix*hog->tz};
    sigmoid_array( &hog_ravel, params->hog_sigmoid, 0, nt);
  }
  //hash_layers(hog)
  
  // final smoothing
  assert( params->post_smoothing>=0 );
  if( params->post_smoothing )
    smooth_hog_gaussian( hog, params->post_smoothing, nt );
  //hash_layers(hog)
  
  // add ninth dimension and normalize per-pixel
  float* ninth_layer = hog->pixels + hog->tz*npix;
  for(int i=0; i<npix; i++) 
    ninth_layer[i] = params->ninth_dim;
  hog->tz++;
  //hash_layers(hog)
  if( params->norm_pixels )
    norm_layers( hog, 1, nt );
  //hash_layers(hog);D(0)getchar();
  
  return hog;
}
Beispiel #24
0
static void hackToFixPartialCoincidence(const Quadratic& q1, const Quadratic& q2, Intersections& i) {
    // look to see if non-coincident data basically has unsortable tangents

    // look to see if a point between non-coincident data is on the curve
    int cIndex;
    for (int uIndex = 0; uIndex < i.fUsed; ) {
        double bestDist1 = 1;
        double bestDist2 = 1;
        int closest1 = -1;
        int closest2 = -1;
        for (cIndex = 0; cIndex < i.fCoincidentUsed; ++cIndex) {
            double dist = fabs(i.fT[0][uIndex] - i.fCoincidentT[0][cIndex]);
            if (bestDist1 > dist) {
                bestDist1 = dist;
                closest1 = cIndex;
            }
            dist = fabs(i.fT[1][uIndex] - i.fCoincidentT[1][cIndex]);
            if (bestDist2 > dist) {
                bestDist2 = dist;
                closest2 = cIndex;
            }
        }
        _Line ends;
        _Point mid;
        double t1 = i.fT[0][uIndex];
        xy_at_t(q1, t1, ends[0].x, ends[0].y);
        xy_at_t(q1, i.fCoincidentT[0][closest1], ends[1].x, ends[1].y);
        double midT = (t1 + i.fCoincidentT[0][closest1]) / 2;
        xy_at_t(q1, midT, mid.x, mid.y);
        LineParameters params;
        params.lineEndPoints(ends);
        double midDist = params.pointDistance(mid);
        // Note that we prefer to always measure t error, which does not scale,
        // instead of point error, which is scale dependent. FIXME
        if (!approximately_zero(midDist)) {
            ++uIndex;
            continue;
        }
        double t2 = i.fT[1][uIndex];
        xy_at_t(q2, t2, ends[0].x, ends[0].y);
        xy_at_t(q2, i.fCoincidentT[1][closest2], ends[1].x, ends[1].y);
        midT = (t2 + i.fCoincidentT[1][closest2]) / 2;
        xy_at_t(q2, midT, mid.x, mid.y);
        params.lineEndPoints(ends);
        midDist = params.pointDistance(mid);
        if (!approximately_zero(midDist)) {
            ++uIndex;
            continue;
        }
        // if both midpoints are close to the line, lengthen coincident span
        int cEnd = closest1 ^ 1; // assume coincidence always travels in pairs
        if (!between(i.fCoincidentT[0][cEnd], t1, i.fCoincidentT[0][closest1])) {
            i.fCoincidentT[0][closest1] = t1;
        }
        cEnd = closest2 ^ 1;
        if (!between(i.fCoincidentT[0][cEnd], t2, i.fCoincidentT[0][closest2])) {
            i.fCoincidentT[0][closest2] = t2;
        }
        int remaining = --i.fUsed - uIndex;
        if (remaining > 0) {
            memmove(&i.fT[0][uIndex], &i.fT[0][uIndex + 1], sizeof(i.fT[0][0]) * remaining);
            memmove(&i.fT[1][uIndex], &i.fT[1][uIndex + 1], sizeof(i.fT[1][0]) * remaining);
        }
    }
    // if coincident data is subjectively a tiny span, replace it with a single point
    for (cIndex = 0; cIndex < i.fCoincidentUsed; ) {
        double start1 = i.fCoincidentT[0][cIndex];
        double end1 = i.fCoincidentT[0][cIndex + 1];
        _Line ends1;
        xy_at_t(q1, start1, ends1[0].x, ends1[0].y);
        xy_at_t(q1, end1, ends1[1].x, ends1[1].y);
        if (!AlmostEqualUlps(ends1[0].x, ends1[1].x) || AlmostEqualUlps(ends1[0].y, ends1[1].y)) {
            cIndex += 2;
            continue;
        }
        double start2 = i.fCoincidentT[1][cIndex];
        double end2 = i.fCoincidentT[1][cIndex + 1];
        _Line ends2;
        xy_at_t(q2, start2, ends2[0].x, ends2[0].y);
        xy_at_t(q2, end2, ends2[1].x, ends2[1].y);
        // again, approximately should be used with T values, not points FIXME
        if (!AlmostEqualUlps(ends2[0].x, ends2[1].x) || AlmostEqualUlps(ends2[0].y, ends2[1].y)) {
            cIndex += 2;
            continue;
        }
        if (approximately_less_than_zero(start1) || approximately_less_than_zero(end1)) {
            start1 = 0;
        } else if (approximately_greater_than_one(start1) || approximately_greater_than_one(end1)) {
            start1 = 1;
        } else {
            start1 = (start1 + end1) / 2;
        }
        if (approximately_less_than_zero(start2) || approximately_less_than_zero(end2)) {
            start2 = 0;
        } else if (approximately_greater_than_one(start2) || approximately_greater_than_one(end2)) {
            start2 = 1;
        } else {
            start2 = (start2 + end2) / 2;
        }
        i.insert(start1, start2);
        i.fCoincidentUsed -= 2;
        int remaining = i.fCoincidentUsed - cIndex;
        if (remaining > 0) {
            memmove(&i.fCoincidentT[0][cIndex], &i.fCoincidentT[0][cIndex + 2], sizeof(i.fCoincidentT[0][0]) * remaining);
            memmove(&i.fCoincidentT[1][cIndex], &i.fCoincidentT[1][cIndex + 2], sizeof(i.fCoincidentT[1][0]) * remaining);
        }
    }
}
Beispiel #25
0
void SkOpAngle::setSpans() {
    double startT = (*fSpans)[fStart].fT;
    double endT = (*fSpans)[fEnd].fT;
    switch (fVerb) {
    case SkPath::kLine_Verb: {
        SkDLine l = SkDLine::SubDivide(fPts, startT, endT);
        // OPTIMIZATION: for pure line compares, we never need fTangent1.c
        fTangent1.lineEndPoints(l);
        fSide = 0;
        } break;
    case SkPath::kQuad_Verb: {
        SkDQuad& quad = *SkTCast<SkDQuad*>(&fCurvePart);
        quad = SkDQuad::SubDivide(fPts, startT, endT);
        fTangent1.quadEndPoints(quad, 0, 1);
        if (dx() == 0 && dy() == 0) {
            fTangent1.quadEndPoints(quad);
        }
        fSide = -fTangent1.pointDistance(fCurvePart[2]);  // not normalized -- compare sign only
        } break;
    case SkPath::kCubic_Verb: {
 //     int nextC = 2;
        fCurvePart = SkDCubic::SubDivide(fPts, startT, endT);
        fTangent1.cubicEndPoints(fCurvePart, 0, 1);
        if (dx() == 0 && dy() == 0) {
            fTangent1.cubicEndPoints(fCurvePart, 0, 2);
 //         nextC = 3;
            if (dx() == 0 && dy() == 0) {
                fTangent1.cubicEndPoints(fCurvePart, 0, 3);
            }
        }
 //     fSide = -fTangent1.pointDistance(fCurvePart[nextC]);  // compare sign only
 //     if (nextC == 2 && approximately_zero(fSide)) {
 //         fSide = -fTangent1.pointDistance(fCurvePart[3]);
 //     }
        double testTs[4];
        // OPTIMIZATION: keep inflections precomputed with cubic segment?
        int testCount = SkDCubic::FindInflections(fPts, testTs);
        double limitT = endT;
        int index;
        for (index = 0; index < testCount; ++index) {
            if (!between(startT, testTs[index], limitT)) {
                testTs[index] = -1;
            }
        }
        testTs[testCount++] = startT;
        testTs[testCount++] = endT;
        SkTQSort<double>(testTs, &testTs[testCount - 1]);
        double bestSide = 0;
        int testCases = (testCount << 1) - 1;
        index = 0;
        while (testTs[index] < 0) {
            ++index;
        }
        index <<= 1;
        for (; index < testCases; ++index) {
            int testIndex = index >> 1;
            double testT = testTs[testIndex];
            if (index & 1) {
                testT = (testT + testTs[testIndex + 1]) / 2;
            }
            // OPTIMIZE: could avoid call for t == startT, endT
            SkDPoint pt = dcubic_xy_at_t(fPts, testT);
            double testSide = fTangent1.pointDistance(pt);
            if (fabs(bestSide) < fabs(testSide)) {
                bestSide = testSide;
            }
        }
        fSide = -bestSide;  // compare sign only
        } break;
    default:
        SkASSERT(0);
    }
    fUnsortable = dx() == 0 && dy() == 0;
    if (fUnsortable) {
        return;
    }
    SkASSERT(fStart != fEnd);
    int step = fStart < fEnd ? 1 : -1;  // OPTIMIZE: worth fStart - fEnd >> 31 type macro?
    for (int index = fStart; index != fEnd; index += step) {
#if 1
        const SkOpSpan& thisSpan = (*fSpans)[index];
        const SkOpSpan& nextSpan = (*fSpans)[index + step];
        if (thisSpan.fTiny || precisely_equal(thisSpan.fT, nextSpan.fT)) {
            continue;
        }
        fUnsortable = step > 0 ? thisSpan.fUnsortableStart : nextSpan.fUnsortableEnd;
#if DEBUG_UNSORTABLE
        if (fUnsortable) {
            SkPoint iPt = (*CurvePointAtT[fVerb])(fPts, thisSpan.fT);
            SkPoint ePt = (*CurvePointAtT[fVerb])(fPts, nextSpan.fT);
            SkDebugf("%s unsortable [%d] (%1.9g,%1.9g) [%d] (%1.9g,%1.9g)\n", __FUNCTION__,
                    index, iPt.fX, iPt.fY, fEnd, ePt.fX, ePt.fY);
        }
#endif
        return;
#else
        if ((*fSpans)[index].fUnsortableStart) {
            fUnsortable = true;
            return;
        }
#endif
    }
#if 1
#if DEBUG_UNSORTABLE
    SkPoint iPt = (*CurvePointAtT[fVerb])(fPts, startT);
    SkPoint ePt = (*CurvePointAtT[fVerb])(fPts, endT);
    SkDebugf("%s all tiny unsortable [%d] (%1.9g,%1.9g) [%d] (%1.9g,%1.9g)\n", __FUNCTION__,
        fStart, iPt.fX, iPt.fY, fEnd, ePt.fX, ePt.fY);
#endif
    fUnsortable = true;
#endif
}
Beispiel #26
0
bool monotonic_in_y(const Cubic& c) {
    return between(c[0].y, c[1].y, c[3].y) && between(c[0].y, c[2].y, c[3].y);
}
Beispiel #27
0
bool
Util::between(const Pose *pose1, const carmen_ackerman_path_point_t pose2, const carmen_ackerman_path_point_t pose3)
{
	carmen_ackerman_path_point_t p;
	return (between(p, pose1, pose2, pose3));
}
Beispiel #28
0
bool SkDCubic::endsAreExtremaInXOrY() const {
    return (between(fPts[0].fX, fPts[1].fX, fPts[3].fX)
            && between(fPts[0].fX, fPts[2].fX, fPts[3].fX))
            || (between(fPts[0].fY, fPts[1].fY, fPts[3].fY)
            && between(fPts[0].fY, fPts[2].fY, fPts[3].fY));
}
Beispiel #29
0
static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
		u8 type, u8 code, int offset, __be32 info)
{
	const struct ipv6hdr *hdr = (const struct ipv6hdr*)skb->data;
	const struct tcphdr *th = (struct tcphdr *)(skb->data+offset);
	struct ipv6_pinfo *np;
	struct sock *sk;
	int err;
	struct tcp_sock *tp;
	__u32 seq;
	struct net *net = dev_net(skb->dev);

	sk = inet6_lookup(net, &tcp_hashinfo, &hdr->daddr,
			th->dest, &hdr->saddr, th->source, skb->dev->ifindex);

	if (sk == NULL) {
		ICMP6_INC_STATS_BH(net, __in6_dev_get(skb->dev),
				   ICMP6_MIB_INERRORS);
		return;
	}

	if (sk->sk_state == TCP_TIME_WAIT) {
		inet_twsk_put(inet_twsk(sk));
		return;
	}

	bh_lock_sock(sk);
	if (sock_owned_by_user(sk))
		NET_INC_STATS_BH(net, LINUX_MIB_LOCKDROPPEDICMPS);

	if (sk->sk_state == TCP_CLOSE)
		goto out;

	if (ipv6_hdr(skb)->hop_limit < inet6_sk(sk)->min_hopcount) {
		NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
		goto out;
	}

	tp = tcp_sk(sk);
	seq = ntohl(th->seq);
	if (sk->sk_state != TCP_LISTEN &&
	    !between(seq, tp->snd_una, tp->snd_nxt)) {
		NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
		goto out;
	}

	np = inet6_sk(sk);

	if (type == ICMPV6_PKT_TOOBIG) {
		struct dst_entry *dst;

		if (sock_owned_by_user(sk))
			goto out;
		if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
			goto out;

		
		dst = __sk_dst_check(sk, np->dst_cookie);

		if (dst == NULL) {
			struct inet_sock *inet = inet_sk(sk);
			struct flowi6 fl6;

			memset(&fl6, 0, sizeof(fl6));
			fl6.flowi6_proto = IPPROTO_TCP;
			fl6.daddr = np->daddr;
			fl6.saddr = np->saddr;
			fl6.flowi6_oif = sk->sk_bound_dev_if;
			fl6.flowi6_mark = sk->sk_mark;
			fl6.fl6_dport = inet->inet_dport;
			fl6.fl6_sport = inet->inet_sport;
			fl6.flowi6_uid = sock_i_uid(sk);
			security_skb_classify_flow(skb, flowi6_to_flowi(&fl6));

			dst = ip6_dst_lookup_flow(sk, &fl6, NULL, false);
			if (IS_ERR(dst)) {
				sk->sk_err_soft = -PTR_ERR(dst);
				goto out;
			}

		} else
			dst_hold(dst);

		if (inet_csk(sk)->icsk_pmtu_cookie > dst_mtu(dst)) {
			tcp_sync_mss(sk, dst_mtu(dst));
			tcp_simple_retransmit(sk);
		} 
		dst_release(dst);
		goto out;
	}

	icmpv6_err_convert(type, code, &err);

	
	switch (sk->sk_state) {
		struct request_sock *req, **prev;
	case TCP_LISTEN:
		if (sock_owned_by_user(sk))
			goto out;

		req = inet6_csk_search_req(sk, &prev, th->dest, &hdr->daddr,
					   &hdr->saddr, inet6_iif(skb));
		if (!req)
			goto out;

		WARN_ON(req->sk != NULL);

		if (seq != tcp_rsk(req)->snt_isn) {
			NET_INC_STATS_BH(net, LINUX_MIB_OUTOFWINDOWICMPS);
			goto out;
		}

		inet_csk_reqsk_queue_drop(sk, req, prev);
		goto out;

	case TCP_SYN_SENT:
	case TCP_SYN_RECV:  
		if (!sock_owned_by_user(sk)) {
			sk->sk_err = err;
			sk->sk_error_report(sk);		

			tcp_done(sk);
		} else
			sk->sk_err_soft = err;
		goto out;
	}

	if (!sock_owned_by_user(sk) && np->recverr) {
		sk->sk_err = err;
		sk->sk_error_report(sk);
	} else
		sk->sk_err_soft = err;

out:
	bh_unlock_sock(sk);
	sock_put(sk);
}
Beispiel #30
0
bool overlaps(Point p, SDL_Rect r)
{
	return (between(p.x, r.x, r.x+r.w))
		&& (between(p.y, r.y, r.y+r.h));
}