25 #include "chipmunk_types.h" 40 cpBB bb = {l, b, r, t};
48 return cpBBNew(c.x - hw, c.y - hh, c.x + hw, c.y + hh);
60 return (a.l <= b.r && b.l <= a.r && a.b <= b.t && b.b <= a.t);
66 return (bb.l <= other.l && bb.r >= other.r && bb.b <= other.b && bb.t >= other.t);
72 return (bb.l <= v.x && bb.r >= v.x && bb.b <= v.y && bb.t >= v.y);
105 return (bb.r - bb.l)*(bb.t - bb.b);
117 cpFloat idx = 1.0f/(b.x - a.x);
119 #pragma warning(disable: 4056) 121 cpFloat tx1 = (bb.l == a.x ? -INFINITY : (bb.l - a.x)*idx);
122 cpFloat tx2 = (bb.r == a.x ? INFINITY : (bb.r - a.x)*idx);
126 cpFloat idy = 1.0f/(b.y - a.y);
127 cpFloat ty1 = (bb.b == a.y ? -INFINITY : (bb.b - a.y)*idy);
128 cpFloat ty2 = (bb.t == a.y ? INFINITY : (bb.t - a.y)*idy);
130 #pragma warning(default: 4056) 135 if(tymin <= txmax && txmin <= tymax){
139 if(0.0 <= max && min <= 1.0)
return cpfmax(min, 0.0);
163 cpFloat modx = cpfmod(v.x - bb.l, dx);
164 cpFloat x = (modx > 0.0f) ? modx : modx + dx;
167 cpFloat mody = cpfmod(v.y - bb.b, dy);
168 cpFloat y = (mody > 0.0f) ? mody : mody + dy;
170 return cpv(x + bb.l, y + bb.b);
static cpBB cpBBMerge(const cpBB a, const cpBB b)
Returns a bounding box that holds both bounding boxes.
Definition: cpBB.h:76
static cpBB cpBBOffset(const cpBB bb, const cpVect v)
Returns a bounding box offseted by v.
Definition: cpBB.h:175
static cpBB cpBBNew(const cpFloat l, const cpFloat b, const cpFloat r, const cpFloat t)
Convenience constructor for cpBB structs.
Definition: cpBB.h:38
static cpBool cpBBIntersects(const cpBB a, const cpBB b)
Returns true if a and b intersect.
Definition: cpBB.h:58
static cpFloat cpfabs(cpFloat f)
Return the absolute value of a cpFloat.
Definition: chipmunk_types.h:152
unsigned char cpBool
Chipmunk's boolean type.
Definition: chipmunk_types.h:199
static cpVect cpBBWrapVect(const cpBB bb, const cpVect v)
Wrap a vector to a bounding box.
Definition: cpBB.h:160
static cpFloat cpfmin(cpFloat a, cpFloat b)
Return the min of two cpFloats.
Definition: chipmunk_types.h:146
static cpBool cpBBContainsBB(const cpBB bb, const cpBB other)
Returns true if other lies completely within bb.
Definition: cpBB.h:64
static cpVect cpBBCenter(cpBB bb)
Returns the center of a bounding box.
Definition: cpBB.h:97
static cpBB cpBBNewForCircle(const cpVect p, const cpFloat r)
Constructs a cpBB for a circle with the given position and radius.
Definition: cpBB.h:52
struct cpBB cpBB
Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
static cpVect cpBBClampVect(const cpBB bb, const cpVect v)
Clamp a vector to a bounding box.
Definition: cpBB.h:153
static cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max)
Clamp f to be between min and max.
Definition: chipmunk_types.h:158
double cpFloat
Chipmunk's floating point type.
Definition: chipmunk_types.h:83
static cpBB cpBBNewForExtents(const cpVect c, const cpFloat hw, const cpFloat hh)
Constructs a cpBB centered on a point with the given extents (half sizes).
Definition: cpBB.h:46
Definition: chipmunk_types.h:271
static cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t)
Linearly interpolate between v1 and v2.
Definition: cpVect.h:140
static cpFloat cpfmax(cpFloat a, cpFloat b)
Return the max of two cpFloats.
Definition: chipmunk_types.h:140
static cpBB cpBBExpand(const cpBB bb, const cpVect v)
Returns a bounding box that holds both bb and v.
Definition: cpBB.h:86
static cpVect cpv(const cpFloat x, const cpFloat y)
Convenience constructor for cpVect structs.
Definition: cpVect.h:35
static cpBool cpBBContainsVect(const cpBB bb, const cpVect v)
Returns true if bb contains v.
Definition: cpBB.h:70
static cpFloat cpBBSegmentQuery(cpBB bb, cpVect a, cpVect b)
Returns the fraction along the segment query the cpBB is hit. Returns INFINITY if it doesn't hit...
Definition: cpBB.h:115
static cpFloat cpBBMergedArea(cpBB a, cpBB b)
Merges a and b and returns the area of the merged bounding box.
Definition: cpBB.h:109
Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
Definition: cpBB.h:33
static cpFloat cpBBArea(cpBB bb)
Returns the area of the bounding box.
Definition: cpBB.h:103
static cpBool cpBBIntersectsSegment(cpBB bb, cpVect a, cpVect b)
Return true if the bounding box intersects the line segment with ends a and b.
Definition: cpBB.h:146