void CWorld::GetHeightPoint( const CPointMap & pt, CGrayMapBlockState & block, bool fHouseCheck ) { ADDTOCALLSTACK("CWorld::GetHeightPoint"); CItemBase * pItemDef = NULL; CItemBaseDupe * pDupeDef = NULL; CItem * pItem = NULL; DWORD wBlockThis = 0; signed char z = 0; height_t zHeight = 0; int x2 = 0, y2 = 0; // Height of statics at/above given coordinates // do gravity here for the z. const CGrayMapBlock * pMapBlock = GetMapBlock( pt ); if (pMapBlock == NULL) return; size_t iQty = pMapBlock->m_Statics.GetStaticQty(); if ( iQty > 0 ) // no static items here. { x2 = pMapBlock->GetOffsetX(pt.m_x); y2 = pMapBlock->GetOffsetY(pt.m_y); const CUOStaticItemRec * pStatic = NULL; for ( size_t i = 0; i < iQty; ++i, z = 0, zHeight = 0, pStatic = NULL, pDupeDef = NULL ) { if ( ! pMapBlock->m_Statics.IsStaticPoint( i, x2, y2 )) continue; pStatic = pMapBlock->m_Statics.GetStatic( i ); if ( pStatic == NULL ) continue; z = pStatic->m_z; //DEBUG_ERR(("z (%d) block.m_zHeight (%d) block.m_Bottom.m_z (%d)\n",z,block.m_zHeight,block.m_Bottom.m_z)); if ( ! block.IsUsableZ( z, block.m_zHeight )) continue; // This static is at the coordinates in question. // enough room for me to stand here ? pItemDef = CItemBase::FindItemBase( pStatic->GetDispID() ); if ( pItemDef ) { //DEBUG_ERR(("pItemDef->GetID(0%x) pItemDef->GetDispID(0%x) pStatic->GetDispID(0%x)\n",pItemDef->GetID(),pItemDef->GetDispID(),pStatic->GetDispID())); if ( pItemDef->GetID() == pStatic->GetDispID() ) //parent item { zHeight = pItemDef->GetHeight(); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); //Use only Block flags, other remove } else //non-parent item { pDupeDef = CItemBaseDupe::GetDupeRef(static_cast<ITEMID_TYPE>(pStatic->GetDispID())); if ( ! pDupeDef ) { g_Log.EventDebug("Failed to get non-parent reference (static) (DispID 0%x) (X: %d Y: %d Z: %d)\n",pStatic->GetDispID(),pStatic->m_x+pMapBlock->m_x,pStatic->m_y+pMapBlock->m_y,pStatic->m_z); zHeight = pItemDef->GetHeight(); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); } else { zHeight = pDupeDef->GetHeight(); wBlockThis = ( pDupeDef->m_Can & CAN_I_MOVEMASK ); //Use only Block flags, other remove - CAN flags cannot be inherited from the parent item due to bad script pack... } } } else if ( pStatic->GetDispID() ) CItemBase::GetItemTiledataFlags(wBlockThis,pStatic->GetDispID()); block.CheckTile_Item( wBlockThis, z, zHeight, pStatic->GetDispID() + TERRAIN_QTY ); } } pItemDef = NULL; pDupeDef = NULL; pItem = NULL; wBlockThis = 0; z = 0; zHeight = 0; x2 = y2 = 0; iQty = 0; // Any multi items here ? // Check all of them if ( fHouseCheck ) { CRegionLinks rlinks; size_t iRegionQty = pt.GetRegions( REGION_TYPE_MULTI, rlinks ); if ( iRegionQty > 0 ) { // ------------ For variables -------------------- CRegionBase * pRegion = NULL; const CGrayMulti * pMulti = NULL; const CUOMultiItemRec2 * pMultiItem = NULL; x2 = 0; y2 = 0; // ------------ For variables -------------------- for ( size_t iRegion = 0; iRegion < iRegionQty; ++iRegion, pRegion = NULL, pItem = NULL, pMulti = NULL, x2 = 0, y2 = 0 ) { pRegion = rlinks.GetAt(iRegion); if ( pRegion != NULL ) pItem = pRegion->GetResourceID().ItemFind(); if ( pItem != NULL ) { pMulti = g_Cfg.GetMultiItemDefs(pItem); if ( pMulti ) { x2 = pt.m_x - pItem->GetTopPoint().m_x; y2 = pt.m_y - pItem->GetTopPoint().m_y; iQty = pMulti->GetItemCount(); for ( size_t ii = 0; ii < iQty; ++ii, pMultiItem = NULL, z = 0, zHeight = 0 ) { pMultiItem = pMulti->GetItem(ii); if ( !pMultiItem ) break; if ( ! pMultiItem->m_visible ) continue; if ( pMultiItem->m_dx != x2 || pMultiItem->m_dy != y2 ) continue; z = static_cast<signed char>( pItem->GetTopZ() + pMultiItem->m_dz ); if ( ! block.IsUsableZ(z,block.m_zHeight)) continue; pItemDef = CItemBase::FindItemBase( pMultiItem->GetDispID() ); if ( pItemDef != NULL ) { if ( pItemDef->GetID() == pMultiItem->GetDispID() ) //parent item { zHeight = pItemDef->GetHeight(); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); //Use only Block flags, other remove } else //non-parent item { pDupeDef = CItemBaseDupe::GetDupeRef(static_cast<ITEMID_TYPE>(pMultiItem->GetDispID())); if ( pDupeDef == NULL ) { g_Log.EventDebug("Failed to get non-parent reference (multi) (DispID 0%x) (X: %d Y: %d Z: %d)\n",pMultiItem->GetDispID(),pMultiItem->m_dx+pItem->GetTopPoint().m_x,pMultiItem->m_dy+pItem->GetTopPoint().m_y,pMultiItem->m_dz+pItem->GetTopPoint().m_z); zHeight = pItemDef->GetHeight(); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); } else { zHeight = pDupeDef->GetHeight(); wBlockThis = ( pDupeDef->m_Can & CAN_I_MOVEMASK ); //Use only Block flags, other remove - CAN flags cannot be inherited from the parent item due to bad script pack... } } } else if ( pMultiItem->GetDispID() ) CItemBase::GetItemTiledataFlags(wBlockThis,pMultiItem->GetDispID()); block.CheckTile_Item( wBlockThis, z, zHeight, pMultiItem->GetDispID() + TERRAIN_QTY ); } } } } } } pItemDef = NULL; pDupeDef = NULL; pItem = NULL; wBlockThis = 0; x2 = y2 = iQty = 0; zHeight = 0; z = 0; // Any dynamic items here ? // NOTE: This could just be an item that an NPC could just move ? CWorldSearch Area( pt ); for (;;) { pItem = Area.GetItem(); if ( !pItem ) break; z = pItem->GetTopZ(); if ( !block.IsUsableZ( z, block.m_zHeight ) ) continue; // Invis items should not block ??? pItemDef = CItemBase::FindItemBase( pItem->GetDispID() ); if ( pItemDef ) { if ( pItemDef->GetDispID() == pItem->GetDispID() )//parent item { zHeight = pItemDef->GetHeight(); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); //Use only Block flags, other remove } else //non-parent item { pDupeDef = CItemBaseDupe::GetDupeRef(static_cast<ITEMID_TYPE>(pItem->GetDispID())); if ( ! pDupeDef ) { g_Log.EventDebug("Failed to get non-parent reference (dynamic) (DispID 0%x) (X: %d Y: %d Z: %d)\n",pItem->GetDispID(),pItem->GetTopPoint().m_x,pItem->GetTopPoint().m_y,pItem->GetTopPoint().m_z); zHeight = pItemDef->GetHeight(); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); } else { zHeight = pDupeDef->GetHeight(); wBlockThis = ( pDupeDef->m_Can & CAN_I_MOVEMASK ); //Use only Block flags, other remove - CAN flags cannot be inherited from the parent item due to bad script pack... } } } else if (pItem->GetDispID()) CItemBase::GetItemTiledataFlags(wBlockThis,pItem->GetDispID()); block.CheckTile_Item(wBlockThis, z, zHeight, pItem->GetDispID() + TERRAIN_QTY); } wBlockThis = 0; // Terrain height is screwed. Since it is related to all the terrain around it. const CUOMapMeter * pMeter = pMapBlock->GetTerrain( UO_BLOCK_OFFSET(pt.m_x), UO_BLOCK_OFFSET(pt.m_y)); if ( ! pMeter ) return; if ( block.IsUsableZ( pMeter->m_z,block.m_zHeight ) ) { //DEBUG_ERR(("pMeter->m_wTerrainIndex 0%x wBlockThis (0%x)\n",pMeter->m_wTerrainIndex,wBlockThis)); if ( pMeter->m_wTerrainIndex == TERRAIN_HOLE ) { wBlockThis = 0; } else if ( CUOMapMeter::IsTerrainNull( pMeter->m_wTerrainIndex ) ) // inter dungeon type. { wBlockThis = CAN_I_BLOCK; } else { CGrayTerrainInfo land( pMeter->m_wTerrainIndex ); //DEBUG_ERR(("Terrain flags - land.m_flags 0%x wBlockThis (0%x)\n",land.m_flags,wBlockThis)); if ( land.m_flags & UFLAG1_WATER ) wBlockThis |= CAN_I_WATER; if ( land.m_flags & UFLAG1_DAMAGE ) wBlockThis |= CAN_I_FIRE; if ( land.m_flags & UFLAG1_BLOCK ) wBlockThis |= CAN_I_BLOCK; if (( ! wBlockThis ) || ( land.m_flags & UFLAG2_PLATFORM )) // Platform items should take precendence over non-platforms. wBlockThis = CAN_I_PLATFORM; } //DEBUG_ERR(("TERRAIN wBlockThis (0%x)\n",wBlockThis)); block.CheckTile_Terrain( wBlockThis, pMeter->m_z, pMeter->m_wTerrainIndex ); } if ( block.m_Bottom.m_z == UO_SIZE_MIN_Z ) { block.m_Bottom = block.m_Lowest; if ( block.m_Top.m_z == block.m_Bottom.m_z ) { block.m_Top.m_dwBlockFlags = 0; block.m_Top.m_dwTile = 0; block.m_Top.m_z = UO_SIZE_Z; } } }
bool HSTriangular::Process( const HSVector2dV &contour,HSVector2dV &outResult ) { /* 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 */ outResult.push_back( contour[a] ); outResult.push_back( contour[b] ); outResult.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; }
Area Area::getOffset( const Vec2i &offset ) const { return Area( x1 + offset.x, y1 + offset.y, x2 + offset.x, y2 + offset.y ); }
Area BoundProcessor::resultArea() const { return Area(); }
/// radius of its inscribed circle double Triangle::InRadius() const { // r = 2*area/perimeter return 2*Area()/Perimeter(); }
int InitTriangles(XParms xp, Parms p, int reps) { int i, j, numPoints; int rows; int x, y; int size, iradius; double phi, phiinc, radius, delta, phi2, area, aarea; XPoint *curPoint; pgc = xp->fggc; size = p->special; phi = 0.0; delta = 2.0 * PI / ((double) NUM_POINTS); if (xp->version == VERSION1_2) { radius = ((double) size) * sqrt(3.0)/2.0; phiinc = delta/10.0; } else { /* Version 1.2's radius computation was completely bogus, and resulted in triangles with sides about 50% longer than advertised. However, this inadvertently resulted in triangles with areas just a little bit smaller than the triangle that covers size^2 pixels, which would make the area directly comparable to 10x10 rectangles and 10x10 trapezoids. So here's the new computation so -triangleN has the same area as -rectN. */ radius = ((double) size) * sqrt(sqrt(16.0/27.0)); phiinc = 1.75*PI / ((double) p->objects); } iradius = (int) (radius + 0.5); numPoints = (p->objects) * NUM_POINTS; points = (XPoint *)malloc(numPoints * sizeof(XPoint)); curPoint = points; x = iradius; y = iradius; rows = 0; aarea = 0.0; for (i = 0; i != p->objects; i++) { for (j = 0; j != NUM_POINTS; j++) { phi2 = phi + ((double) j) * delta; curPoint->x = (int) ((double)x + (radius * cos(phi2)) + 0.5); curPoint->y = (int) ((double)y + (radius * sin(phi2)) + 0.5); curPoint++; } area = Area(curPoint[-1], curPoint[-2], curPoint[-3]); aarea += area; /* printf("%6.1lf %6.1lf %6.1lf %6.1lf\n", Distance(curPoint[-1], curPoint[-2]), Distance(curPoint[-1], curPoint[-3]), Distance(curPoint[-2], curPoint[-3]), area); */ phi += phiinc; y += 2 * iradius; rows++; if (y + iradius > HEIGHT || rows == MAXROWS) { rows = 0; y = iradius; x += 2 * iradius; if (x + iradius > WIDTH) { x = iradius; } } } /* printf("Average area = %6.2lf\n", aarea/p->objects); */ SetFillStyle(xp, p); return reps; }
bool Polygon::IsDegenerate(float epsilon) const { return p.size() < 3 || Area() <= epsilon; }
double area_tet(tetrahedron T) { double area = 0; for(int i=0; i<4; i++) area = area + Area(Side(T,i)); return area; }
void USceneCapturer::CaptureComponent( int32 CurrentHorizontalStep, int32 CurrentVerticalStep, FString Folder, USceneCaptureComponent2D* CaptureComponent, TArray<FColor>& Atlas ) { TArray<FColor> SurfaceData; { SCOPE_CYCLE_COUNTER( STAT_SPReadStrip ); FTextureRenderTargetResource* RenderTarget = CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource(); //TODO: ikrimae: Might need to validate that this divides evenly. Might not matter int32 CenterX = CaptureWidth / 2; int32 CenterY = CaptureHeight / 2; SurfaceData.AddUninitialized( StripWidth * StripHeight ); // Read pixels FIntRect Area( CenterX - ( StripWidth / 2 ), CenterY - ( StripHeight / 2 ), CenterX + ( StripWidth / 2 ), CenterY + ( StripHeight / 2) ); auto readSurfaceDataFlags = FReadSurfaceDataFlags(); readSurfaceDataFlags.SetLinearToGamma(false); RenderTarget->ReadPixelsPtr( SurfaceData.GetData(), readSurfaceDataFlags, Area ); } // Copy off strip to atlas texture CopyToUnprojAtlas( CurrentHorizontalStep, CurrentVerticalStep, Atlas, SurfaceData ); if( FStereoPanoramaManager::GenerateDebugImages->GetInt() != 0 ) { SCOPE_CYCLE_COUNTER( STAT_SPSavePNG ); // Generate name FString TickString = FString::Printf( TEXT( "_%05d_%04d_%04d" ), CurrentFrameCount, CurrentHorizontalStep, CurrentVerticalStep ); FString CaptureName = OutputDir / Timestamp / Folder / TickString + TEXT( ".png" ); UE_LOG( LogStereoPanorama, Log, TEXT( "Writing snapshot: %s" ), *CaptureName ); // Write out PNG if (FStereoPanoramaManager::GenerateDebugImages->GetInt() == 2) { //Read Whole Capture Buffer IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper( EImageFormat::PNG ); TArray<FColor> SurfaceDataWhole; SurfaceDataWhole.AddUninitialized(CaptureWidth * CaptureHeight); // Read pixels FTextureRenderTargetResource* RenderTarget = CaptureComponent->TextureTarget->GameThread_GetRenderTargetResource(); RenderTarget->ReadPixelsPtr(SurfaceDataWhole.GetData(), FReadSurfaceDataFlags()); // Force alpha value if (bForceAlpha) { for (FColor& Color : SurfaceDataWhole) { Color.A = 255; } } ImageWrapper->SetRaw(SurfaceDataWhole.GetData(), SurfaceDataWhole.GetAllocatedSize(), CaptureWidth, CaptureHeight, ERGBFormat::BGRA, 8); const TArray<uint8>& PNGData = ImageWrapper->GetCompressed(100); FFileHelper::SaveArrayToFile(PNGData, *CaptureName); ImageWrapper.Reset(); } else { if (bForceAlpha) { for (FColor& Color : SurfaceData) { Color.A = 255; } } IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG); ImageWrapper->SetRaw(SurfaceData.GetData(), SurfaceData.GetAllocatedSize(), StripWidth, StripHeight, ERGBFormat::BGRA, 8); const TArray<uint8>& PNGData = ImageWrapper->GetCompressed(100); FFileHelper::SaveArrayToFile( PNGData, *CaptureName ); ImageWrapper.Reset(); } } }
void PlayerShip::draw() { cinder::gl::draw( shipTexture, Area(Vec2f(SIZE*(floor(tween)+FRAMENO), 0), Vec2f(SIZE*(floor(tween)+FRAMENO) + SIZE, SIZE)), Rectf(mMouseLoc - Vec2f(SIZE/2,0), mMouseLoc + Vec2f(SIZE/2,SIZE)) ); pg.draw(); }
void ShowCircle( ) { ShowPoint( ); // F cout<<" Radius: "<<r<<'\t'; cout<<"Area: "<<Area( )<<endl; //G }
string Circle::ToString() const { stringstream circleStream; // Start reading input into a stringstream // EDIT: Added the ToString() function of the Shape class to display the ID as well. circleStream << Shape::ToString() << ": Circle with Center at " << centre.ToString() << " and Radius = " << radius << "\nCircumference: " << Circumference() << "\nArea: " << Area(); // Add string to circleStream return(circleStream.str()); // Output the string using the str() member function }
int peanoclaw::Area::getAreasOverlappedByRemoteGhostlayers( const tarch::la::Vector<THREE_POWER_D_MINUS_ONE, int>& adjacentRanks, tarch::la::Vector<THREE_POWER_D_MINUS_ONE, int> overlapOfRemoteGhostlayers, const tarch::la::Vector<DIMENSIONS, int>& subdivisionFactor, int rank, Area areas[THREE_POWER_D_MINUS_ONE] ) { logTraceInWith2Arguments("getAreasOverlappedByRemoteGhostlayers(...)", adjacentRanks, overlapOfRemoteGhostlayers); int numberOfAreas = 0; bool oneAreaCoversCompleteSubgrid = false; for(int dimensionality = 0; dimensionality < DIMENSIONS; dimensionality++) { int numberOfManifolds = getNumberOfManifolds(dimensionality); for(int manifoldIndex = 0; manifoldIndex < numberOfManifolds; manifoldIndex++) { tarch::la::Vector<DIMENSIONS, int> manifoldPosition = getManifold(dimensionality, manifoldIndex); int manifoldEntry = linearizeManifoldPosition(manifoldPosition); logDebug("getAreasOverlappedByRemoteGhostlayers(...)", "Manifold " << manifoldPosition << " of dimensions " << dimensionality << ": entry=" << manifoldEntry << ", rank=" << adjacentRanks[manifoldEntry] << ", overlap=" << overlapOfRemoteGhostlayers[manifoldEntry]); if(adjacentRanks[manifoldEntry] == rank && overlapOfRemoteGhostlayers[manifoldEntry] > 0) { //Reduce lower-dimensional manifolds bool canBeOmitted = checkHigherDimensionalManifoldForOverlap( adjacentRanks, overlapOfRemoteGhostlayers, manifoldPosition, dimensionality, manifoldEntry, rank ); //Restrict size and offset by higher-dimensional manifolds logDebug("getAreasOverlappedByRemoteGhostlayers(...)","Testing manifold " << manifoldPosition << " of dimensions " << dimensionality << ": " << (canBeOmitted ? "omitting" : "consider")); if(!canBeOmitted) { tarch::la::Vector<DIMENSIONS, int> size; tarch::la::Vector<DIMENSIONS, int> offset; //Initialise size and offset for(int d = 0; d < DIMENSIONS; d++) { size(d) = (manifoldPosition(d) == 0) ? subdivisionFactor(d) : std::min(subdivisionFactor(d), overlapOfRemoteGhostlayers[manifoldEntry]); offset(d) = (manifoldPosition(d) == 1) ? subdivisionFactor(d) - size(d) : 0; } //TODO unterweg debug // std::cout << "offset: " << offset << ", size: " << size << std::endl; for(int adjacentDimensionality = dimensionality - 1; adjacentDimensionality >= 0; adjacentDimensionality--) { int numberOfAdjacentManifolds = getNumberOfAdjacentManifolds(manifoldPosition, dimensionality, adjacentDimensionality); for(int adjacentManifoldIndex = 0; adjacentManifoldIndex < numberOfAdjacentManifolds; adjacentManifoldIndex++) { tarch::la::Vector<DIMENSIONS, int> adjacentManifoldPosition = getIndexOfAdjacentManifold( manifoldPosition, dimensionality, adjacentDimensionality, adjacentManifoldIndex ); //TODO unterweg debug // std::cout << "adj. manifold " << adjacentManifoldPosition << std::endl; int adjacentEntry = linearizeManifoldPosition(adjacentManifoldPosition); if(adjacentRanks[adjacentEntry] == rank) { for(int d = 0; d < DIMENSIONS; d++) { if(manifoldPosition(d) == 0) { if(adjacentManifoldPosition(d) < 0) { int overlap = std::max(0, overlapOfRemoteGhostlayers[adjacentEntry] - offset(d)); offset(d) += overlap; size(d) -= overlap; //TODO unterweg debug // std::cout << "Reducing bottom " << overlap << std::endl; } else if(adjacentManifoldPosition(d) > 0) { assertion2(adjacentManifoldPosition(d) > 0, adjacentManifoldPosition, d); int overlap = std::max(0, offset(d) + size(d) - (subdivisionFactor(d) - overlapOfRemoteGhostlayers[adjacentEntry])); size(d) -= overlap; //TODO unterweg debug // std::cout << "Reducing top " << overlap << std::endl; } } } } } } logDebug("getAreasOverlappedByRemoteGhostlayers(...)", "offset: " << offset << ", size: " << size << ", dimensionality=" << dimensionality << ", manifoldIndex=" << manifoldIndex << ", manifoldEntry=" << manifoldEntry); if(tarch::la::allGreater(size, 0)) { areas[numberOfAreas++] = Area(offset, size); oneAreaCoversCompleteSubgrid |= (tarch::la::volume(size) >= tarch::la::volume(subdivisionFactor)); assertion1(tarch::la::allGreaterEquals(offset, 0), offset); assertion3(tarch::la::allGreaterEquals(subdivisionFactor, offset + size), offset, size, subdivisionFactor); } } } } } //Optimize areas if(oneAreaCoversCompleteSubgrid) { numberOfAreas = 1; areas[0] = Area(0, subdivisionFactor); } logTraceOutWith2Arguments("getAreasOverlappedByRemoteGhostlayers(...)", numberOfAreas, areas); return numberOfAreas; }
bool Triangulate::Process(const Vector2dVector &contour,Vector2dVector &result) { #if defined(PRECISE_TRIANGULATION) std::vector<p2t::Point*> _polyline; for (auto _p : contour){ _polyline.push_back(new p2t::Point(_p.GetX(), _p.GetY())); } p2t::CDT* _cdt = new p2t::CDT(_polyline); _cdt->Triangulate(); std::vector<p2t::Triangle*> _triangles = _cdt->GetTriangles(); for (auto _t : _triangles){ auto _pt1 = _t->GetPoint(0); auto _pt2 = _t->GetPoint(1); auto _pt3 = _t->GetPoint(2); result.push_back(Vector2d(_pt1->x, _pt1->y)); result.push_back(Vector2d(_pt2->x, _pt2->y)); result.push_back(Vector2d(_pt3->x, _pt3->y)); } delete _cdt; for (auto _p : _polyline) delete _p; return true; #else /* allocate and initialize list of Vertices in polygon */ int n = (int)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; } } //Danilo S Carvalho Alteration from delete to delete[] delete[] V; return true; #endif }
void BorderResizer::Wrap() { auto& controller(widget.get().GetController()); yunseq( FetchEvent<TouchDown>(controller).Add([this](CursorEventArgs&& e){ yunseq(orig_loc = FetchGUIState().CursorLocation, locked_bounds = GetBoundsOf(widget), focused = CheckArea(e)); }, 0xE0), FetchEvent<TouchHeld>(controller).Add([this](CursorEventArgs&& e){ if(e.Strategy == RoutedEventArgs::Direct && focused != Area(BorderArea::Center, BorderArea::Center)) { auto& st(FetchGUIState()); if(st.CheckDraggingOffset()) { const auto offset(st.CursorLocation - orig_loc); auto bounds(locked_bounds); switch(focused.first) { case BorderArea::Left: bounds.Width = max<SPos>(MinSize.Width, locked_bounds.Width - offset.X); bounds.X += locked_bounds.Width - bounds.Width; break; case BorderArea::Right: bounds.Width = max<SPos>(MinSize.Width, locked_bounds.Width + offset.X); break; default: ; } switch(focused.second) { case BorderArea::Up: bounds.Height = max<SPos>(MinSize.Height, locked_bounds.Height - offset.Y); bounds.Y += locked_bounds.Height - bounds.Height; break; case BorderArea::Down: bounds.Height = max<SPos>(MinSize.Height, locked_bounds.Height + offset.Y); break; default: ; } YTraceDe(Notice, "BorderResizer: new bounds = %s.\n", to_string(bounds).c_str()); InvalidateParent(widget); if(HostMode) { const auto& off( bounds.GetPoint() - locked_bounds.GetPoint()); SetBoundsOf(widget, bounds); const auto& nloc(FetchGUIState().CursorLocation - off); if(bounds.Width != MinSize.Width) orig_loc.X = nloc.X; if(bounds.Height != MinSize.Height) orig_loc.Y = nloc.Y; locked_bounds = GetBoundsOf(widget); locked_bounds.GetPointRef() -= off; } else SetBoundsOf(widget, bounds); } e.Handled = true; // XXX: Paint context target invalidated. } }, 0xE0), FetchEvent<Click>(controller).Add([this](CursorEventArgs&& e){ CallEvent<ClickAcross>(widget, e); }, 0xE0), FetchEvent<ClickAcross>(controller).Add([this](CursorEventArgs&&){ yunseq(orig_loc = Point::Invalid, locked_bounds = Rect(), focused = {BorderArea::Center, BorderArea::Center}); }, 0xE0) ); }
// return is to be freed by the caller C4ValueArray *C4FindObject::FindMany(const C4ObjectList &Objs, const C4LSectors &Sct) { // Trivial case if (IsImpossible()) return new C4ValueArray(); C4Rect *pBounds = GetBounds(); if (!pBounds) return FindMany(Objs); // Prepare for array that may be generated C4ValueArray *pArray; int32_t iSize; // Check shape lists? if (UseShapes()) { // Get area C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct; C4ObjectList *pLst = Area.FirstObjectShapes(&pSct); // Check if a single-sector check is enough if (!Area.Next(pSct)) return FindMany(pSct->ObjectShapes); // Set up array pArray = new C4ValueArray(32); iSize = 0; // Create marker, search all areas uint32_t iMarker = ::Objects.GetNextMarker(); for (; pLst; pLst=Area.NextObjectShapes(pLst, &pSct)) for (C4Object *obj : *pLst) if (obj->Status) if (obj->Marker != iMarker) { obj->Marker = iMarker; if (Check(obj)) { // Grow the array, if neccessary if (iSize >= pArray->GetSize()) pArray->SetSize(iSize * 2); // Add object (*pArray)[iSize++] = C4VObj(obj); } } } else { // Set up array pArray = new C4ValueArray(32); iSize = 0; // Search C4LArea Area(&::Objects.Sectors, *pBounds); C4LSector *pSct; for (C4ObjectList *pLst=Area.FirstObjects(&pSct); pLst; pLst=Area.NextObjects(pLst, &pSct)) for (C4Object *obj : *pLst) if (obj->Status) if (Check(obj)) { // Grow the array, if neccessary if (iSize >= pArray->GetSize()) pArray->SetSize(iSize * 2); // Add object (*pArray)[iSize++] = C4VObj(obj); } } // Shrink array pArray->SetSize(iSize); // Recheck object status (may shrink array again) CheckObjectStatus(pArray); // Apply sorting if (pSort) pSort->SortObjects(pArray); return pArray; }
void HalfEdgeMesh::Update() { // Calculate and store all differentials and area // First update all face normals and triangle areas for(unsigned int i = 0; i < GetNumFaces(); i++){ f(i).normal = FaceNormal(i); } // Then update all vertex normals and curvature for(unsigned int i = 0; i < GetNumVerts(); i++){ // Vertex normals are just weighted averages mVerts.at(i).normal = VertexNormal(i); } // Then update vertex curvature for(unsigned int i = 0; i < GetNumVerts(); i++){ mVerts.at(i).curvature = VertexCurvature(i); // std::cerr << mVerts.at(i).curvature << "\n"; } // Finally update face curvature for(unsigned int i = 0; i < GetNumFaces(); i++){ f(i).curvature = FaceCurvature(i); } std::cerr << "Area: " << Area() << ".\n"; std::cerr << "Volume: " << Volume() << ".\n"; // Update vertex and face colors if (mVisualizationMode == CurvatureVertex) { std::vector<Vertex>::iterator iter = mVerts.begin(); std::vector<Vertex>::iterator iend = mVerts.end(); float minCurvature = (std::numeric_limits<float>::max)(); float maxCurvature = -(std::numeric_limits<float>::max)(); while (iter != iend) { if (minCurvature > (*iter).curvature) minCurvature = (*iter).curvature; if (maxCurvature < (*iter).curvature) maxCurvature = (*iter).curvature; iter++; } std::cerr << "Mapping color based on vertex curvature with range [" << minCurvature << "," << maxCurvature << "]" << std::endl; iter = mVerts.begin(); while (iter != iend) { (*iter).color = mColorMap->Map((*iter).curvature, minCurvature, maxCurvature); iter++; } } else if (mVisualizationMode == CurvatureFace) { std::vector<Face>::iterator iter = mFaces.begin(); std::vector<Face>::iterator iend = mFaces.end(); float minCurvature = (std::numeric_limits<float>::max)(); float maxCurvature = -(std::numeric_limits<float>::max)(); while (iter != iend) { if (minCurvature > (*iter).curvature) minCurvature = (*iter).curvature; if (maxCurvature < (*iter).curvature) maxCurvature = (*iter).curvature; iter++; } std::cerr << "Mapping color based on face curvature with range [" << minCurvature << "," << maxCurvature << "]" << std::endl; iter = mFaces.begin(); while (iter != iend) { (*iter).color = mColorMap->Map((*iter).curvature, minCurvature, maxCurvature); iter++; } } }
double Clipping::Area(const vector<ExPoly> &expolys){ double a=0; for (uint i=0; i<expolys.size(); i++) a += Area(expolys[i]); return a; }
void SensitiveAreas::addArea(const Point & point, const Dimension & dimension) { areas.push_back(Area(point, dimension)); }
Area Gate::getArea() { return Area(); }
bool ROITracker::useROIFinder( const PixelViewport& pvp, const uint32_t stage, const uint128_t& frameID, uint8_t*& ticket ) { LBASSERT( !_needsUpdate ); ticket = 0; const uint32_t pvpArea = pvp.getArea(); if( pvpArea < 100 ) return false; if( _lastFrameID != frameID ) // new frame { stde::hash_map< uint32_t, Stage >* tmp = _prvFrame; _prvFrame = _curFrame; _curFrame = tmp; _curFrame->clear(); _lastFrameID = frameID; } _lastStage = stage; Stage& curStage = (*_curFrame)[ stage ]; // check if proper stage is avaliable if( _prvFrame->find( stage ) == _prvFrame->end( )) // new stage { curStage.areas.push_back( Area( pvp )); return _returnPositive( ticket ); } //else existing stage, try to find matching area const Area* match = 0; uint32_t bestArea = 0; const Stage& prvStage = (*_prvFrame)[ stage ]; for( uint32_t i = 0; i < prvStage.areas.size(); i++ ) { PixelViewport tmp = prvStage.areas[i].pvp; tmp.intersect( pvp ); const uint32_t area = tmp.getArea(); if( area > bestArea ) { bestArea = area; match = &prvStage.areas[i]; if( area == pvpArea ) // full match break; } } if( bestArea < pvpArea*2/3 ) // no proper match found, new area { curStage.areas.push_back( Area( pvp )); return _returnPositive( ticket ); } // else good match if( match->skip == 0 ) // don't skip frame { curStage.areas.push_back( Area( pvp, match->lastSkip )); return _returnPositive( ticket ); } //else skip frame curStage.areas.push_back( Area( pvp, match->lastSkip, match->skip-1 )); return false; }
void Circle::Print(){ cout << "Circle Perimetur: " << Perimetre() << "Lice: " << Area() << endl; }
QImage *BoundProcessor::processImage(const QImage& image) const { QImage *result = new QImage(image.width(), image.height(), QImage::Format_ARGB32); result->fill(qRgb(0, 0, 0)); QImage *boundImage; if (type.testFlag(UpDown)) { ImageAlgorithm::ConvolutionFilter *filter = new ImageAlgorithm::ConvolutionFilter(UpDownConvolutionCore, 3, 3, 1, 0); boundImage = ImageAlgorithm::filtImage<ImageAlgorithm::ConvolutionFilter>(image, Area(), filter); delete filter; if (boundImage) { ImageAlgorithm::algebraOperation(result, *boundImage, ImageAlgorithm::Add); delete boundImage; } } if (type.testFlag(DownUp)) { ImageAlgorithm::ConvolutionFilter *filter = new ImageAlgorithm::ConvolutionFilter(DownUpConvolutionCore, 3, 3, 1, 0); boundImage = ImageAlgorithm::filtImage<ImageAlgorithm::ConvolutionFilter>(image, Area(), filter); delete filter; if (boundImage) { ImageAlgorithm::algebraOperation(result, *boundImage, ImageAlgorithm::Add); delete boundImage; } } if (type.testFlag(LeftRight)) { ImageAlgorithm::ConvolutionFilter *filter = new ImageAlgorithm::ConvolutionFilter(LeftRightConvolutionCore, 3, 3, 1, 0); boundImage = ImageAlgorithm::filtImage<ImageAlgorithm::ConvolutionFilter>(image, Area(), filter); delete filter; if (boundImage) { ImageAlgorithm::algebraOperation(result, *boundImage, ImageAlgorithm::Add); delete boundImage; } } if (type.testFlag(RightLeft)) { ImageAlgorithm::ConvolutionFilter *filter = new ImageAlgorithm::ConvolutionFilter(RightLeftConvolutionCore, 3, 3, 1, 0); boundImage = ImageAlgorithm::filtImage<ImageAlgorithm::ConvolutionFilter>(image, Area(), filter); delete filter; if (boundImage) { ImageAlgorithm::algebraOperation(result, *boundImage, ImageAlgorithm::Add); delete boundImage; } } return result; }
int Kurve::OffsetMethod1(Kurve& kOffset, double off, int direction, int method, int& ret)const { // offset kurve with simple span elimination // direction 1 = left, -1 = right // ret = 0 - kurve offset ok // = 1 - kurve has differential scale (not allowed) // = 2 - offset failed // = 3 - offset too large if(this == &kOffset) FAILURE(L"Illegal Call - 'this' must not be kOffset"); double offset = (direction == GEOFF_LEFT)?off : -off; if(fabs(offset) < geoff_geometry::TOLERANCE || m_nVertices < 2) { kOffset = *this; ret = 0; return 1; } Span curSpan, curSpanOff; // current & offset spans Span prevSpanOff; // previous offset span Point p0, p1; // Offset span intersections // offset Kurve kOffset = Matrix(*this); if(m_mirrored) offset = -offset; int RollDir = ( off < 0 ) ? direction : - direction; // Roll arc direction double scalex; if(!GetScale(scalex)) { ret = 1; return 0; // differential scale } offset /= scalex; bool bClosed = Closed(); int nspans = nSpans(); if(bClosed) { Get(nspans, curSpan, true); // assign previus span for closed prevSpanOff = curSpan.Offset(offset); nspans++; // read first again } for(int spannumber = 1; spannumber <= nspans; spannumber++) { if(spannumber > nSpans()) Get(1, curSpan, true); // closed kurve - read first span again else Get(spannumber, curSpan, true); if(!curSpan.NullSpan) { int numint = 0; curSpanOff = curSpan.Offset(offset); curSpanOff.ID = 0; if(!kOffset.m_started) { kOffset.Start(curSpanOff.p0); kOffset.AddSpanID(0); } if(spannumber > 1) { // see if tangent double d = curSpanOff.p0.Dist(prevSpanOff.p1); if((d > geoff_geometry::TOLERANCE) && (curSpanOff.NullSpan == false && prevSpanOff.NullSpan == false)) { // see if offset spans intersect double cp = prevSpanOff.ve ^ curSpanOff.vs; bool inters = (cp > 0 && direction == GEOFF_LEFT) || (cp < 0 && direction == GEOFF_RIGHT); if(inters) { double t[4]; numint = prevSpanOff.Intof(curSpanOff, p0, p1, t); } if(numint == 1) { // intersection - modify previous endpoint kOffset.Replace(kOffset.m_nVertices-1, prevSpanOff.dir, p0, prevSpanOff.pc, prevSpanOff.ID); } else { // 0 or 2 intersections, add roll around (remove -ve loops in elimination function) if(kOffset.Add(RollDir, curSpanOff.p0, curSpan.p0, false)) kOffset.AddSpanID(ROLL_AROUND); } } } // add span if(spannumber < m_nVertices) { curSpanOff.ID = spannumber; kOffset.Add(curSpanOff, false); } else if(numint == 1) // or replace the closed first span kOffset.Replace(0, 0, p0, Point(0, 0), 0); } if(!curSpanOff.NullSpan)prevSpanOff = curSpanOff; } // end of main pre-offsetting loop #ifdef _DEBUG //testDraw->AddKurve("", &kOffset, 0, GREEN); // outXML oxml(L"c:\\temp\\eliminateLoops.xml"); // oxml.startElement(L"eliminateLoops"); // oxml.Write(kOffset, L"kOffset"); // oxml.endElement(); #endif // eliminate loops if(method == NO_ELIMINATION) { ret = 0; return 1; } kOffset = eliminateLoops(kOffset, *this, offset, ret); if(ret == 0 && bClosed) { // check for inverted offsets of closed kurves if(kOffset.Closed()) { double a = Area(); int dir = (a < 0); double ao = kOffset.Area(); int dirOffset = ao < 0; if(dir != dirOffset) ret = 3; else { // check area change compatible with offset direction - catastrophic failure bool bigger = (a > 0 && offset > 0) || (a < 0 && offset < 0); if(bigger && fabs(ao) < fabs(a)) ret = 2; } } else ret = 2; // started closed but now open?? } return (ret == 0)?1 : 0; }
//--------------------------------------------------------- bool CCRS_Transform_Grid::Set_Target_Area(const CSG_Grid_System &Source, const CSG_Grid_System &Target) { if( Parameters("TARGET_AREA")->asBool() == false ) { m_Target_Area.Destroy(); return( true ); } //----------------------------------------------------- CSG_Rect r(Source.Get_Extent()); if( m_Projector.Get_Source().Get_Type() == SG_PROJ_TYPE_CS_Geographic ) { if( r.Get_XMax() > 180.0 ) r.Move(-180.0, 0.0); if( r.Get_YMin() < -90.0 ) r.m_rect.yMin = -90.0; if( r.Get_YMax() < 90.0 ) r.m_rect.yMax = 90.0; } //----------------------------------------------------- CSG_Shapes Area(SHAPE_TYPE_Polygon); CSG_Shape_Polygon *pArea = (CSG_Shape_Polygon *)Area.Add_Shape(); TSG_Point p, q; double dx = Source.Get_XRange() / 100.0; double dy = Source.Get_YRange() / 100.0; m_Projector.Set_Inverse(false); for(p.x=r.Get_XMin(), p.y=r.Get_YMin(); p.y<r.Get_YMax(); p.y+=dy) { m_Projector.Get_Projection(q = p); pArea->Add_Point(q); } for(p.x=r.Get_XMin(), p.y=r.Get_YMax(); p.x<r.Get_XMax(); p.x+=dx) { m_Projector.Get_Projection(q = p); pArea->Add_Point(q); } for(p.x=r.Get_XMax(), p.y=r.Get_YMax(); p.y>r.Get_YMin(); p.y-=dy) { m_Projector.Get_Projection(q = p); pArea->Add_Point(q); } for(p.x=r.Get_XMax(), p.y=r.Get_YMin(); p.x>r.Get_XMin(); p.x-=dx) { m_Projector.Get_Projection(q = p); pArea->Add_Point(q); } m_Projector.Set_Inverse(true); //----------------------------------------------------- m_Target_Area.Create(Target, SG_DATATYPE_Char); m_Target_Area.Set_NoData_Value(0); for(int y=0; y<m_Target_Area.Get_NY() && Set_Progress(y, m_Target_Area.Get_NY()); y++) { double yWorld = Target.Get_yGrid_to_World(y); #pragma omp parallel for for(int x=0; x<m_Target_Area.Get_NX(); x++) { m_Target_Area.Set_Value(x, y, pArea->Contains(Target.Get_xGrid_to_World(x), yWorld) ? 1 : 0); } } //----------------------------------------------------- return( true ); }
void Triangle::ComputeArea() { //Extra credit to implement this this->area = Area(points[0], points[1], points[2]); }
Area Area::getMoveULTo( const Vec2i &newUL ) const { return Area( newUL.x, newUL.y, newUL.x + getWidth(), newUL.y + getHeight() ); }
Area DilationErosionProcessor::resultArea() const { return Area(); }
/*----------------------------------------------------------------------------------------------------------------------------------------- */ void haar_scale(unsigned char *I , int Ny , int Nx , int P , struct model detector , double *z) { int p , indF , NxNy = Nx*Ny , indNxNy = 0 ; double *rect_param = detector.rect_param; unsigned int *F = detector.F; int nx = detector.nx , ny = detector.ny , nF = detector.nF; unsigned int f , indnF = 0; int x , xr , y , yr , w , wr , h , hr , i , r , R , indR ; int coeffw , coeffh; int last = NxNy - 1; double val , s , var , mean , std , cteNxNy = 1.0/NxNy , scalex = (Nx - 1 )/(double)nx , scaley = (Ny - 1 )/(double)ny ; double ctescale = 1.0/(scalex*scaley); unsigned int *II , *Itemp , tempI; II = (unsigned int *)malloc(NxNy*sizeof(unsigned int)); Itemp = (unsigned int *)malloc(NxNy*sizeof(unsigned int)); for(p = 0 ; p < P ; p++) { MakeIntegralImage((I + indNxNy) , II , Nx , Ny , Itemp); var = 0.0; for(i = 0 ; i < NxNy ; i++) { tempI = I[i + indNxNy]; var += (tempI*tempI); } var *= cteNxNy; mean = II[last]*cteNxNy; std = ctescale/sqrt(var - mean*mean); indF = 0; for (f = 0 ; f < nF ; f++) { x = F[1 + indF]; y = F[2 + indF]; w = F[3 + indF]; h = F[4 + indF]; indR = F[5 + indF]; R = (int) rect_param[3 + indR]; val = 0.0; for (r = 0 ; r < R ; r++) { coeffw = w/(int)rect_param[1 + indR]; coeffh = h/(int)rect_param[2 + indR]; xr = Round(scalex*(x + (coeffw*(int)rect_param[5 + indR]))); yr = Round(scaley*(y + (coeffh*(int)rect_param[6 + indR]))); wr = Round(scalex*coeffw*(int)(rect_param[7 + indR])); hr = Round(scaley*coeffh*(int)(rect_param[8 + indR])); s = rect_param[9 + indR]; val += s*Area(II , xr , yr , wr , hr , Ny); indR += 10; } z[f + indnF] = val*std; indF += 6; } indNxNy += NxNy; indnF += nF; } free(II); free(Itemp); }
void CWorld::GetFixPoint( const CPointMap & pt, CGrayMapBlockState & block) { //Will get the highest CAN_I_PLATFORM|CAN_I_CLIMB and places it into block.Bottom ADDTOCALLSTACK("CWorld::GetFixPoint"); CItemBase * pItemDef = NULL; CItemBaseDupe * pDupeDef = NULL; CItem * pItem = NULL; DWORD wBlockThis = 0; signed char z = 0; int x2 = 0, y2 = 0; // Height of statics at/above given coordinates // do gravity here for the z. const CGrayMapBlock * pMapBlock = GetMapBlock( pt ); if (pMapBlock == NULL) return; size_t iQty = pMapBlock->m_Statics.GetStaticQty(); if ( iQty > 0 ) // no static items here. { x2 = pMapBlock->GetOffsetX(pt.m_x); y2 = pMapBlock->GetOffsetY(pt.m_y); const CUOStaticItemRec * pStatic = NULL; for ( size_t i = 0; i < iQty; ++i, z = 0, pStatic = NULL, pDupeDef = NULL ) { if ( ! pMapBlock->m_Statics.IsStaticPoint( i, x2, y2 )) continue; pStatic = pMapBlock->m_Statics.GetStatic( i ); if ( pStatic == NULL ) continue; z = pStatic->m_z; pItemDef = CItemBase::FindItemBase( pStatic->GetDispID() ); if ( pItemDef ) { if (pItemDef->GetID() == pStatic->GetDispID()) //parent item { wBlockThis = (pItemDef->m_Can & CAN_I_MOVEMASK); z += ((wBlockThis & CAN_I_CLIMB) ? pItemDef->GetHeight()/2 : pItemDef->GetHeight()); } else //non-parent item { pDupeDef = CItemBaseDupe::GetDupeRef(static_cast<ITEMID_TYPE>(pStatic->GetDispID())); if ( ! pDupeDef ) { g_Log.EventDebug("Failed to get non-parent reference (static) (DispID 0%x) (X: %d Y: %d Z: %d)\n",pStatic->GetDispID(),pStatic->m_x+pMapBlock->m_x,pStatic->m_y+pMapBlock->m_y,pStatic->m_z); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); z += ((wBlockThis & CAN_I_CLIMB) ? pItemDef->GetHeight()/2 : pItemDef->GetHeight()); } else { wBlockThis = (pDupeDef->m_Can & CAN_I_MOVEMASK); z += ((wBlockThis & CAN_I_CLIMB) ? pDupeDef->GetHeight()/2 : pDupeDef->GetHeight()); } } } else if ( pStatic->GetDispID() ) CItemBase::GetItemTiledataFlags(wBlockThis,pStatic->GetDispID()); if (block.m_Bottom.m_z < z) { if ((z < pt.m_z+PLAYER_HEIGHT) && (wBlockThis & (CAN_I_PLATFORM|CAN_I_CLIMB|CAN_I_WATER))) { block.m_Bottom.m_dwBlockFlags = wBlockThis; block.m_Bottom.m_dwTile = pStatic->GetDispID() + TERRAIN_QTY; block.m_Bottom.m_z = z; } else if (block.m_Top.m_z > z) { block.m_Top.m_dwBlockFlags = wBlockThis; block.m_Top.m_dwTile = pStatic->GetDispID() + TERRAIN_QTY; block.m_Top.m_z = z; } } } } pItemDef = NULL; pDupeDef = NULL; pItem = NULL; wBlockThis = 0; z = 0; x2 = y2 = 0; iQty = 0; // Any multi items here ? // Check all of them CRegionLinks rlinks; size_t iRegionQty = pt.GetRegions( REGION_TYPE_MULTI, rlinks ); if ( iRegionQty > 0 ) { // ------------ For variables -------------------- CRegionBase * pRegion = NULL; const CGrayMulti * pMulti = NULL; const CUOMultiItemRec2 * pMultiItem = NULL; x2 = 0; y2 = 0; // ------------ For variables -------------------- for ( size_t iRegion = 0; iRegion < iRegionQty; ++iRegion, pRegion = NULL, pItem = NULL, pMulti = NULL, x2 = 0, y2 = 0 ) { pRegion = rlinks.GetAt(iRegion); if ( pRegion != NULL ) pItem = pRegion->GetResourceID().ItemFind(); if ( pItem != NULL ) { pMulti = g_Cfg.GetMultiItemDefs(pItem); if ( pMulti ) { x2 = pt.m_x - pItem->GetTopPoint().m_x; y2 = pt.m_y - pItem->GetTopPoint().m_y; iQty = pMulti->GetItemCount(); for ( size_t ii = 0; ii < iQty; ++ii, pMultiItem = NULL, z = 0 ) { pMultiItem = pMulti->GetItem(ii); if ( !pMultiItem ) break; if ( ! pMultiItem->m_visible ) continue; if ( pMultiItem->m_dx != x2 || pMultiItem->m_dy != y2 ) continue; z = static_cast<signed char>(pItem->GetTopZ() + pMultiItem->m_dz); pItemDef = CItemBase::FindItemBase( pMultiItem->GetDispID() ); if ( pItemDef != NULL ) { if ( pItemDef->GetID() == pMultiItem->GetDispID() ) //parent item { wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); z += ((wBlockThis & CAN_I_CLIMB) ? pItemDef->GetHeight()/2 : pItemDef->GetHeight()); } else //non-parent item { pDupeDef = CItemBaseDupe::GetDupeRef(static_cast<ITEMID_TYPE>(pMultiItem->GetDispID())); if ( pDupeDef == NULL ) { g_Log.EventDebug("Failed to get non-parent reference (multi) (DispID 0%x) (X: %d Y: %d Z: %d)\n",pMultiItem->GetDispID(),pMultiItem->m_dx+pItem->GetTopPoint().m_x,pMultiItem->m_dy+pItem->GetTopPoint().m_y,pMultiItem->m_dz+pItem->GetTopPoint().m_z); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); z += ((wBlockThis & CAN_I_CLIMB) ? pItemDef->GetHeight()/2 : pItemDef->GetHeight()); } else { wBlockThis = ( pDupeDef->m_Can & CAN_I_MOVEMASK ); z += ((wBlockThis & CAN_I_CLIMB) ? pDupeDef->GetHeight()/2 : pDupeDef->GetHeight()); } } } else if ( pMultiItem->GetDispID() ) CItemBase::GetItemTiledataFlags(wBlockThis,pMultiItem->GetDispID()); if (block.m_Bottom.m_z < z) { if ((z < pt.m_z+PLAYER_HEIGHT) && (wBlockThis & (CAN_I_PLATFORM|CAN_I_CLIMB|CAN_I_WATER))) { block.m_Bottom.m_dwBlockFlags = wBlockThis; block.m_Bottom.m_dwTile = pMultiItem->GetDispID() + TERRAIN_QTY; block.m_Bottom.m_z = z; } else if (block.m_Top.m_z > z) { block.m_Top.m_dwBlockFlags = wBlockThis; block.m_Top.m_dwTile = pMultiItem->GetDispID() + TERRAIN_QTY; block.m_Top.m_z = z; } } } } } } } pItemDef = NULL; pDupeDef = NULL; pItem = NULL; wBlockThis = 0; x2 = y2 = iQty = 0; z = 0; // Any dynamic items here ? // NOTE: This could just be an item that an NPC could just move ? CWorldSearch Area( pt ); for (;;) { pItem = Area.GetItem(); if ( !pItem ) break; z = pItem->GetTopZ(); // Invis items should not block ??? pItemDef = CItemBase::FindItemBase( pItem->GetDispID() ); if ( pItemDef ) { if ( pItemDef->GetDispID() == pItem->GetDispID() )//parent item { wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); z += ((wBlockThis & CAN_I_CLIMB) ? pItemDef->GetHeight()/2 : pItemDef->GetHeight()); } else //non-parent item { pDupeDef = CItemBaseDupe::GetDupeRef(static_cast<ITEMID_TYPE>(pItem->GetDispID())); if ( ! pDupeDef ) { g_Log.EventDebug("Failed to get non-parent reference (dynamic) (DispID 0%x) (X: %d Y: %d Z: %d)\n",pItem->GetDispID(),pItem->GetTopPoint().m_x,pItem->GetTopPoint().m_y,pItem->GetTopPoint().m_z); wBlockThis = ( pItemDef->m_Can & CAN_I_MOVEMASK ); z += ((wBlockThis & CAN_I_CLIMB) ? pItemDef->GetHeight()/2 : pItemDef->GetHeight()); } else { wBlockThis = ( pDupeDef->m_Can & CAN_I_MOVEMASK ); z += ((wBlockThis & CAN_I_CLIMB) ? pDupeDef->GetHeight()/2 : pDupeDef->GetHeight()); } } if ( block.m_Bottom.m_z < z ) { if ( (z < pt.m_z + PLAYER_HEIGHT) && (wBlockThis & (CAN_I_PLATFORM|CAN_I_CLIMB|CAN_I_WATER)) ) { block.m_Bottom.m_dwBlockFlags = wBlockThis; block.m_Bottom.m_dwTile = pItemDef->GetDispID() + TERRAIN_QTY; block.m_Bottom.m_z = z; } else if ( block.m_Top.m_z > z ) { block.m_Top.m_dwBlockFlags = wBlockThis; block.m_Top.m_dwTile = pItemDef->GetDispID() + TERRAIN_QTY; block.m_Top.m_z = z; } } } else if (pItem->GetDispID()) CItemBase::GetItemTiledataFlags(wBlockThis,pItem->GetDispID()); } wBlockThis = 0; // Terrain height is screwed. Since it is related to all the terrain around it. const CUOMapMeter * pMeter = pMapBlock->GetTerrain( UO_BLOCK_OFFSET(pt.m_x), UO_BLOCK_OFFSET(pt.m_y)); if ( ! pMeter ) return; if ( pMeter->m_wTerrainIndex == TERRAIN_HOLE ) { wBlockThis = 0; } else if ( CUOMapMeter::IsTerrainNull( pMeter->m_wTerrainIndex ) ) // inter dungeon type. { wBlockThis = CAN_I_BLOCK; } else { CGrayTerrainInfo land( pMeter->m_wTerrainIndex ); //DEBUG_ERR(("Terrain flags - land.m_flags 0%x wBlockThis (0%x)\n",land.m_flags,wBlockThis)); if ( land.m_flags & UFLAG1_WATER ) wBlockThis |= CAN_I_WATER; if ( land.m_flags & UFLAG1_DAMAGE ) wBlockThis |= CAN_I_FIRE; if ( land.m_flags & UFLAG1_BLOCK ) wBlockThis |= CAN_I_BLOCK; if (( ! wBlockThis ) || ( land.m_flags & UFLAG2_PLATFORM )) // Platform items should take precendence over non-platforms. wBlockThis = CAN_I_PLATFORM; } if (block.m_Bottom.m_z < pMeter->m_z) { if (((pMeter->m_z < pt.m_z+PLAYER_HEIGHT) && (wBlockThis & (CAN_I_PLATFORM|CAN_I_CLIMB|CAN_I_WATER))) || (block.m_Bottom.m_z == UO_SIZE_MIN_Z)) { block.m_Bottom.m_dwBlockFlags = wBlockThis; block.m_Bottom.m_dwTile = pMeter->m_wTerrainIndex; block.m_Bottom.m_z = pMeter->m_z; } else if (block.m_Top.m_z > pMeter->m_z) { block.m_Top.m_dwBlockFlags = wBlockThis; block.m_Top.m_dwTile = pMeter->m_wTerrainIndex; block.m_Top.m_z = pMeter->m_z; } } if ( block.m_Bottom.m_z == UO_SIZE_MIN_Z ) { //Fail safe... Reset to 0z with no top block; block.m_Bottom.m_dwBlockFlags = 0; block.m_Bottom.m_dwTile = 0; block.m_Bottom.m_z = 0; block.m_Top.m_dwBlockFlags = 0; block.m_Top.m_dwTile = 0; block.m_Top.m_z = UO_SIZE_Z; } }