int main() { double xp[1000],yp[1000] ; int n,q ; double P[2] ; swidth = 700 ; sheight = 700 ; G_init_graphics(swidth, sheight) ; G_rgb(0,0,0) ; G_clear() ; G_rgb(1,0,0) ; n = click_and_save(xp,yp) ; G_rgb(0,1,0) ; G_fill_polygon(xp,yp,n) ; while(1==1){ G_wait_click(P) ; if(P[1] < 40){ break; } int r = in_out(xp,yp,n,P); if(r==1){ G_rgb(1,0,0); }else{ G_rgb(0,0,1) ; } G_fill_circle(P[0],P[1],2) ; } q = G_wait_key() ; }
void TempMotifCounter::Count3TEdge2Node(int u, int v, double delta, Counter3D& counts) { // Sort event list by time TVec<TIntPair> combined; AddStarEdges(combined, u, v, 0); AddStarEdges(combined, v, u, 1); combined.Sort(); // Get the counts ThreeTEdgeMotifCounter counter(2); TIntV in_out(combined.Len()); TIntV timestamps(combined.Len()); for (int k = 0; k < combined.Len(); k++) { in_out[k] = combined[k].Dat; timestamps[k] = combined[k].Key; } counter.Count(in_out, timestamps, delta, counts); }
void genCode() { DefNodePtr cursouce = sourcedefs; int mainNo; while (cursouce != NULL) { if (cursouce->sort == DEF_FUNC) { if (strcmp(cursouce->sym->name, "main")==0) { if (cursouce->sym->nParam == 0) { mainNo = cursouce->sym->no; } else { fprintf(stderr, "main()関数のnParamが0ではありません\n"); } } } cursouce = cursouce->next; } fprintf(af, " .text\n"); fprintf(af, "CRT0: ld16 #0xFFE\n"); fprintf(af, " mv sp, acc\n"); fprintf(af, " call F%04d\n", mainNo); fprintf(af, " halt\n"); fprintf(af, " .data\n"); fprintf(af, "_FP: .space 1\n"); genCodeGlobals(); fprintf(af, " .text\n"); genCodeFuncs(); in_out(); fprintf(af, " .const 0xfff\n"); fprintf(af, " .word CRT0\n"); }
void polygon2_clip(polygon2_t* poly, polygon2_t* other) { // This implementation is based on that shown in Chapter 7.6.1 of // Joseph O'Rourke's _Computational_Geometry_In_C_. int a = 0, b = 0, aa = 0, ba = 0; int n = poly->num_vertices, m = other->num_vertices; polygon2_inout_t inflag = UNKNOWN; static point2_t origin = {.x = 0.0, .y = 0.0}; point2_t p0; // First point. // We'll store the coordinates of the vertices of the // clipped polygon here. real_slist_t* xlist = real_slist_new(); real_slist_t* ylist = real_slist_new(); do { // Computations of key variables. int a1 = (a + n - 1) % n; int b1 = (b + m - 1) % m; int aa = poly->ordering[a]; int aa1 = poly->ordering[a1]; int bb = poly->ordering[b]; int bb1 = poly->ordering[b1]; point2_t* Pa = &poly->vertices[aa]; point2_t* Pa1 = &poly->vertices[aa1]; point2_t* Qb = &other->vertices[bb]; point2_t* Qb1 = &other->vertices[bb1]; point2_t A, B; A.x = Pa1->x - Pa->x; A.y = Pa1->y - Pa->y; B.x = Qb1->x - Qb->x; B.y = Qb1->y - Qb->y; int cross = SIGN(triangle_area(&origin, &A, &B)); int aHB = SIGN(triangle_area(Qb1, Qb, Pa)); int bHA = SIGN(triangle_area(Pa1, Pa, Qb)); // If A and B intersect, update inflag. point2_t p; char code = seg_set_int(Pa1, Pa, Qb1, Qb, &p); if ((code == '1') || (code == 'v')) { if ((inflag == UNKNOWN) && (real_slist_empty(xlist))) { aa = ba = 0; p0.x = p.x; p0.y = p.y; real_slist_append(xlist, p0.x); real_slist_append(ylist, p0.y); } inflag = in_out(&p, inflag, aHB, bHA, xlist, ylist); } // Advance rules. else if (cross >= 0) { if (bHA > 0) a = advance(a, &aa, n, (inflag == PIN), Pa, xlist, ylist); else b = advance(b, &ba, m, (inflag == QIN), Qb, xlist, ylist); } else // if (cross < 0) { if (aHB > 0) b = advance(b, &ba, m, (inflag == QIN), Qb, xlist, ylist); else a = advance(a, &aa, n, (inflag == PIN), Pa, xlist, ylist); } } while (((aa < n) || (ba < m)) && (aa < 2*n) && (ba < 2*m)); // Replace this polygon with its clipped version. ASSERT(xlist->size > 0); ASSERT(xlist->size == ylist->size); if (xlist->size > poly->num_vertices) poly->vertices = polymec_realloc(poly->vertices, sizeof(point2_t)*xlist->size); poly->num_vertices = xlist->size; for (int i = 0; i < xlist->size; ++i) { // FIXME: Verify! poly->vertices[i].x = real_slist_pop(xlist, NULL); poly->vertices[i].y = real_slist_pop(ylist, NULL); } polygon2_compute_area(poly); // Clean up. real_slist_free(xlist); real_slist_free(ylist); }
void GraphTest::iterTest() { { TestGraph g_big(1200, 9540, true, GRAPH_REPR); TestGraph::VertexIterator vi; int i = 0; for(vi = g_big.vertexBegin(); vi != g_big.vertexEnd(); ++vi, ++i) (*vi)->setData(65536); assert(i == 1200); TestGraph::EdgeIterator ei; i = 0; for(ei = g_big.edgeBegin(); ei != g_big.edgeEnd(); ++ei, ++i) (*ei)->setData(131052); assert(i == 9540); } TestGraph in_out(0, true, GRAPH_REPR); Vertex_t *v1 = in_out.insertVertex(); Vertex_t *v2 = in_out.insertVertex(); Vertex_t *v3 = in_out.insertVertex(); Vertex_t *v4 = in_out.insertVertex(); Vertex_t *v5 = in_out.insertVertex(); Vertex_t *v6 = in_out.insertVertex(); Vertex_t *v7 = in_out.insertVertex(); Vertex_t *v8 = in_out.insertVertex(); Vertex_t *v9 = in_out.insertVertex(); // for outgoing e-iter in_out.insertEdge(v1, v2)->setData(12); in_out.insertEdge(v1, v7)->setData(17); in_out.insertEdge(v1, v5)->setData(15); in_out.insertEdge(v1, v9)->setData(19); in_out.insertEdge(v1, v4)->setData(14); in_out.insertEdge(v1, v6)->setData(16); in_out.insertEdge(v1, v1)->setData(11); // dummy in_out.insertEdge(v2, v3)->setData(23); in_out.insertEdge(v7, v6)->setData(76); in_out.insertEdge(v8, v6)->setData(86); in_out.insertEdge(v5, v3)->setData(53); in_out.insertEdge(v6, v2)->setData(62); in_out.insertEdge(v4, v4)->setData(44); in_out.insertEdge(v5, v4)->setData(54); in_out.insertEdge(v7, v7)->setData(77); in_out.insertEdge(v7, v7); in_out.insertEdge(v7, v2)->setData(72); in_out.insertEdge(v4, v6)->setData(46); in_out.insertEdge(v7, v4)->setData(74); in_out.insertEdge(v3, v8)->setData(38); // for incoming e-iter in_out.insertEdge(v2, v9)->setData(28); in_out.insertEdge(v5, v9)->setData(59); in_out.insertEdge(v8, v9)->setData(89); in_out.insertEdge(v3, v9)->setData(39); in_out.insertEdge(v4, v9)->setData(49); in_out.insertEdge(v9, v9)->setData(99); assert(in_out.vertexCount() == 9); assert(in_out.edgeCount() == 25); int i = 0; TestGraph::EdgeIterator ei2; for(ei2 = in_out.edgeBegin(); ei2 != in_out.edgeEnd(); ++ei2, ++i) (*ei2)->getData(); assert(i == 25); i = 0; TestGraph::OutgoingEdgeIterator oi; for(oi = in_out.outgoingEdgeBegin(v1); oi != in_out.outgoingEdgeEnd(v1); ++oi, ++i) (*oi)->setWeight(3948212); assert(i == 7); i = 0; TestGraph::IncomingEdgeIterator ii; for(ii = in_out.incomingEdgeBegin(v9); ii != in_out.incomingEdgeEnd(v9); ++ii, ++i) (*ii)->setData(4987935); assert(i == 7); //test loop TestGraph g_small(3, 6, false, GRAPH_REPR); i = 0; TestGraph::VertexIterator vii = g_small.vertexBegin(); TestGraph::OutgoingEdgeIterator oii; for(oii = g_small.outgoingEdgeBegin(*vii); oii != g_small.outgoingEdgeEnd(*vii); ++oii, ++i) (*oii)->setWeight(3948212); assert(i == 3); }
#if (BOOST_PARAMETER_MAX_ARITY < 4) #error Define BOOST_PARAMETER_MAX_ARITY as 4 or greater. #endif #if !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) && \ (BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY < 5) #error Define BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \ as 5 or greater. #endif #include <boost/parameter/name.hpp> namespace test { BOOST_PARAMETER_NAME((_lrc0, kw) in(lrc0)) BOOST_PARAMETER_NAME((_lr0, kw) in_out(lr0)) BOOST_PARAMETER_NAME((_rrc0, kw) in(rrc0)) #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) BOOST_PARAMETER_NAME((_rr0, kw) consume(rr0)) #else BOOST_PARAMETER_NAME((_rr0, kw) rr0) #endif } // namespace test #include <boost/parameter/preprocessor.hpp> #include <boost/parameter/value_type.hpp> #include <boost/core/lightweight_test.hpp> #include <boost/type_traits/is_scalar.hpp> #include <boost/type_traits/remove_const.hpp> #include <boost/type_traits/remove_reference.hpp> #include "evaluate_category.hpp"