int is_in_poly(int x, int y) { struct coef ray = {0, 1, -y}; if (crossings(x, y, ray) % 2) return 1; return 0; }
static void globalopt(Agraph_t *root) { Agraph_t *g; rank_t *glob; g = GD_model(root); glob = globalize(root,g); GD_rank(g) = glob; fprintf(stderr,"%s: %d crossings\n",root->name,crossings(g)); }
static void savebest(graph_t *g) { int nc; Agnode_t *n; nc = crossings(g); if (nc < GD_bestcrossings(g)) { for (n = agfstnode(g); n; n = agnxtnode(g,n)) ND_saveorder(n) = ND_order(n); GD_bestcrossings(g) = nc; GD_lastwin(g) = GD_pass(g); } }
void SplitHeuristic::recCall(Level &L, int low, int high) { if (high <= low) return; const Hierarchy &H = L.hierarchy(); CrossingsMatrix &crossings = *m_cm; int up = high, down = low; // chooses L[low] as pivot int i; for (i = low+1; i <= high; i++) { if (crossings(i,low) < crossings(low,i)) buffer[down++] = L[i]; } // use two for-loops in order to keep the number of swaps low for (i = high; i >= low+1; i--) { if (crossings(i,low) >= crossings(low,i)) buffer[up--] = L[i]; } buffer[down] = L[low]; for (i = low; i < high; i++) { int j = H.pos(buffer[i]); if (i != j) { L.swap(i,j); crossings.swap(i,j); } } recCall(L,low,down-1); recCall(L,up+1,high); }
static bool try_get_intersect_point_with_item_recursive(Geom::PathVector& conn_pv, SPItem* item, const Geom::Affine& item_transform, double& intersect_pos) { double initial_pos = intersect_pos; // if this is a group... if (SP_IS_GROUP(item)) { SPGroup* group = SP_GROUP(item); // consider all first-order children double child_pos = 0.0; std::vector<SPItem*> g = sp_item_group_item_list(group); for (std::vector<SPItem*>::const_iterator i = g.begin();i!=g.end();i++) { SPItem* child_item = *i; try_get_intersect_point_with_item_recursive(conn_pv, child_item, item_transform * child_item->transform, child_pos); if (intersect_pos < child_pos) intersect_pos = child_pos; } return intersect_pos != initial_pos; } // if this is not a shape, nothing to be done if (!SP_IS_SHAPE(item)) return false; // make sure it has an associated curve SPCurve* item_curve = SP_SHAPE(item)->getCurve(); if (!item_curve) return false; // apply transformations (up to common ancestor) item_curve->transform(item_transform); const Geom::PathVector& curve_pv = item_curve->get_pathvector(); Geom::CrossingSet cross = crossings(conn_pv, curve_pv); // iterate over all Crossings //TODO: check correctness of the following code: inner loop uses loop variable // with a name identical to the loop variable of the outer loop. Then rename. for (Geom::CrossingSet::const_iterator i = cross.begin(); i != cross.end(); ++i) { const Geom::Crossings& cr = *i; for (Geom::Crossings::const_iterator i = cr.begin(); i != cr.end(); ++i) { const Geom::Crossing& cr_pt = *i; if ( intersect_pos < cr_pt.ta) intersect_pos = cr_pt.ta; } } item_curve->unref(); return intersect_pos != initial_pos; }
static bool try_get_intersect_point_with_item_recursive(Geom::PathVector& conn_pv, SPItem* item, const Geom::Matrix& item_transform, double& intersect_pos) { double initial_pos = intersect_pos; // if this is a group... if (SP_IS_GROUP(item)) { SPGroup* group = SP_GROUP(item); // consider all first-order children double child_pos = 0.0; for (GSList const* i = sp_item_group_item_list(group); i != NULL; i = i->next) { SPItem* child_item = SP_ITEM(i->data); try_get_intersect_point_with_item_recursive(conn_pv, child_item, item_transform * child_item->transform, child_pos); if (intersect_pos < child_pos) intersect_pos = child_pos; } return intersect_pos != initial_pos; } // if this is not a shape, nothing to be done if (!SP_IS_SHAPE(item)) return false; // make sure it has an associated curve SPCurve* item_curve = sp_shape_get_curve(SP_SHAPE(item)); if (!item_curve) return false; // apply transformations (up to common ancestor) item_curve->transform(item_transform); const Geom::PathVector& curve_pv = item_curve->get_pathvector(); Geom::CrossingSet cross = crossings(conn_pv, curve_pv); // iterate over all Crossings for (Geom::CrossingSet::const_iterator i = cross.begin(); i != cross.end(); i++) { const Geom::Crossings& cr = *i; for (Geom::Crossings::const_iterator i = cr.begin(); i != cr.end(); i++) { const Geom::Crossing& cr_pt = *i; if ( intersect_pos < cr_pt.ta) intersect_pos = cr_pt.ta; } } item_curve->unref(); return intersect_pos != initial_pos; }
int generate_events(double lat, double lon, time_t now, event** events) { int n = 20 * 365; int k; julian jnow; J2000_days t; event* evs; evs = (event*) calloc(2 * n, sizeof(event)); jnow = from_time_t(now); t = lround(jnow - EXACT_EPOCH - lon / 360); for (k = 0; k < n; k++) { crossings(t - 1 + k, lat, lon, &evs[2*k], &evs[2*k+1]); } *events = evs; return 2*n; }
void color_poly() { int i, y, z, n, tmp; struct coef ray = {0, 1, 0}; int ymin, ymax; ymin = ymax = points[0].y; for (i = 0 ; i < num_points ; ++i) { if (points[i].y < ymin) ymin = points[i].y; if (points[i].y > ymax) ymax = points[i].y; } for (y = ymin ; y < ymax ; y++) { ray.c = -y; n = crossings(0, y, ray); if (n < 2) continue; do { z = 0; for (i = 0 ; i < n - 1 ; ++i) if (s[i] > s[i+1]) { tmp = s[i]; s[i] = s[i+1]; s[i+1] = tmp; z = 1; } } while (z); for (i = 0 ; i < n - 1 ; i += 2) { glBegin(GL_LINES); glVertex2i(s[i], y); glVertex2i(s[i+1], y); glEnd(); } } glFlush(); }