bool TerritoryRegion::IsPointValid(GameWorldBase* gwb, std::vector< Point<MapCoord> > &polygon, MapCoord x, MapCoord y) { // This is for specifying polyons that wrap around corners: // - e.g. w=64, h=64, polygon = {(40,40), (40,80), (80,80), (80,40)} return(polygon.empty() || IsPointInPolygon(gwb, polygon, x, y) || IsPointInPolygon(gwb, polygon, x + gwb->GetWidth(), y) || IsPointInPolygon(gwb, polygon, x, y + gwb->GetHeight()) || IsPointInPolygon(gwb, polygon, x + gwb->GetWidth(), y + gwb->GetHeight())); }
/* --------------------------------------------------------------------------- * checks all visible lines which belong to the same group as the passed polygon. * If one of the endpoints of the line lays inside the passed polygon, * the scanned line is added to the 'rubberband' list. */ static void CheckPolygonForRubberbandConnection (LayerType *Layer, PolygonType *Polygon) { Cardinal group; /* lookup layergroup and check all visible lines in this group */ group = GetLayerGroupNumberByPointer (Layer); GROUP_LOOP (PCB->Data, group); { if (layer->On) { Coord thick; /* the following code just stupidly compares the endpoints * of the lines */ LINE_LOOP (layer); { if (TEST_FLAG (LOCKFLAG, line)) continue; if (TEST_FLAG (CLEARLINEFLAG, line)) continue; thick = (line->Thickness + 1) / 2; if (IsPointInPolygon (line->Point1.X, line->Point1.Y, thick, Polygon)) CreateNewRubberbandEntry (layer, line, &line->Point1); if (IsPointInPolygon (line->Point2.X, line->Point2.Y, thick, Polygon)) CreateNewRubberbandEntry (layer, line, &line->Point2); } END_LOOP; } } END_LOOP; }
static int polygon_callback (const BoxType * box, void *cl) { PolygonTypePtr polygon = (PolygonTypePtr) box; struct ans_info *i = (struct ans_info *) cl; if (TEST_FLAG (i->locked, polygon)) return 0; if (IsPointInPolygon (PosX, PosY, SearchRadius, polygon)) { *i->ptr2 = *i->ptr3 = polygon; longjmp (i->env, 1); } return 0; }
inline std::pair<bool, double> PolygonIntersection::PolygonRayIntersectionParam(const Point3D& pt, const Vector3D& lineDir, const Polygon3D& poly, const Vector3D& n) { if (poly.points.size() < 3) return std::pair<bool, double>(false, 0); if (lineDir * n == 0) return std::pair<bool, double>(false, 0); const double s = PlaneLineIntersectionParam(pt, lineDir, Point3D(poly.points.front()), n); if (s < 0) return std::pair<bool, double>(false, s); const Point3D pointOnPlane = pt + s * lineDir; const bool inPolygon = IsPointInPolygon(pointOnPlane, poly, n); return std::pair<bool, double>(inPolygon, s); }
static bool IsPointInGoafPolygon( const AcGePoint3dArray& polygons, const AcDbIntArray& polygon_counts, int k, const AcGePoint3d& pt ) { int s = 0; for( int i = 0; i < k; i++ ) { s += polygon_counts[i]; } int t = s + polygon_counts[k]; AcGePoint3dArray polygon; for( int i = s; i < t; i++ ) { polygon.append( polygons[i] ); } return IsPointInPolygon( pt, polygon ); }
int mptl_pin_callback (const BoxType *b, void *cl) { struct mptlc *d = (struct mptlc *) cl; PinTypePtr pin = (PinTypePtr) b; if (!TEST_THERM (d->snum, pin) || ! IsPointInPolygon (pin->X, pin->Y, pin->Thickness + pin->Clearance + 2, d->polygon)) return 0; if (d->type == PIN_TYPE) AddObjectToFlagUndoList (PIN_TYPE, pin->Element, pin, pin); else AddObjectToFlagUndoList (VIA_TYPE, pin, pin, pin); ASSIGN_THERM (d->dnum, GET_THERM (d->snum, pin), pin); CLEAR_THERM (d->snum, pin); return 1; }
inline bool PolygonIntersection::IsPointInPolygon(const Point3D& pt, const Polygon3D& poly) { return IsPointInPolygon(pt, poly, poly.Normal()); }