Document * populate(getc_func getc, void* ctx, int flags) { Cstring line; Document *a = new_Document(); int c; #ifdef PANDOC_HEADER int pandoc = 0; #endif if ( !a ) return 0; a->tabstop = (flags & STD_TABSTOP) ? 4 : TABSTOP; CREATE(line); while ( (c = (*getc)(ctx)) != EOF ) { if ( c == '\n' ) { #ifdef PANDOC_HEADER if ( pandoc != EOF && pandoc < 3 ) { if ( S(line) && (T(line)[0] == '%') ) pandoc++; else pandoc = EOF; } #endif queue(a, &line); S(line) = 0; } else EXPAND(line) = c; } if ( S(line) ) queue(a, &line); DELETE(line); #ifdef PANDOC_HEADER if ( (pandoc == 3) && !(flags & NO_HEADER) ) { /* the first three lines started with %, so we have a header. * clip the first three lines out of content and hang them * off header. */ a->headers = T(a->content); T(a->content) = a->headers->next->next->next; a->headers->next->next->next = 0; snip(a->headers); snip(a->headers->next); snip(a->headers->next->next); } #endif return a; }
/** * Print an EDID monitor descriptor block * * @param monitor The EDID monitor descriptor block * @have_timing Modifies to 1 if the desciptor contains timing info */ static void edid_print_dtd(struct edid_monitor_descriptor *monitor, unsigned int *have_timing) { unsigned char *bytes = (unsigned char *)monitor; struct edid_detailed_timing *timing = (struct edid_detailed_timing *)monitor; if (bytes[0] == 0 && bytes[1] == 0) { if (monitor->type == EDID_MONITOR_DESCRIPTOR_SERIAL) printf("Monitor serial number: %s\n", snip(monitor->data.string)); else if (monitor->type == EDID_MONITOR_DESCRIPTOR_ASCII) printf("Monitor ID: %s\n", snip(monitor->data.string)); else if (monitor->type == EDID_MONITOR_DESCRIPTOR_NAME) printf("Monitor name: %s\n", snip(monitor->data.string)); else if (monitor->type == EDID_MONITOR_DESCRIPTOR_RANGE) printf("Monitor range limits, horizontal sync: " "%d-%d kHz, vertical refresh: " "%d-%d Hz, max pixel clock: " "%d MHz\n", monitor->data.range_data.horizontal_min, monitor->data.range_data.horizontal_max, monitor->data.range_data.vertical_min, monitor->data.range_data.vertical_max, monitor->data.range_data.pixel_clock_max * 10); } else { uint32_t pixclock, h_active, h_blanking, v_active, v_blanking; uint32_t h_total, v_total, vfreq; pixclock = EDID_DETAILED_TIMING_PIXEL_CLOCK(*timing); h_active = EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*timing); h_blanking = EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*timing); v_active = EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*timing); v_blanking = EDID_DETAILED_TIMING_VERTICAL_BLANKING(*timing); h_total = h_active + h_blanking; v_total = v_active + v_blanking; if (v_total * h_total) vfreq = pixclock / (v_total * h_total); else vfreq = 1; /* Error case */ printf("\t%dx%d\%c\t%d Hz (detailed)\n", h_active, v_active, h_active > 1000 ? ' ' : '\t', vfreq); *have_timing = 1; } }
void triangulate(const Polygon& polygon, vector<Vector2D>& triangles) { const vector<Vector2D>& contour = polygon.points; // allocate and initialize list of vertices in polygon int n = contour.size(); if ( n < 3 ) return; int* V = new int[n]; // we want a counter-clockwise polygon in V if ( 0.0f < area(contour) ) { for (int v=0; v<n; v++) V[v] = v; } else { for(int v=0; v<n; v++) V[v] = (n-1)-v; } int nv = n; // remove nv-2 Vertices, creating 1 triangle every time int count = 2*nv; // error detection for(int m = 0, v = nv - 1; nv > 2;) { // if we loop, it is probably a non-simple polygon if (0 >= (count--)) { // Triangulate: ERROR - probable bad polygon! return; } // three consecutive vertices in current polygon, <u,v,w> int u = v ; if (nv <= u) u = 0; // prev v = u + 1 ; if (nv <= v) v = 0; // new v int w = v + 1 ; if (nv <= w) w = 0; // next if ( snip(contour,u,v,w,nv,V) ) { int a,b,c,s,t; // true names of the vertices a = V[u]; b = V[v]; c = V[w]; // output Triangle triangles.push_back( contour[a] ); triangles.push_back( contour[b] ); triangles.push_back( contour[c] ); m++; // remove v from remaining polygon for( s = v, t = v + 1; t < nv; s++, t++) V[s] = V[t]; nv--; // resest error detection counter count = 2 * nv; } } delete[] V; }
bool EyeCalibration::triangulate(CalibrationPointVector &contour, CalibrationPointVector &result) { /* allocate and initialize list of Vertices in polygon */ int n = contour.size(); if ( n < 3 ) return false; int *V = new int[n]; /* we want a counter-clockwise polygon in V */ if ( 0.0f < area(contour) ) for (int v=0; v<n; v++) V[v] = v; else for(int v=0; v<n; v++) V[v] = (n-1)-v; int nv = n; /* remove nv-2 Vertices, creating 1 triangle every time */ int count = 2*nv; /* error detection */ for(int m=0, v=nv-1; nv>2; ) { /* if we loop, it is probably a non-simple polygon */ if (0 >= (count--)) { //** Triangulate: ERROR - probable bad polygon! return false; } /* three consecutive vertices in current polygon, <u,v,w> */ int u = v ; if (nv <= u) u = 0; /* previous */ v = u+1; if (nv <= v) v = 0; /* new v */ int w = v+1; if (nv <= w) w = 0; /* next */ if ( snip(contour,u,v,w,nv,V) ) { int a,b,c,s,t; /* true names of the vertices */ a = V[u]; b = V[v]; c = V[w]; /* output Triangle */ result.push_back( contour[a] ); result.push_back( contour[b] ); result.push_back( contour[c] ); m++; /* remove v from remaining polygon */ for(s=v,t=v+1;t<nv;s++,t++) V[s] = V[t]; nv--; /* resest error detection counter */ count = 2*nv; } } delete V; return true; }
/** \brief Consume bytes and parse shoutcast header \returns number of bytes consumed */ int ShoutCastResponse::fillResponse(const char *s, int l) { QByteArray d(s, l); int result = 0; // check each line for (;;) { int pos = d.indexOf("\r"); if (pos <= 0) break; // Extract the line QByteArray snip(d.data(), pos + 1); d.remove(0, pos + 2); result += pos + 2; if (snip.left(4) == "ICY ") { int space = snip.indexOf(' '); m_data["protocol"] = "ICY"; QString tmp = snip.mid(space).simplified(); int second_space = tmp.indexOf(' '); if (second_space > 0) m_data["status"] = tmp.left(second_space); else m_data["status"] = tmp; } else if (snip.left(7) == "HTTP/1.") { int space = snip.indexOf(' '); m_data["protocol"] = snip.left(space); QString tmp = snip.mid(space).simplified(); int second_space = tmp.indexOf(' '); if (second_space > 0) m_data["status"] = tmp.left(second_space); else m_data["status"] = tmp; } else if (snip.left(9).toLower() == "location:") { m_data["location"] = snip.mid(9).trimmed(); } else if (snip.left(13).toLower() == "content-type:") { m_data["content-type"] = snip.mid(13).trimmed(); } else if (snip.left(4) == "icy-") { int pos = snip.indexOf(':'); QString key = snip.left(pos); m_data[key.toAscii()] = snip.mid(pos+1).trimmed(); } } return result; }
void TGen::Engine::EarClippingTriangulator::process(std::vector<unsigned int> & indices) { const int n = points.size(); if (n < 3) return; int *V = new int[n]; if (0.0f < area()) { for (int v = 0; v < n; v++) V[v] = v; } else { for (int v = 0; v < n; v++) V[v] = (n - 1) - v; } int nv = n; int count = 2 * nv; for (int m = 0, v = nv - 1; nv > 2;) { if (0 >= (count--)) return; int u = v; if (nv <= u) u = 0; v = u + 1; if (nv <= v) v = 0; int w = v + 1; if (nv <= w) w = 0; if (snip(u, v, w, nv, V)) { int a, b, c, s, t; a = V[u]; b = V[v]; c = V[w]; indices.push_back(a); indices.push_back(b); indices.push_back(c); m++; for (s = v, t = v + 1; t < nv; s++, t++) V[s] = V[t]; nv--; count = 2 * nv; } } delete V; }
bool Triangulator::triangulateConcave(const he::PrimitiveList<vec2>& vertices, he::PrimitiveList<uint32>& indices) { int n = (int)vertices.size(); int* V = HENewArray(int, n); // TODO: seeb cache this buffer as a member, enlarge if needed if ( 0.0f < calculateArea(vertices) ) for (int v=0; v<n; v++) V[v] = v; else for(int v=0; v<n; v++) V[v] = (n-1)-v; int nv = n; int count = 2*nv; for(int m=0, v=nv-1; nv>2; ) { if (0 >= (count--)) { HEDeleteArray(V); return false; } int u = v ; if (nv <= u) u = 0; v = u+1; if (nv <= v) v = 0; int w = v+1; if (nv <= w) w = 0; if ( snip(vertices,u,v,w,nv,V) ) { int a,b,c,s,t; a = V[u]; b = V[v]; c = V[w]; indices.add(a); indices.add(c); indices.add(b); m++; for(s=v,t=v+1;t<nv;s++,t++) V[s] = V[t]; nv--; count = 2*nv; } } HEDeleteArray(V); return true; }
static bfd_boolean bfd_cache_delete (bfd *abfd) { bfd_boolean ret; if (fclose ((FILE *) abfd->iostream) == 0) ret = TRUE; else { ret = FALSE; bfd_set_error (bfd_error_system_call); } snip (abfd); abfd->iostream = NULL; --open_files; return ret; }
static FILE * bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag) { bfd *orig_bfd = abfd; if ((abfd->flags & BFD_IN_MEMORY) != 0) abort (); while (abfd->my_archive != NULL && !bfd_is_thin_archive (abfd->my_archive)) abfd = abfd->my_archive; if (abfd->iostream != NULL) { /* Move the file to the start of the cache. */ if (abfd != bfd_last_cache) { snip (abfd); insert (abfd); } return (FILE *) abfd->iostream; } if (flag & CACHE_NO_OPEN) return NULL; if (bfd_open_file (abfd) == NULL) ; else if (!(flag & CACHE_NO_SEEK) && _bfd_real_fseek ((FILE *) abfd->iostream, abfd->where, SEEK_SET) != 0 && !(flag & CACHE_NO_SEEK_ERROR)) bfd_set_error (bfd_error_system_call); else return (FILE *) abfd->iostream; /* xgettext:c-format */ _bfd_error_handler (_("reopening %B: %s\n"), orig_bfd, bfd_errmsg (bfd_get_error ())); return NULL; }
// Original comment: // Triangulation happens in 2d. We could inverse transform the polygon around the normal direction, or we just use the two // most signficant axes. Here we find the two longest axes and use them to triangulate. Inverse transforming them would // introduce more doubling point error and isn't worth it. // // SC says: // This doesn't work: the vertices can be collinear when projected onto the plane of the two longest axes of the bounding box. // Example (from real data): // // v[0] = (-13.7199, 4.45725, -8.00059) // v[1] = (-0.115787, 12.3116, -4.96109) // v[2] = (0.88992, 12.8922, -3.80342) // v[3] = (-0.115787, 12.3116, -2.64576) // v[4] = (-13.7199, 4.45725, 0.393742) // v[5] = (-13.7199, 4.45725, -0.856258) // v[6] = (-12.5335, 5.14221, -3.80342) // v[7] = (-13.7199, 4.45725, -6.75059) // // Instead, we will project onto the plane of the polygon. long Polygon3::triangulate(Array<long> & tri_indices, Real epsilon) const { if (epsilon < 0) epsilon = Math::eps<Real>(); if (vertices.size() < 3) { tri_indices.clear(); } else if (vertices.size() == 3) { tri_indices.resize(3); tri_indices[0] = vertices[0].index; tri_indices[1] = vertices[1].index; tri_indices[2] = vertices[2].index; } else if (vertices.size() > 3) { tri_indices.clear(); size_t n = vertices.size(); proj_vertices.resize(n); Vector3 normal = computeNormal(); Matrix3 basis = Math::orthonormalBasis(normal); Vector3 axis0 = basis.col(0); Vector3 axis1 = basis.col(1); Vector3 v0 = vertices[0].position; // a reference point for the plane of the polygon for (size_t i = 0; i < n; ++i) { Vector3 v = vertices[i].position - v0; proj_vertices[i] = Vector2(v.dot(axis0), v.dot(axis1)); } Array<size_t> indices(n); bool flipped = false; if (projArea() > 0) { for (size_t v = 0; v < n; ++v) indices[v] = v; } else { for (size_t v = 0; v < n; ++v) indices[v] = (n - 1) - v; flipped = true; } size_t nv = n; size_t count = 2 * nv; for (size_t v = nv - 1; nv > 2; ) { if ((count--) <= 0) break; size_t u = v; if (nv <= u) u = 0; v = u + 1; if (nv <= v) v = 0; size_t w = v + 1; if (nv <= w) w = 0; if (snip(u, v, w, nv, indices, epsilon)) { size_t a = indices[u]; size_t b = indices[v]; size_t c = indices[w]; if (flipped) { tri_indices.push_back(vertices[c].index); tri_indices.push_back(vertices[b].index); tri_indices.push_back(vertices[a].index); } else { tri_indices.push_back(vertices[a].index); tri_indices.push_back(vertices[b].index); tri_indices.push_back(vertices[c].index); } size_t s = v, t = v + 1; for ( ; t < nv; ++s, ++t) indices[s] = indices[t]; nv--; count = 2 * nv; } } } return (long)tri_indices.size() / 3; }
bool Triangulate::triangulate(const Vector<Vector2> &contour, Vector<int> &result) { /* allocate and initialize list of Vertices in polygon */ int n = contour.size(); if (n < 3) return false; Vector<int> V; V.resize(n); /* we want a counter-clockwise polygon in V */ if (0.0 < get_area(contour)) for (int v = 0; v < n; v++) V.write[v] = v; else for (int v = 0; v < n; v++) V.write[v] = (n - 1) - v; bool relaxed = false; int nv = n; /* remove nv-2 Vertices, creating 1 triangle every time */ int count = 2 * nv; /* error detection */ for (int v = nv - 1; nv > 2;) { /* if we loop, it is probably a non-simple polygon */ if (0 >= (count--)) { if (relaxed) { //** Triangulate: ERROR - probable bad polygon! return false; } else { // There may be aligned vertices that the strict // checks prevent from triangulating. In this situation // we are better off adding flat triangles than // failing, so we relax the checks and try one last // round. // Only relaxing the constraints as a last resort avoids // degenerate triangles when they aren't necessary. count = 2 * nv; relaxed = true; } } /* three consecutive vertices in current polygon, <u,v,w> */ int u = v; if (nv <= u) u = 0; /* previous */ v = u + 1; if (nv <= v) v = 0; /* new v */ int w = v + 1; if (nv <= w) w = 0; /* next */ if (snip(contour, u, v, w, nv, V, relaxed)) { int a, b, c, s, t; /* true names of the vertices */ a = V[u]; b = V[v]; c = V[w]; /* output Triangle */ result.push_back(a); result.push_back(b); result.push_back(c); /* remove v from remaining polygon */ for (s = v, t = v + 1; t < nv; s++, t++) V.write[s] = V[t]; nv--; /* reset error detection counter */ count = 2 * nv; } } return true; }
// Original comment: // Triangulation happens in 2d. We could inverse transform the polygon around the normal direction, or we just use the two // most signficant axes. Here we find the two longest axes and use them to triangulate. Inverse transforming them would // introduce more doubling point error and isn't worth it. // // SC says: // This doesn't work: the vertices can be collinear when projected onto the plane of the two longest axes of the bounding box. // Example (from real data): // // v[0] = (-13.7199, 4.45725, -8.00059) // v[1] = (-0.115787, 12.3116, -4.96109) // v[2] = (0.88992, 12.8922, -3.80342) // v[3] = (-0.115787, 12.3116, -2.64576) // v[4] = (-13.7199, 4.45725, 0.393742) // v[5] = (-13.7199, 4.45725, -0.856258) // v[6] = (-12.5335, 5.14221, -3.80342) // v[7] = (-13.7199, 4.45725, -6.75059) // // Instead, we will project onto the plane of the polygon. long Polygon3::triangulate(TheaArray<long> & tri_indices) const { if (vertices.size() < 3) { tri_indices.clear(); } else if (vertices.size() == 3) { tri_indices.resize(3); tri_indices[0] = vertices[0].index; tri_indices[1] = vertices[1].index; tri_indices[2] = vertices[2].index; } else if (vertices.size() > 3) { tri_indices.clear(); array_size_t n = vertices.size(); proj_vertices.resize(n); Vector3 normal = getNormal(); Vector3 axis0, axis1; normal.createOrthonormalBasis(axis0, axis1); Vector3 v0 = vertices[0].position; // a reference point for the plane of the polygon for (array_size_t i = 0; i < n; ++i) { Vector3 v = vertices[i].position - v0; proj_vertices[i] = Vector2(v.dot(axis0), v.dot(axis1)); } TheaArray<array_size_t> indices(n); bool flipped = false; if (projArea() > 0) { for (array_size_t v = 0; v < n; ++v) indices[v] = v; } else { for (array_size_t v = 0; v < n; ++v) indices[v] = (n - 1) - v; flipped = true; } array_size_t nv = n; array_size_t count = 2 * nv; for (array_size_t v = nv - 1; nv > 2; ) { if ((count--) <= 0) break; array_size_t u = v; if (nv <= u) u = 0; v = u + 1; if (nv <= v) v = 0; array_size_t w = v + 1; if (nv <= w) w = 0; if (snip(u, v, w, nv, indices)) { array_size_t a = indices[u]; array_size_t b = indices[v]; array_size_t c = indices[w]; if (flipped) { tri_indices.push_back(vertices[c].index); tri_indices.push_back(vertices[b].index); tri_indices.push_back(vertices[a].index); } else { tri_indices.push_back(vertices[a].index); tri_indices.push_back(vertices[b].index); tri_indices.push_back(vertices[c].index); } array_size_t s = v, t = v + 1; for ( ; t < nv; ++s, ++t) indices[s] = indices[t]; nv--; count = 2 * nv; } } } return (long)tri_indices.size() / 3; }