static void gts_triangulate_test_stuff() { gdouble v[4][3] = { {0.0, 0.0, 0.0}, {0.0, 3.0, 0.0}, {3.0, 3.0, 0.0}, {1.0, 1.0, 0.0} }; int i; GtsVertex *vtx[4]; GCList *polygon = NULL; GtsVector orient; GCList *p; for (i = 0; i < 4; ++i) { vtx[i] = gts_vertex_new(gts_vertex_class(), v[i][0],v[i][1],v[i][2]); polygon = g_clist_append(polygon, vtx[i]); } g_assert(g_clist_length(polygon)); g_assert(gts_polygon_orientation(polygon, orient)); g_assert(orient[0] == 0 && orient[1] == 0 && orient[2] < 0); p = g_clist_next(polygon); g_assert(is_convex(GTS_POINT(p->prev->data), GTS_POINT(p->data),GTS_POINT(p->next->data), orient)); g_assert(is_inside(GTS_POINT(vtx[0]), GTS_POINT(vtx[1]), GTS_POINT(vtx[2]), GTS_POINT(vtx[3]))); g_assert(!is_inside(GTS_POINT(vtx[0]), GTS_POINT(vtx[1]), GTS_POINT(vtx[3]), GTS_POINT(vtx[2]))); g_clist_free(p); for (i = 0; i < 4; ++i) gts_object_destroy(GTS_OBJECT(vtx[i])); }
/** * Prints a WKT version of the polygons to stdout * * NOTE: if a polygon is inside another polygon is treated as a hole */ void toWKT_polygons(std::vector<Polygon_2> polygons) { std::vector<std::string> strings; std::vector<bool> isinsidesomeone; //fill the inside booleans bool inside = false; for(std::vector<Polygon_2>::iterator plg = polygons.begin(); plg != polygons.end(); ++plg) { inside = false; for(std::vector<Polygon_2>::iterator plg2 = polygons.begin(); plg2 != polygons.end(); ++plg2) { if(is_inside(*plg2,*plg)) inside = true; } isinsidesomeone.push_back(inside); } for(std::vector<Polygon_2>::iterator plg1 = polygons.begin(); plg1 != polygons.end(); ++plg1) { //print the first polygon part if (isinsidesomeone.at(std::distance(polygons.begin(),plg1))) { continue; } std::cout << "POLYGON("; print_WKT_polygon_2(*plg1); //check for holes, and print them with the polygon for(std::vector<Polygon_2>::iterator plg2 = polygons.begin(); plg2 != polygons.end(); ++plg2) { if (is_inside(*plg1,*plg2)) { //if is inside the polygon, is a hole std::cout << ","; print_WKT_polygon_2(*plg2); } } std::cout << ")" << std::endl; } }
static uint8_t scan_blk_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd, const int mi_row, const int mi_col, int block, const MV_REFERENCE_FRAME rf[2], int row_offset, int col_offset, CANDIDATE_MV *ref_mv_stack, uint8_t *refmv_count) { const TileInfo *const tile = &xd->tile; POSITION mi_pos; uint8_t newmv_count = 0; mi_pos.row = row_offset; mi_pos.col = col_offset; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, &mi_pos) && *refmv_count < MAX_REF_MV_STACK_SIZE) { const MODE_INFO *const candidate_mi = xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col]; const MB_MODE_INFO *const candidate_mbmi = &candidate_mi->mbmi; const int len = 1; newmv_count += add_ref_mv_candidate(xd, candidate_mi, candidate_mbmi, rf, refmv_count, ref_mv_stack, cm->allow_high_precision_mv, len, block, mi_pos.col); } // Analyze a single 8x8 block motion information. return newmv_count; }
double circle::intersect(ray const& r) const { double t; point3d v1, v2; v1=normalize(p1_-center_); v2=normalize(p2_-center_); point3d n=normalenvektor(v1, v2); double s=scaleproduct(n, center_); point3d dir=normalize(r.getDir()); if (scaleproduct(n, dir)!=0) { double temp=(scaleproduct(n, r.getOrigin())+s)/scaleproduct(n, dir); point3d schnitt=r.getOrigin()+temp*dir; //std::cout<<"schnitt: "<<schnitt<<std::endl; if (is_inside(schnitt)) { //std::cout<<"Schnittpunkt mit dem Kreis"<<std::endl; return t=temp; } else { //std::cout<<"Schnittpunkt mit Ebene aber nicht mit Kreis"<<std::endl; return t=-1; } } else { //std::cout<<"Kein Schnittpunkt mit Kreisebene"<<std::endl; return t=-1; } }
static uint8_t scan_col_mbmi(const AV1_COMMON *cm, const MACROBLOCKD *xd, const int mi_row, const int mi_col, int block, const MV_REFERENCE_FRAME rf[2], int col_offset, CANDIDATE_MV *ref_mv_stack, uint8_t *refmv_count) { const TileInfo *const tile = &xd->tile; int i; uint8_t newmv_count = 0; for (i = 0; i < xd->n8_h && *refmv_count < MAX_REF_MV_STACK_SIZE;) { POSITION mi_pos; mi_pos.row = i; mi_pos.col = col_offset; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, &mi_pos)) { const MODE_INFO *const candidate_mi = xd->mi[mi_pos.row * xd->mi_stride + mi_pos.col]; const MB_MODE_INFO *const candidate_mbmi = &candidate_mi->mbmi; const int len = AOMMIN(xd->n8_h, num_8x8_blocks_high_lookup[candidate_mbmi->sb_type]); newmv_count += add_ref_mv_candidate(xd, candidate_mi, candidate_mbmi, rf, refmv_count, ref_mv_stack, cm->allow_high_precision_mv, len, block, mi_pos.col); i += len; } else { ++i; } } return newmv_count; }
pixel_t bicubic_sampler_t::operator()( const Imath::V2d& p) const { if( !is_inside( p)) return pixel_t( 0, 0, 0, 0); return sample( p); }
void query_pointer(xcb_window_t *win, xcb_point_t *pt) { xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL); if (qpr != NULL) { if (win != NULL) { *win = qpr->child; xcb_point_t pt = {qpr->root_x, qpr->root_y}; for (stacking_list_t *s = stack_tail; s != NULL; s = s->prev) { if (!s->node->client->shown || s->node->hidden) { continue; } xcb_rectangle_t rect = get_rectangle(NULL, s->node); if (is_inside(pt, rect)) { if (s->node->id == qpr->child || is_presel_window(qpr->child)) { *win = s->node->id; } break; } } } if (pt != NULL) { *pt = (xcb_point_t) {qpr->root_x, qpr->root_y}; } } free(qpr); }
std::list<Tile*> Tilemap::getRectangle( const TilePos& start, const TilePos& stop, const bool corners /*= true*/ ) { std::list<Tile*> res; int delta_corners = 0; if (! corners) { delta_corners = 1; } /*Rect maxRect( 0, 0, _size, _size ); Rect rect( start.getI()+delta_corners, start.getJ()+delta_corners, stop.getI()-delta_corners, stop.getJ()-delta_corners ); rect.constrainTo( maxRect ); for( int i=rect.getLeft(); i < rect.getRight(); i++ ) for( int j=rect.getTop(); j < rect.getBottom(); j++ ) ret.push_back( &at( TilePos( i, j ) ) ); */ for(int i = start.getI()+delta_corners; i <= stop.getI()-delta_corners; ++i) { if (is_inside( TilePos( i, start.getJ() ) )) { res.push_back( &at(i, start.getJ() )); } if (is_inside( TilePos( i, stop.getJ() ) )) { res.push_back( &at( i, stop.getJ() )); } } for (int j = start.getJ()+1; j <= stop.getJ()-1; ++j) // corners have been handled already { if (is_inside( TilePos( start.getI(), j ) )) { res.push_back(&at(start.getI(), j)); } if (is_inside( TilePos( stop.getI(), j ) )) { res.push_back(&at(stop.getI(), j)); } } return res; }
void clip_polygon(struct item_bin *ib, struct rect *r, struct tile_parameter *param, struct item_bin_sink *out) { int count_in=ib->clen/2; struct coord *pin,*p,*s,pi; char buffer1[ib->len*4+ib->clen*7+32]; struct item_bin *ib1=(struct item_bin *)buffer1; char buffer2[ib->len*4+ib->clen*7+32]; struct item_bin *ib2=(struct item_bin *)buffer2; struct item_bin *ib_in,*ib_out; int edge,i; ib_out=ib1; ib_in=ib; for (edge = 0 ; edge < 4 ; edge++) { count_in=ib_in->clen/2; pin=(struct coord *)(ib_in+1); p=pin; s=pin+count_in-1; item_bin_init(ib_out, ib_in->type); for (i = 0 ; i < count_in ; i++) { if (is_inside(p, r, edge)) { if (! is_inside(s, r, edge)) { poly_intersection(s,p,r,edge,&pi); item_bin_add_coord(ib_out, &pi, 1); } item_bin_add_coord(ib_out, p, 1); } else { if (is_inside(s, r, edge)) { poly_intersection(p,s,r,edge,&pi); item_bin_add_coord(ib_out, &pi, 1); } } s=p; p++; } if (ib_in == ib1) { ib_in=ib2; ib_out=ib1; } else { ib_in=ib1; ib_out=ib2; } } if (ib_in->clen) item_bin_write_clipped(ib_in, param, out); }
template < typename C > static bool includes_impl( const C& corners, const Eigen::Vector3d& rhs ) { for( std::size_t i = 2; i < corners.size(); ++i ) { if( is_inside( corners[0], corners[i-1], corners[i], rhs ) ) { return true; } } return false; }
void CreateHexCore::deleteOutside(vtkUnstructuredGrid *grid) { MeshPartition part(grid, true); QVector<bool> is_inside(grid->GetNumberOfCells(), false); vtkIdType id_start = -1; double dmin = 1e99; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (isVolume(id_cell, grid)) { vec3_t x = cellCentre(grid, id_cell); double d = (x - m_Xi).abs(); if (d < dmin) { dmin = d; id_start = id_cell; } } } if (id_start == -1) { EG_BUG; } is_inside[id_start] = true; bool added = true; while (added) { added = false; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (is_inside[id_cell]) { for (int j = 0; j < part.c2cGSize(id_cell); ++j) { vtkIdType id_neigh = part.c2cGG(id_cell, j); if (id_neigh >= 0) { if (!is_inside[id_neigh]) { is_inside[id_neigh] = true; added = true; } } } } } } int N = 0; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (isSurface(id_cell, grid)) { is_inside[id_cell] = true; } if (is_inside[id_cell]) { ++N; } } QVector<vtkIdType> cls(N); N = 0; for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) { if (is_inside[id_cell]) { cls[N] = id_cell; ++N; } } EG_VTKSP(vtkUnstructuredGrid, return_grid); makeCopy(grid, return_grid, cls); makeCopy(return_grid, grid); }
FileSelection ED_fileselect_layout_offset_rect(FileLayout *layout, const rcti *rect) { int colmin, colmax, rowmin, rowmax; FileSelection sel; sel.first = sel.last = -1; if (layout == NULL) return sel; colmin = (rect->xmin) / (layout->tile_w + 2 * layout->tile_border_x); rowmin = (rect->ymin) / (layout->tile_h + 2 * layout->tile_border_y); colmax = (rect->xmax) / (layout->tile_w + 2 * layout->tile_border_x); rowmax = (rect->ymax) / (layout->tile_h + 2 * layout->tile_border_y); if (is_inside(colmin, rowmin, layout->columns, layout->rows) || is_inside(colmax, rowmax, layout->columns, layout->rows) ) { CLAMP(colmin, 0, layout->columns - 1); CLAMP(rowmin, 0, layout->rows - 1); CLAMP(colmax, 0, layout->columns - 1); CLAMP(rowmax, 0, layout->rows - 1); } if ((colmin > layout->columns - 1) || (rowmin > layout->rows - 1)) { sel.first = -1; } else { if (layout->flag & FILE_LAYOUT_HOR) sel.first = layout->rows * colmin + rowmin; else sel.first = colmin + layout->columns * rowmin; } if ((colmax > layout->columns - 1) || (rowmax > layout->rows - 1)) { sel.last = -1; } else { if (layout->flag & FILE_LAYOUT_HOR) sel.last = layout->rows * colmax + rowmax; else sel.last = colmax + layout->columns * rowmax; } return sel; }
int test_bounding_box( float *b1, float *b2) // big small { int a = is_inside( b1, b2[0], b2[1]); int b = is_inside( b1, b2[2], b2[3]); int c = is_inside( b1, b2[4], b2[5]); int d = is_inside( b1, b2[6], b2[7]); //printf("%d %d %d %d\n", a, b, c, d); if( !a && !b && !c && !d) { return 0; } else { return 1; } }
int main () { int i, count; struct point origin = {0,0}; for (count = 0, i = 0; i < NO_TRI; i++) if (is_inside (origin, &list[i])) count++; printf ("%d\n", count); return 0; }
double estimate_volume(const mesh& mesh) { const auto& nodes = mesh.get_structure().get_condensed_nodes(); const auto num_inside = std::count_if(cbegin(nodes), cend(nodes), [](const auto& i) { return is_inside(i); }); const auto spacing = mesh.get_descriptor().spacing; const auto node_volume = spacing * spacing * spacing; return node_volume * num_inside; }
static int add_col_ref_mv(const AV1_COMMON *cm, const MV_REF *prev_frame_mvs_base, const MACROBLOCKD *xd, int mi_row, int mi_col, MV_REFERENCE_FRAME ref_frame, int blk_row, int blk_col, uint8_t *refmv_count, CANDIDATE_MV *ref_mv_stack, int16_t *mode_context) { const MV_REF *prev_frame_mvs = prev_frame_mvs_base + blk_row * cm->mi_cols + blk_col; POSITION mi_pos; int ref, idx; int coll_blk_count = 0; mi_pos.row = blk_row; mi_pos.col = blk_col; if (!is_inside(&xd->tile, mi_col, mi_row, cm->mi_rows, &mi_pos)) return coll_blk_count; for (ref = 0; ref < 2; ++ref) { if (prev_frame_mvs->ref_frame[ref] == ref_frame) { int_mv this_refmv = prev_frame_mvs->mv[ref]; lower_mv_precision(&this_refmv.as_mv, cm->allow_high_precision_mv); clamp_mv_ref(&this_refmv.as_mv, xd->n8_w << 3, xd->n8_h << 3, xd); if (abs(this_refmv.as_mv.row) >= 16 || abs(this_refmv.as_mv.col) >= 16) mode_context[ref_frame] |= (1 << ZEROMV_OFFSET); for (idx = 0; idx < *refmv_count; ++idx) if (this_refmv.as_int == ref_mv_stack[idx].this_mv.as_int) break; if (idx < *refmv_count) ref_mv_stack[idx].weight += 2; if (idx == *refmv_count && *refmv_count < MAX_REF_MV_STACK_SIZE) { ref_mv_stack[idx].this_mv.as_int = this_refmv.as_int; ref_mv_stack[idx].pred_mv = prev_frame_mvs->pred_mv[ref]; ref_mv_stack[idx].weight = 2; ++(*refmv_count); } ++coll_blk_count; } } return coll_blk_count; }
/*virtual*/ bool triangle::intersect(ray const& r, double& t, HitPoint& hp) const { hp.norm = -1*normalize(cross((B_ - A_), (C_ - A_))); //normal on triangle plain t = -1 * dot((r.o - A_),hp.norm) / dot(r.dir,hp.norm); //intersection of ray with triangle plain hp.pos = r.o + t * r.dir; if(is_inside(hp.pos)) { //see if hp is inside triangle hp.view = r.dir; hp.material = *material_; hp.t = t; return true; } else return false; }
std::list<Tile*> Tilemap::getFilledRectangle(const TilePos& start, const TilePos& stop ) { std::list<Tile*> res; for (int i = start.getI(); i <= stop.getI(); ++i) { for (int j = start.getJ(); j <= stop.getJ(); ++j) { if( is_inside( TilePos( i, j ) )) { res.push_back(&at( TilePos( i, j ) ) ); } } } return res; }
void Object_finish_warp(object_t *obj) { int group; hitmask_t hitmask = NONBALL_BIT | HITMASK(obj->team); /* * clear warped, so we can use shape_is inside, * Wormhole_hitfunc check for WARPED bit. */ CLR_BIT(obj->obj_status, WARPED); group = is_inside(obj->pos.cx, obj->pos.cy, hitmask, obj); /* * kps - we might possibly have entered another polygon, e.g. * a wormhole ? */ if (group != NO_GROUP) SET_BIT(obj->obj_status, WARPED); }
//窗体队鼠标的响应 void form1_dispose() { static u8 mouse_status = 255; static u32 top, left; if( input_status.button == 0) { if(mouse_status == 1) { //拖放操作松开的处理->移动窗体 move_pic_layer( PicLayerTable->Picture[MouseHaldle].Position.top - top, PicLayerTable->Picture[MouseHaldle].Position.left - left, form1_handle, absolute); } mouse_status = 0; } //判断鼠标是否在标题栏 bool is = is_inside (PicLayerTable->Picture[form1_handle].Position.top, PicLayerTable->Picture[form1_handle].Position.left, PicLayerTable->Picture[form1_handle].Position.width, 30, PicLayerTable->Picture[MouseHaldle].Position.left, PicLayerTable->Picture[MouseHaldle].Position.top ); if(is) //鼠标在窗体标题栏上 { if(input_status.button == 1) { if(mouse_status == 0) { //拖放开始 top = PicLayerTable->Picture[MouseHaldle].Position.top - PicLayerTable->Picture[form1_handle].Position.top; left = PicLayerTable->Picture[MouseHaldle].Position.left - PicLayerTable->Picture[form1_handle].Position.left; } mouse_status = 1 ; } } //else if(is_inside (PicLayerTable->Picture[form1_handle].Position.top + 200 - 46, PicLayerTable->Picture[form1_handle].Position.left + 200, 37, 37, PicLayerTable->Picture[MouseHaldle].Position.left, PicLayerTable->Picture[MouseHaldle].Position.top )); //鼠标在重启按钮上 /* { if(input_status.button == 1) { if(mouse_status == 0) { reboot(); } mouse_status = 1 ; } }*/ }
void Attractor::update(Particle* particle, float k, gvec3& movement) { this->_direction = this->position + this->space->getPosition() - particle->position; this->_squaredLength = this->_direction.squaredLength(); if (is_inside(this->_squaredLength, 0.02f, this->radius * this->radius)) { this->_factor = (this->radius - hsqrt(this->_squaredLength)) / this->radius; if (this->exponent != 1.0f) { if (this->exponent == (int)this->exponent) { this->_factor = pow(this->_factor, (int)this->exponent); } else { this->_factor = pow(this->_factor, this->exponent); } } movement += this->_direction.normalized() * (RAND_RANGE(Randomness) * this->force * this->_factor * k); } }
static gboolean add_ear(GtsSurface *s, GtsEdgePool *pool, GCList *p, GCList *polygon, GtsVector orientation) { GtsPoint *v1, *v2, *v3; GCList *i; // ears are convex GCList *pp = p->prev; GCList *pn = p->next; v1 = GTS_POINT(pp->data); v2 = GTS_POINT(p->data); v3 = GTS_POINT(pn->data); GTS_IS_POINT(v1); GTS_IS_POINT(v2); GTS_IS_POINT(v3); if ( !is_convex(v1, v2, v3, orientation) ) { g_debug("concave face (%6.2f %6.2f %6.2f) (%6.2f %6.2f %6.2f) (%6.2f %6.2f %6.2f)", v1->x, v1->y, v1->z, v2->x, v2->y, v2->z, v3->x, v3->y, v3->z); return FALSE; } i = polygon; do { GtsPoint *p1 = GTS_POINT(i->data); if (p1 != v1 && p1 != v2 && p1 != v3) { GtsPoint *p0 = GTS_POINT(i->prev->data); GtsPoint *p2 = GTS_POINT(i->next->data); if (!is_convex(p0, p1, p2, orientation) && is_inside(v1, v2, v3, p1)) { g_debug("reject face\n"); return FALSE; } } i = g_clist_next(i); } while (i != polygon); add_face_from_polygon_corner(s, pool, GTS_VERTEX(v1), GTS_VERTEX(v2), GTS_VERTEX(v3)); return TRUE; }
// replicate the functionality of hex_findpt bool SpectralHex::evaluate_reverse(CartVect const & xyz, CartVect ¶ms, double iter_tol, const double inside_tol, const CartVect &init) const { params = init; //find nearest point double x_star[3]; xyz.get(x_star); double r[3] = {0, 0, 0 }; // initial guess for parametric coords unsigned c = opt_no_constraints_3; double dist = opt_findpt_3(&_data, (const double **)_xyz, x_star, r, &c); // if it did not converge, get out with throw... if (dist > 0.9e+30) return false; //c tells us if we landed inside the element or exactly on a face, edge, or node // also, dist shows the distance to the computed point. //copy parametric coords back params = r; return is_inside(params, inside_tol); }
// This function searches the neighbourhood of a given MB/SB // to try and find candidate reference vectors. static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, int block, int mi_row, int mi_col) { const int *ref_sign_bias = cm->ref_frame_sign_bias; int i, refmv_count = 0; const MODE_INFO *prev_mi = cm->prev_mi ? cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col] : NULL; const MB_MODE_INFO *const prev_mbmi = prev_mi ? &prev_mi->mbmi : NULL; const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; int different_ref_found = 0; int context_counter = 0; // Blank the reference vector list vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); // The nearest 2 blocks are treated differently // if the size < 8x8 we get the mv from the bmi substructure, // and we also need to keep a mode count. for (i = 0; i < 2; ++i) { const POSITION *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi = xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]; const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; // Keep counts for entropy encoding. context_counter += mode_2_counter[candidate->mode]; different_ref_found = 1; if (candidate->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block)); else if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block)); } } // Check the rest of the neighbors in much the same way // as before except we don't need to keep track of sub blocks or // mode counts. for (; i < MVREF_NEIGHBOURS; ++i) { const POSITION *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi; different_ref_found = 1; if (candidate->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(candidate->mv[0]); else if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(candidate->mv[1]); } } // Check the last frame's mode and mv info. if (prev_mbmi) { if (prev_mbmi->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[0]); else if (prev_mbmi->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[1]); } // Since we couldn't find 2 mvs from the same reference frame // go back through the neighbors and find motion vectors from // different reference frames. if (different_ref_found) { for (i = 0; i < MVREF_NEIGHBOURS; ++i) { const POSITION *mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi[mv_ref->col + mv_ref->row * xd->mi_stride]->mbmi; // If the candidate is INTRA we don't want to consider its mv. IF_DIFF_REF_FRAME_ADD_MV(candidate); } } } // Since we still don't have a candidate we'll try the last frame. if (prev_mbmi) IF_DIFF_REF_FRAME_ADD_MV(prev_mbmi); Done: mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; // Clamp vectors for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) clamp_mv_ref(&mv_ref_list[i].as_mv, xd); }
bool is_inside(const mesh& m, size_t node_index) { return is_inside(m.get_structure().get_condensed_nodes()[node_index]); }
bool clip_cg_polygon ( sk_cg_geometry *source, int x_min, int y_min, int x_max, int y_max, sk_list *dest ) { if (!source || !dest) { return false; } sk_cg_point V0 = { .x = x_min, .y = y_min }; sk_cg_point V1 = { .x = x_max, .y = y_min }; sk_cg_point V2 = { .x = x_max, .y = y_max }; sk_cg_point V3 = { .x = x_min, .y = y_max }; struct w_a_node; typedef struct w_a_node w_a_node; struct w_a_node { sk_cg_point *point; w_a_node *A_prev; w_a_node *A_next; w_a_node *B_prev; w_a_node *B_next; bool in; }; bool retval = true; // Initialize the output list if (!sk_list_init(dest, NULL)) { retval = false; goto dest_init_fail; } // Initialize the clipping polygon sk_cg_geometry clipping_polygon; clipping_polygon.type = POLYGON; if (!( sk_list_init(&clipping_polygon.geometry.polygon.points, NULL) && sk_list_append(&clipping_polygon.geometry.polygon.points, &V0) && sk_list_append(&clipping_polygon.geometry.polygon.points, &V1) && sk_list_append(&clipping_polygon.geometry.polygon.points, &V2) && sk_list_append(&clipping_polygon.geometry.polygon.points, &V3) ) ) { retval = false; goto clipping_poly_init_fail; } w_a_node *A_head; w_a_node *B_head; w_a_node **curr; w_a_node *prev; // Establish the Weiler-Atherton list for the clipping polygon curr = &A_head; prev = NULL; sk_iterator A_it; if (!sk_list_begin(&A_it, &clipping_polygon.geometry.polygon.points)) { retval = false; goto A_W_A_list_fail; } while (A_it.has_next(&A_it)) { *curr = ALLOC(*(*curr), 1); (*curr)->point = A_it.next(&A_it); (*curr)->in = is_inside((*curr)->point, source); (*curr)->A_prev = prev; prev = *curr; curr = &(*curr)->A_next; } *curr = A_head; A_head->A_prev = prev; A_it.destroy(&A_it); // Establish the Weiler-Atherton list for the source polygon curr = &B_head; prev = NULL; sk_iterator B_it; bool found_out = false; bool found_in = false; if (!sk_list_begin(&B_it, &source->geometry.polygon.points)) { retval = false; goto B_W_A_list_fail; } while (B_it.has_next(&B_it)) { *curr = ALLOC(*(*curr), 1); (*curr)->point = B_it.next(&B_it); (*curr)->in = is_inside((*curr)->point, &clipping_polygon); if (!(*curr)->in) { found_out = true; } if ((*curr)->in) { found_in = true; } (*curr)->B_prev = prev; prev = *curr; curr = &(*curr)->B_next; } *curr = B_head; B_head->B_prev = prev; B_it.destroy(&B_it); // If source is entirely inside the clipping polygon, it is already clipped. if (!found_out) { sk_cg_geometry *poly = ALLOC(*poly, 1); poly->type = POLYGON; sk_iterator it; sk_list_begin(&it, &source->geometry.polygon.points); while (it.has_next(&it)) { sk_list_append(&poly->geometry.polygon.points, it.next(&it)); sk_list_remove(&it); } it.destroy(&it); sk_list_append(dest, poly); retval = true; goto cleanup; } // If source is entirely outside the clipping polygon, determine whether the clipping polygon is inside source if (!found_in) { sk_list_begin(&A_it, &clipping_polygon.geometry.polygon.points); while (A_it.has_next(&A_it)) { if (is_inside(A_it.next(&A_it), source)) { found_in = true; break; } break; } A_it.destroy(&A_it); // Clipping polygon is inside source. Source becomes clipping polygon. if (found_in) { sk_cg_geometry *poly = ALLOC(*poly, 1); poly->type = POLYGON; sk_iterator it; sk_list_begin(&it, &clipping_polygon.geometry.polygon.points); while (it.has_next(&it)) { sk_cg_point *point = ALLOC(*point, 1); sk_cg_point *old_point = it.next(&it); *point = *old_point; sk_list_append(&poly->geometry.polygon.points, point); } it.destroy(&it); sk_list_append(dest, poly); retval = true; goto cleanup; } else { retval = false; goto cleanup; } } sk_cg_point intersection_point; w_a_node *intersection_node; w_a_node *B_node; bool B_end; w_a_node *A_node; bool A_end; // Loop across polygon B until no new intersection points with A have been found for (B_node = B_head, B_end = false; (!B_end || B_node != B_head); B_node = B_node->B_next) { B_end = true; // Loop across polygon A searching for a new intersection point for (A_node = A_head, A_end = false; (!A_end || A_node != A_head); A_node = A_node->A_next) { A_end = true; // If we're starting on an intersection point, don't try to intersect with itself if (B_node->A_next && B_node->B_next) { if (sk_cg_point_equals(B_node->point, A_node->point) || sk_cg_point_equals(B_node->point, A_node->A_next->point)) { continue; } } // If we're ending on an intersection point don't try to intersect with itself if (B_node->B_next->A_next && B_node->B_next->B_next) { if (sk_cg_point_equals(B_node->B_next->point, A_node->point) || sk_cg_point_equals(B_node->B_next->point, A_node->A_next->point)) { continue; } } // Find the intersection between the current line segments for polygons A and B if (intersection(B_node->point, B_node->B_next->point, A_node->point, A_node->A_next->point, &intersection_point)) { intersection_node = ALLOC(*intersection_node, 1); intersection_node->point = ALLOC(*intersection_node->point, 1); *intersection_node->point = intersection_point; intersection_node->in = true; intersection_node->A_next = A_node->A_next; intersection_node->A_prev = A_node; intersection_node->B_next = B_node->B_next; intersection_node->B_prev = B_node; // If the head of either list will be replaced, point the head at the new intersection nodes if (sk_cg_point_equals(A_head->point, &intersection_point)) { A_head = intersection_node; } if (sk_cg_point_equals(B_head->point, &intersection_point)) { B_head = intersection_node; } // Update the W_A list for polygon A // if intersected at the beginning vertex, replace it with intersection point // if intersected at the ending vertex, replace it with intersection point if (sk_cg_point_equals(A_node->point, &intersection_point)) { intersection_node->A_prev = A_node->A_prev; if (A_node->A_next && A_node->B_next) { free(A_node->point); } free(A_node); A_node = intersection_node; } else if (sk_cg_point_equals(A_node->A_next->point, &intersection_point)) { intersection_node->A_next = A_node->A_next->A_next; if (A_node->A_next->A_next && A_node->A_next->B_next) { free(A_node->A_next->point); } free(A_node->A_next); } // Update the W_A list for polygon B // if intersected at the beginning vertex, replace it with intersection point // if intersected at the ending vertex, replace it with intersection point if (sk_cg_point_equals(B_node->point, &intersection_point)) { intersection_node->B_prev = B_node->B_prev; if (B_node->A_next && B_node->B_next) { free(B_node->point); } free(B_node); B_node = intersection_node; } else if (sk_cg_point_equals(B_node->B_next->point, &intersection_point)) { intersection_node->B_next = B_node->B_next->B_next; if (B_node->B_next->A_next && B_node->B_next->B_next) { free(B_node->B_next->point); } free(B_node->B_next); } // Update the intersection node's neighbors intersection_node->A_prev->A_next = intersection_node; intersection_node->A_next->A_prev = intersection_node; intersection_node->B_prev->B_next = intersection_node; intersection_node->B_next->B_prev = intersection_node; // Make the head of W_A list B point to this intersection node B_head = intersection_node; // Loop ends when we iterate over the entire polygon once without finding a new intersection point B_end = false; break; } } } w_a_node *node; // false = A, true = B // Iterate over polygon B until we don't find any more intersection nodes for (node = B_head, B_end = false; (!B_end || node != B_head);) { B_end = true; // Continue until we find an intersection node if (!(node->A_next && node->B_next)) { node = node->B_next; continue; } // Node is an intersection node: sk_cg_geometry *polygon = ALLOC(*polygon, 1); polygon->type = POLYGON; sk_list_init(&polygon->geometry.polygon.points, NULL); // Remove intersection node, and all subsequent nodes until the next node is outside A. w_a_node *final_node = node; w_a_node *temp; while (final_node) { sk_cg_point *new_node = ALLOC(*new_node, 1); *new_node = *final_node->point; // Add this node's point to the new polygon, then remove this node from both lists. sk_list_append(&polygon->geometry.polygon.points, new_node); if (final_node->A_next && final_node->B_next) { free(final_node->point); final_node->point = NULL; } if (final_node->A_next) { if (final_node->A_next == final_node) { A_head = NULL; } else { if (A_head == final_node) { A_head = final_node->A_next; } final_node->A_next->A_prev = final_node->A_prev; final_node->A_prev->A_next = final_node->A_next; } } if (final_node->B_next) { final_node->B_next->B_prev = final_node->B_prev; final_node->B_prev->B_next = final_node->B_next; } temp = final_node; if (final_node->B_next && (final_node->B_next->in || (final_node->B_next->A_next && final_node->B_next->B_next))) { final_node = final_node->B_next; node = final_node; B_head = node->B_next; } else if (final_node->B_prev && (final_node->B_prev->in || (final_node->B_prev->A_next && final_node->B_prev->B_next))) { final_node = final_node->B_prev; node = final_node; B_head = node->B_next;; } else if ((final_node->A_next) && final_node->A_next->in) { final_node = final_node->A_next; } else if ((final_node->A_prev) && final_node->A_prev->in) { final_node = final_node->A_prev; } else { if (final_node->B_prev) { node = final_node->B_prev; B_head = node->B_next; } B_end = false; final_node = NULL; } free(temp); } sk_list_append(dest, polygon); node = node->B_next; } cleanup: { w_a_node *B_node; for (B_node = B_head->B_prev; B_node != B_head;) { B_node = B_node->B_prev; free(B_node->B_next); } free(B_node); } B_W_A_list_fail: { w_a_node *A_node; if (A_head) { for (A_node = A_head->A_prev; A_node != A_head;) { A_node = A_node->A_prev; free(A_node->A_next); } free(A_node); } } A_W_A_list_fail: sk_list_destroy(&clipping_polygon.geometry.polygon.points); clipping_poly_init_fail: if (!retval) { sk_list_destroy(dest); } dest_init_fail: return retval; }
bool check_triangulation( std::vector<cg::triangle_2> res) { bool ans = true; for (cg::triangle_2 t : res) { bool cur = true; for (cg::triangle_2 help_t : res) { for (int i = 0; i < 3; i++) { if (cur && t[0] != help_t[i] && t[1] != help_t[i] && t[2] != help_t[i] && is_inside(t[0], t[1], t[2], help_t[i])) { ans = cur = false; } } } } return ans; }
void vp9_find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, MODE_INFO *mi, const MODE_INFO *prev_mi, MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, int block_idx, int mi_row, int mi_col) { const int *ref_sign_bias = cm->ref_frame_sign_bias; int i, refmv_count = 0; const MV *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; const MB_MODE_INFO *const prev_mbmi = prev_mi ? &prev_mi->mbmi : NULL; int different_ref_found = 0; int context_counter = 0; vpx_memset(mv_ref_list, 0, sizeof(*mv_ref_list) * MAX_MV_REF_CANDIDATES); for (i = 0; i < 2; ++i) { const MV *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MODE_INFO *const candidate_mi = xd->mi_8x8[mv_ref->col + mv_ref->row * xd->mode_info_stride]; const MB_MODE_INFO *const candidate = &candidate_mi->mbmi; context_counter += mode_2_counter[candidate->mode]; if (candidate->ref_frame[0] == ref_frame) { ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 0, mv_ref->col, block_idx)); different_ref_found = candidate->ref_frame[1] != ref_frame; } else { if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(get_sub_block_mv(candidate_mi, 1, mv_ref->col, block_idx)); different_ref_found = 1; } } } for (; i < MVREF_NEIGHBOURS; ++i) { const MV *const mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi_8x8[mv_ref->col + mv_ref->row * xd->mode_info_stride]->mbmi; if (candidate->ref_frame[0] == ref_frame) { ADD_MV_REF_LIST(candidate->mv[0]); different_ref_found = candidate->ref_frame[1] != ref_frame; } else { if (candidate->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(candidate->mv[1]); different_ref_found = 1; } } } if (prev_mbmi) { if (prev_mbmi->ref_frame[0] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[0]); else if (prev_mbmi->ref_frame[1] == ref_frame) ADD_MV_REF_LIST(prev_mbmi->mv[1]); } if (different_ref_found) { for (i = 0; i < MVREF_NEIGHBOURS; ++i) { const MV *mv_ref = &mv_ref_search[i]; if (is_inside(tile, mi_col, mi_row, cm->mi_rows, mv_ref)) { const MB_MODE_INFO *const candidate = &xd->mi_8x8[mv_ref->col + mv_ref->row * xd->mode_info_stride]->mbmi; if (is_inter_block(candidate)) IF_DIFF_REF_FRAME_ADD_MV(candidate); } } } if (prev_mbmi && is_inter_block(prev_mbmi)) IF_DIFF_REF_FRAME_ADD_MV(prev_mbmi); Done: mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) clamp_mv_ref(&mv_ref_list[i].as_mv, xd); }
bool is_inside_monitor(monitor_t *m, xcb_point_t pt) { return is_inside(pt, m->rectangle); }
int main(int argc, char **argv) { FILE *fp; surfspline_desc sspline; int err, npoints, itempart=0; int binary_output=FALSE, matlab_output=FALSE, mtv_output=FALSE, interpolate_only=FALSE; float fbuf, external_value=0.0; DATATYPE f, x, y, xmin, xmax, ymin, ymax, xstep, ystep; array index; pid_t pid; char outname[L_tmpnam], inname[L_tmpnam], **inargs, *infile; /*{{{ Read command line args*/ for (inargs=argv+1; inargs-argv<argc && **inargs=='-'; inargs++) { switch(inargs[0][1]) { case 'B': binary_output=TRUE; break; case 'I': if (inargs[0][2]!='\0') { itempart=atoi(*inargs+2); } break; case 'i': interpolate_only=TRUE; if (inargs[0][2]!='\0') { external_value=atof(*inargs+2); } break; case 'M': matlab_output=TRUE; break; case 'm': mtv_output=TRUE; break; default: fprintf(stderr, "%s: Ignoring unknown option %s\n", argv[0], *inargs); continue; } } if (argc-(inargs-argv)!=3) { fprintf(stderr, "Usage: %s array_filename degree npoints\n" "Options:\n" " -Iitem: Use item number item as z-axis (2+item'th column); default: 0\n" " -i[value]: Interpolate only; set external values to value (default: 0.0)\n" " -B: Binary output (gnuplot floats)\n" " -M: Matlab output (x, y vectors and z matrix)\n" " -m: Plotmtv output\n" , argv[0]); return -1; } infile= *inargs++; if ((fp=fopen(infile, "r"))==NULL) { fprintf(stderr, "Can't open %s\n", infile); return -2; } array_undump(fp, &sspline.inpoints); fclose(fp); if (sspline.inpoints.message==ARRAY_ERROR) { fprintf(stderr, "Error in array_undump\n"); return -3; } if (sspline.inpoints.nr_of_elements<3+itempart) { fprintf(stderr, "Not enough columns in array %s\n", *(inargs-1)); return -3; } sspline.degree=atoi(*inargs++);; npoints=atoi(*inargs++); /*}}} */ /*{{{ Get the index of qhull point pairs by running qhull*/ tmpnam(outname); tmpnam(inname); if ((pid=fork())==0) { /* I'm the child */ #define LINEBUF_SIZE 128 char linebuf[LINEBUF_SIZE]; array tmp_array; /*{{{ Dump xy positions to tmp file inname*/ tmp_array.nr_of_elements=2; tmp_array.nr_of_vectors=sspline.inpoints.nr_of_vectors; tmp_array.element_skip=1; if (array_allocate(&tmp_array)==NULL) { fprintf(stderr, "Error allocating tmp_array\n"); return -4; } array_reset(&sspline.inpoints); do { array_write(&tmp_array, array_scan(&sspline.inpoints)); array_write(&tmp_array, array_scan(&sspline.inpoints)); array_nextvector(&sspline.inpoints); } while (tmp_array.message!=ARRAY_ENDOFSCAN); if ((fp=fopen(inname, "w"))==NULL) { fprintf(stderr, "Can't open %s\n", inname); return -5; } array_dump(fp, &tmp_array, ARRAY_ASCII); fclose(fp); array_free(&tmp_array); /*}}} */ snprintf(linebuf, LINEBUF_SIZE, "qhull C0 i b <%s >%s", inname, outname); execl("/bin/sh", "sh", "-c", linebuf, 0); #undef LINEBUF_SIZE } else { wait(NULL); } unlink(inname); if ((fp=fopen(outname, "r"))==NULL) { fprintf(stderr, "Can't open %s\n", outname); return -6; } array_undump(fp, &index); fclose(fp); unlink(outname); /*}}} */ /*{{{ Find min, max and mean coordinates*/ array_transpose(&sspline.inpoints); array_reset(&sspline.inpoints); xmin=array_min(&sspline.inpoints); ymin=array_min(&sspline.inpoints); array_reset(&sspline.inpoints); xmax=array_max(&sspline.inpoints); ymax=array_max(&sspline.inpoints); array_reset(&sspline.inpoints); xmean=array_mean(&sspline.inpoints); ymean=array_mean(&sspline.inpoints); xstep=(xmax-xmin)/npoints; ystep=(ymax-ymin)/npoints; array_transpose(&sspline.inpoints); array_reset(&sspline.inpoints); /*}}} */ /*{{{ Copy itempart to 3rd location if necessary*/ /* Note: For this behavior it is essential that array_surfspline * will accept vectors of any size >=3 and only process the first three * elements ! */ if (itempart>0) { DATATYPE hold; do { sspline.inpoints.current_element=2+itempart; hold=READ_ELEMENT(&sspline.inpoints); sspline.inpoints.current_element=2; WRITE_ELEMENT(&sspline.inpoints, hold); array_nextvector(&sspline.inpoints); } while (sspline.inpoints.message!=ARRAY_ENDOFSCAN); } /*}}} */ /*{{{ Do surface spline*/ if ((err=array_surfspline(&sspline))!=0) { fprintf(stderr, "Error %d in array_surfspline\n", err); return err; } xmin-=xstep; xmax+=2*xstep; ymin-=ystep; ymax+=2*ystep; if (binary_output) { /*{{{ Gnuplot binary output*/ int n_xval=(xmax-xmin)/xstep+1, n; /* Number of x values */ fbuf=n_xval; fwrite(&fbuf, sizeof(float), 1, stdout); for (fbuf=xmin, n=0; n<n_xval; fbuf+=xstep, n++) { /* x values */ fwrite(&fbuf, sizeof(float), 1, stdout); } for (y=ymin; y<=ymax; y+=ystep) { fbuf=y; fwrite(&fbuf, sizeof(float), 1, stdout); for (x=xmin, n=0; n<n_xval; x+=xstep, n++) { if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) { f=external_value; } else { f=array_fsurfspline(&sspline, x, y); } fbuf=f; fwrite(&fbuf, sizeof(float), 1, stdout); } } /*}}} */ } else if (matlab_output) { /*{{{ Matlab output*/ array xm, ym, zm; xm.nr_of_elements=ym.nr_of_elements=1; xm.nr_of_vectors=zm.nr_of_elements=(xmax-xmin)/xstep+1; ym.nr_of_vectors=zm.nr_of_vectors=(ymax-ymin)/ystep+1; xm.element_skip=ym.element_skip=zm.element_skip=1; array_allocate(&xm); array_allocate(&ym); array_allocate(&zm); if (xm.message==ARRAY_ERROR || ym.message==ARRAY_ERROR || zm.message==ARRAY_ERROR) { fprintf(stderr, "Error allocating output arrays\n"); return -7; } x=xmin; do { array_write(&xm, x); x+=xstep; } while (xm.message!=ARRAY_ENDOFSCAN); y=ymin; do { array_write(&ym, y); x=xmin; do { if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) { f=external_value; } else { f=array_fsurfspline(&sspline, x, y); } array_write(&zm, f); x+=xstep; } while (zm.message==ARRAY_CONTINUE); y+=ystep; } while (zm.message!=ARRAY_ENDOFSCAN); array_dump(stdout, &xm, ARRAY_MATLAB); array_dump(stdout, &ym, ARRAY_MATLAB); array_dump(stdout, &zm, ARRAY_MATLAB); array_free(&xm); array_free(&ym); array_free(&zm); /*}}} */ } else if (mtv_output) { /*{{{ Plotmtv output*/ array zm; DATATYPE zmin=FLT_MAX, zmax= -FLT_MAX; zm.nr_of_elements=(xmax-xmin)/xstep+1; zm.nr_of_vectors=(ymax-ymin)/ystep+1; zm.element_skip=1; array_allocate(&zm); if (zm.message==ARRAY_ERROR) { fprintf(stderr, "Error allocating output arrays\n"); return -7; } y=ymin; do { x=xmin; do { if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) { f=external_value; } else { f=array_fsurfspline(&sspline, x, y); } array_write(&zm, f); if (f<zmin) zmin=f; if (f>zmax) zmax=f; x+=xstep; } while (zm.message==ARRAY_CONTINUE); y+=ystep; } while (zm.message!=ARRAY_ENDOFSCAN); /*{{{ Print file header*/ printf( "# Output of Spline_Gridder (C) Bernd Feige 1995\n\n" "$ DATA=CONTOUR\n\n" "%% toplabel = \"Spline_Gridder output\"\n" "%% subtitle = \"File: %s\"\n\n" "%% interp = 0\n" "%% contfill = on\n" "%% meshplot = off\n\n" "%% xmin = %g xmax = %g\n" "%% ymin = %g ymax = %g\n" "%% zmin = %g zmax = %g\n" "%% nx = %d\n" "%% ny = %d\n" , infile, xmin, xmax, ymin, ymax, zmin, zmax, zm.nr_of_elements, zm.nr_of_vectors); /*}}} */ array_dump(stdout, &zm, ARRAY_MATLAB); array_free(&zm); /*}}} */ } else { /*{{{ Gnuplot output*/ for (x=xmin; x<=xmax; x+=xstep) { for (y=ymin; y<=ymax; y+=ystep) { if (interpolate_only && !is_inside(&index, &sspline.inpoints, x, y)) { f=external_value; } else { f=array_fsurfspline(&sspline, x, y); } printf("%g %g %g\n", x, y, f); } printf("\n"); } /*}}} */ } /*}}} */ return 0; }