Example #1
0
UnitAny* FindItemByPosition(DWORD x, DWORD y, DWORD Location) {
	for(UnitAny* pItem = D2COMMON_GetItemFromInventory(D2CLIENT_GetPlayerUnit()->pInventory); pItem; pItem = D2COMMON_GetNextItemFromInventory(pItem)) {
		if((DWORD)GetItemLocation(pItem) == Location && InArea(x,y,pItem->pObjectPath->dwPosX,pItem->pObjectPath->dwPosY,D2COMMON_GetItemText(pItem->dwTxtFileNo)->xSize,D2COMMON_GetItemText(pItem->dwTxtFileNo)->ySize))
			return pItem;
	}
	return NULL;
}
Example #2
0
int GetLargestParticle(Image* binaryImage, int* largestParticleIndex, Rect rect)
{
	*largestParticleIndex = 0; // points to caller-provided variable
	
	/* determine number of particles in thresholded image */	
	int numParticles;
	int success = frcCountParticles(binaryImage, &numParticles);
	if ( !success )	{  return success; 	}			
	
	/* if no particles found we can quit here */
	if (numParticles == 0)  {  return 0; 	}  // unsuccessful if zero particles found
	
	// find the largest particle
	double largestParticleArea = 0;
	double particleArea;
	for (int i = 0; i < numParticles; ++i) {		
		success = imaqMeasureParticle(binaryImage, i, 0, IMAQ_MT_AREA, &particleArea);
		if ( !success )	{ return success; }		
		if (particleArea > largestParticleArea) 	{
			// see if is in the right area
			if ( InArea(binaryImage, i, rect) ) {
				largestParticleArea = particleArea;
				*largestParticleIndex = i;  // return index to caller
			}
		}
	}
	
	return success;
}
Example #3
0
bool CComplexArea::RandomPointInArea (int *retx, int *rety)

//	RandomPointInArea
//
//	Attempts to return a random point inside the area. If successful, returns TRUE

{
    int iTries = MAX_TRIES;
    while (iTries > 0)
    {
        *retx = mathRandom(m_rcBounds.left, m_rcBounds.right);
        *rety = mathRandom(m_rcBounds.bottom, m_rcBounds.top);

        if (InArea(*retx, *rety))
            return true;

        iTries--;
    }

    return false;
}
Example #4
0
/*******************************************************************************
  Function name: InitPixDump()

  Purpose      : Initialize the pixel dumps.  This information is in the
         [OUTPUT] section of the input file

  Required     :
    LISTPTR Input         - Linked list with input strings
    MAPSIZE *Map          - Information about basin extent
    uchar **BasinMask     - Basin mask
    char *Path            - Directory to write output to
    int NPix              - Number of pixels to dump
    PIXDUMP **Pix         - Array of pixels to dump

  Returns      : number of accepted dump pixels (i.e. in the mask, etc)

  Modifies     : NPix and its members

  Comments     :
*******************************************************************************/
int InitPixDump(LISTPTR Input, MAPSIZE *Map, uchar **BasinMask, char *Path,
  int NPix, PIXDUMP **Pix, OPTIONSTRUCT *Options)
{
  char *Routine = "InitPixDump";
  char Str[BUFSIZE + 1];
  double North;
  double East;
  int i;			/* counter */
  int j;
  int ok;
  char temp_name[BUFSIZE + 1];
  char KeyName[name + 1][BUFSIZE + 1];
  char *KeyStr[] = {
    "NORTH COORDINATE",
    "EAST COORDINATE",
    "NAME"
  };
  char *SectionName = "OUTPUT";
  char VarStr[name + 1][BUFSIZE + 1];

  ok = 0;

  if (!(*Pix = (PIXDUMP *)calloc(NPix, sizeof(PIXDUMP))))
    ReportError(Routine, 1);

  for (i = 0; i < NPix; i++) {

    /* Read the key-entry pairs from the input file */
    for (j = 0; j <= name; j++) {
      sprintf(KeyName[j], "%s %d", KeyStr[j], i + 1);
      GetInitString(SectionName, KeyName[j], "", VarStr[j],
        (unsigned long)BUFSIZE, Input);
    }

    /* Assign the entries to the appropriate variables */
    if (!CopyDouble(&North, VarStr[north], 1))
      ReportError(KeyName[north], 51);

    if (!CopyDouble(&East, VarStr[east], 1))
      ReportError(KeyName[east], 51);

    if (IsEmptyStr(VarStr[name]))
      ReportError(KeyName[name], 51);
    strcpy(temp_name, VarStr[name]);

    /* Convert map coordinates to matrix coordinates */
    (*Pix)[i].Loc.N = Round(((Map->Yorig - 0.5 * Map->DY) - North) / Map->DY);
    (*Pix)[i].Loc.E = Round((East - (Map->Xorig + 0.5 * Map->DX)) / Map->DX);

    if (!InArea(Map, &((*Pix)[i].Loc)) ||
      !INBASIN(BasinMask[(*Pix)[i].Loc.N][(*Pix)[i].Loc.E])) {
      printf("Ignoring dump command for pixel named %s \n", temp_name);
    }
    else {
      printf("Accepting dump command for pixel named %s \n", temp_name);
      sprintf(Str, "%s", temp_name);
      sprintf((*Pix)[ok].OutFile.FileName, "%sPixel.%s", Path, Str);
      (*Pix)[ok].Loc.N = (*Pix)[i].Loc.N;
      (*Pix)[ok].Loc.E = (*Pix)[i].Loc.E;
      OpenFile(&((*Pix)[ok].OutFile.FilePtr), (*Pix)[ok].OutFile.FileName, "w", TRUE);
      ok++;
    }
  }
  return ok;
}
Example #5
0
bool InSprite(int x,int y,int sx,int sy,LPDIRECT3DTEXTURE9 pTex)
{
	int w,h;
	GetSpriteSize(pTex,w,h);
	return InArea(x,y,sx,sy,w,h);
}
Example #6
0
bool InSprite(const POINT& p,const POINT& s,IDirect3DTexture9* pTex)
{
	int w,h;
	GetSpriteSize(pTex,w,h);
	return InArea(p.x,p.y,s.x,s.y,w,h);
}
Example #7
0
bool CComplexArea::GeneratePointsInArea (int iCount, int iMinSeparation, TArray<int> *retX, TArray<int> *retY)

//	GeneratePointsInArea
//
//	Generates a set of points inside the area. Optionally ensures that each point
//	has a minimum separation from the others.
//
//	The array is always filled with the proper number of points, but if FALSE is returned,
//	then some points don't meet the required constraints

{
    int i, j;

    //	Optimize 0

    retX->DeleteAll();
    retY->DeleteAll();
    if (iCount <= 0)
        return true;

    //	Generate the requisite number of points

    bool bConstraints = true;
    retX->InsertEmpty(iCount);
    retY->InsertEmpty(iCount);
    for (i = 0; i < iCount; i++)
        if (!RandomPointInArea(&retX->GetAt(i), &retY->GetAt(i)))
            bConstraints = false;

    //	Now randomly adjust the positions until all have the minimum separation

    if (iMinSeparation > 0)
    {
        int iMinDist2 = iMinSeparation * iMinSeparation;
        int iTries = 100 * iCount;
        while (iTries > 0)
        {
            bool bNodeMoved = false;
            bool bTooClose = false;

            for (i = 0; i < iCount; i++)
            {
                //	Compute a vector pointing away from any close nodes

                int xRepel = 0;
                int yRepel = 0;
                for (j = 0; j < iCount; j++)
                    if (j != i)
                    {
                        int xDist = (retX->GetAt(j) - retX->GetAt(i));
                        int yDist = (retY->GetAt(j) - retY->GetAt(i));

                        if (xDist == 0 && yDist == 0)
                        {
                            xRepel += (mathRandom(1, 2) == 1 ? 1 : -1);
                            yRepel += (mathRandom(1, 2) == 1 ? 1 : -1);
                        }
                        else if ((xDist * xDist) + (yDist * yDist) < iMinDist2)
                        {
                            xRepel -= xDist;
                            yRepel -= yDist;
                        }
                    }

                //	If we're too close to some nodes, move away

                if (xRepel != 0 || yRepel != 0)
                {
                    int iRadius = Max(1, Max(Absolute(xRepel), Absolute(yRepel)) / 2);
                    int xNew = retX->GetAt(i) + (xRepel / iRadius);
                    int yNew = retY->GetAt(i) + (yRepel / iRadius);

                    if (InArea(xNew, yNew))
                    {
                        retX->GetAt(i) = xNew;
                        retY->GetAt(i) = yNew;

                        bNodeMoved = true;
                    }

                    bTooClose = true;
                }
            }

            //	If none of the nodes moved, then it means either that all nodes
            //	are in place or that none were able to move. Either way, we're done

            if (!bNodeMoved)
            {
                if (bTooClose)
                    bConstraints = false;
                return bConstraints;
            }

            //	Otherwise, we loop

            iTries--;
        }

        //	If we get this far, then we couldn't do it

        bConstraints = false;
    }

    //	Done

    return bConstraints;
}