VGboolean polygon_is_closed(struct polygon *p) { VGfloat start[2], end[2]; polygon_vertex(p, 0, start); polygon_vertex(p, p->num_verts - 1, end); return floatsEqual(start[0], end[0]) && floatsEqual(start[1], end[1]); }
Plane::RelativeLocation Plane::relativeLocationOfPoint(const Vector3& point) const { Float f = a*point[0] + b*point[1] + c*point[2] + d; if (f < 0) { return kBelow; } else if (floatsEqual(f, 0.0)) { return kCoincident; } else { return kAbove; } }
static INLINE boolean is_affine(float *matrix) { return floatIsZero(matrix[2]) && floatIsZero(matrix[5]) && floatsEqual(matrix[8], 1); }
bool BodyTracker::CompareToBaseline(const b2Body *body, int32 flag, float32 epsilon) const { const std::string &bodyName = m_bodyNames.find(body)->second; std::map<const b2Body *, SampleVec>::const_iterator it = m_samples.find(body); if (it == m_samples.end()) { m_errors.push_back("Could not find data for body " + bodyName); return false; } const SampleVec &samples = it->second; std::map<const std::string, SampleVec>::const_iterator it2 = m_baselineSamples.find(bodyName); if (it2 == m_baselineSamples.end()) { m_errors.push_back("Could not find baseline data for body " + bodyName); return false; } double printPrecision = 1.0 / pow(10.0f, PRINT_PRECISION); if (epsilon < printPrecision) { std::stringstream strstream; strstream << "Specified epsilon " << std::setprecision(PRINT_PRECISION) << epsilon << " is greater than print precision " << std::setprecision(PRINT_PRECISION) << printPrecision << "\n"; m_errors.push_back(strstream.str()); return false; } // Assume that each sample in each of the two arrays represent the same sample. std::stringstream diffs; const SampleVec &baselineSamples = it2->second; for (size_t i = 0 ; i < samples.size() ; i++ ) { const Sample &sample = samples[i]; const Sample &baselineSample = baselineSamples[i]; if ((flag & TRACK_POSITION) && !vecsEqual(sample.position, baselineSample.position, epsilon)) diffs << "\t\tsample = " << i << ", TRACK_POSITION: (" << sample.position << ") != (" << baselineSample.position << ")\n"; else if ((flag & TRACK_ANGLE) && !floatsEqual(sample.angle, baselineSample.angle, epsilon)) diffs << "\t\tsample = " << i << ", TRACK_ANGLE: " << sample.angle << " != " << baselineSample.angle << "\n"; else if ((flag & TRACK_WORLD_CENTER) && !vecsEqual(sample.worldCenter, baselineSample.worldCenter, epsilon)) diffs << "\t\tsample = " << i << ", TRACK_WORLD_CENTER: (" << sample.worldCenter << ") != (" << baselineSample.worldCenter << ")\n"; else if ((flag & TRACK_LOCAL_CENTER) && !vecsEqual(sample.localCenter, baselineSample.localCenter, epsilon)) diffs << "\t\tsample = " << i << ", TRACK_LOCAL_CENTER: (" << sample.localCenter << ") != (" << baselineSample.localCenter << ")\n"; else if ((flag & TRACK_LINEAR_VELOCITY) && !vecsEqual(sample.linearVelocity, baselineSample.linearVelocity, epsilon)) diffs << "\t\tsample = " << i << ", TRACK_LINEAR_VELOCITY: (" << sample.linearVelocity << ") != (" << baselineSample.linearVelocity << ")\n"; else if ((flag & TRACK_ANGULAR_VELOCITY) && !floatsEqual(sample.angularVelocity, baselineSample.angularVelocity, epsilon)) diffs << "\t\tsample = " << i << ", TRACK_ANGULAR_VELOCITY: " << sample.angularVelocity << " != " << baselineSample.angularVelocity << "\n"; } const std::string diffsStr = diffs.str(); if (diffsStr.empty()) return true; std::stringstream strstream; strstream << "In '" << bodyName << "':\n"; m_errors.push_back(strstream.str() + diffsStr); return false; }
static bool vecsEqual(const b2Vec2 &a, const b2Vec2 &b, float32 epsilon) { return floatsEqual(a.x, b.x, epsilon) && floatsEqual(a.y, b.y, epsilon); }
void renderer_copy_surface(struct renderer *ctx, struct pipe_surface *src, int srcX0, int srcY0, int srcX1, int srcY1, struct pipe_surface *dst, int dstX0, int dstY0, int dstX1, int dstY1, float z, unsigned filter) { struct pipe_context *pipe = ctx->pipe; struct pipe_screen *screen = pipe->screen; struct pipe_sampler_view view_templ; struct pipe_sampler_view *view; struct pipe_box src_box; struct pipe_resource texTemp, *tex; const struct pipe_framebuffer_state *fb = &ctx->g3d.fb; const int srcW = abs(srcX1 - srcX0); const int srcH = abs(srcY1 - srcY0); const int srcLeft = MIN2(srcX0, srcX1); const int srcTop = MIN2(srcY0, srcY1); assert(filter == PIPE_TEX_MIPFILTER_NEAREST || filter == PIPE_TEX_MIPFILTER_LINEAR); if (srcLeft != srcX0) { /* left-right flip */ int tmp = dstX0; dstX0 = dstX1; dstX1 = tmp; } if (srcTop != srcY0) { /* up-down flip */ int tmp = dstY0; dstY0 = dstY1; dstY1 = tmp; } assert(screen->is_format_supported(screen, src->format, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW)); assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW)); assert(screen->is_format_supported(screen, dst->format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET)); /* * XXX for now we're always creating a temporary texture. * Strictly speaking that's not always needed. */ /* create temp texture */ memset(&texTemp, 0, sizeof(texTemp)); texTemp.target = PIPE_TEXTURE_2D; texTemp.format = src->format; texTemp.last_level = 0; texTemp.width0 = srcW; texTemp.height0 = srcH; texTemp.depth0 = 1; texTemp.array_size = 1; texTemp.bind = PIPE_BIND_SAMPLER_VIEW; tex = screen->resource_create(screen, &texTemp); if (!tex) return; u_sampler_view_default_template(&view_templ, tex, tex->format); view = pipe->create_sampler_view(pipe, tex, &view_templ); if (!view) return; u_box_2d_zslice(srcLeft, srcTop, src->u.tex.first_layer, srcW, srcH, &src_box); pipe->resource_copy_region(pipe, tex, 0, 0, 0, 0, /* dest */ src->texture, 0, &src_box); assert(floatsEqual(z, 0.0f)); /* draw */ if (fb->cbufs[0] == dst) { /* transform back to surface coordinates */ dstY0 = dst->height - dstY0; dstY1 = dst->height - dstY1; if (renderer_drawtex_begin(ctx, view)) { renderer_drawtex(ctx, dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0, 0, 0, view->texture->width0, view->texture->height0); renderer_drawtex_end(ctx); } } else { if (renderer_copy_begin(ctx, dst, VG_TRUE, view)) { renderer_copy(ctx, dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0, 0, 0, view->texture->width0, view->texture->height0); renderer_copy_end(ctx); } } }
void testNSTheta() { char *seq1 = "CCCCCAGACGGGGGG"; int pairing1[] = {14,13,12,11,10,-1,-1,-1,-1,-1,4,3,2,1,0}; int fakeBases1[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int numStrands1 = 1; int *breaks1 = NULL; int length1 = strlen(seq1); DBL_TYPE *pairPr1 = (DBL_TYPE *)calloc((length1 + 1) * (length1 + 1), sizeof(DBL_TYPE)); char *seq2 = "ACGUACUGACGCGCGCGCGCCAGACUGCGCGCGCGC"; int pairing2[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,34,33,32,31,30,29,28,27,26,25, -1,-1,-1,-1,-1, 19, 18, 17,16,15,14,13,12,11,10}; int fakeBases2[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int numStrands2 = 2; int breaks2[] = {15}; int length2 = strlen(seq2); DBL_TYPE *pairPr2 = (DBL_TYPE *)calloc((length2 + 1) * (length2 + 1), sizeof(DBL_TYPE)); char *seq3 = "ACGAUCGAUUAGCUAGCUAACGAUCGAUCGAUUCAGACGAUCGAUUAGCUAGCUAACGAUCGAUCGAUUCAGACGAUCGAUUAGCUAGCUAACGAUCGAUCGAUUCAG"; int pairing3[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; int fakeBases3[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int numStrands3 = 1; int *breaks3 = NULL; int length3 = strlen(seq3); DBL_TYPE *pairPr3 = (DBL_TYPE *)calloc((length3 + 1) * (length3 + 1), sizeof(DBL_TYPE)); DBL_TYPE val1 = createNSThetaCase(seq1, pairing1, fakeBases1, numStrands1, breaks1, pairPr1); DBL_TYPE val2 = createNSThetaCase(seq2, pairing2, fakeBases2, numStrands2, breaks2, pairPr2); DBL_TYPE val3 = createNSThetaCase(seq3, pairing3, fakeBases3, numStrands3, breaks3, pairPr3); printf("VAL: %LE:%LE\n", val1, val2); int i; for (i = 0; i < 10; i++) { DBL_TYPE tempVal1a = createNSThetaCase(seq1, pairing1, fakeBases1, numStrands1, breaks1, pairPr1); DBL_TYPE tempVal1b = val1; assert(floatsEqual(tempVal1b, tempVal1a)); DBL_TYPE tempVal2a = createNSThetaCase(seq2, pairing2, fakeBases2, numStrands2, breaks2, pairPr2); DBL_TYPE tempVal2b = val2; assert(floatsEqual(tempVal2b, tempVal2a)); DBL_TYPE tempVal3a = createNSThetaCase(seq3, pairing3, fakeBases3, numStrands3, breaks3, pairPr3); DBL_TYPE tempVal3b = val3; assert(floatsEqual(tempVal3b, tempVal3a)); } }