예제 #1
0
파일: Accumulate.c 프로젝트: LukeMeszar/CAS
void AccumulateAnInhComp (Binding symComp, Binding inhComp) {
/* on entry:
     symComp is an accumulating computation in a TREE symbol context.
     It inherits accumulated computations from inhComp.
   on exit:
     The accumulated computations from inhComp are accumulated.
     The xref properties of ruleComp and inhComp are set.
     It is checked that inhComp is accumulating and 
     has the type VOID.
*/ 
   DefTableKey symKey = KeyOf (symComp);
   DefTableKey inhAttr = GetAttribute (KeyOf (inhComp), NoKey);
   PExprList elst = GetAccuExecList (KeyOf (inhComp), NULLPExprList);

#ifdef ACCUTEST
  printf ("AccumulateAnInhComp line %d inherits from %d\n",
          LineOf (*(GetCoord(KeyOf(symComp), ZeroCoord))),
          LineOf (*(GetCoord(KeyOf(inhComp), ZeroCoord))));
#endif

   while (elst != NULLPExprList) {
     ResetAccuExecList 
       (symKey,
        ConsPExprList 
          (HeadPExprList (elst), GetAccuExecList (symKey, NULLPExprList)));
     elst = TailPExprList (elst);
   }

   elst = GetAccuDepList (KeyOf (inhComp), NULLPExprList);
   while (elst != NULLPExprList) {
     ResetAccuDepList 
       (symKey,
        ConsPExprList 
          (HeadPExprList (elst), GetAccuDepList (symKey, NULLPExprList)));
     elst = TailPExprList (elst);
   }

   ResetAccuLhs (symKey, GetAccuLhs (KeyOf (inhComp), NULLPExpr));

   /* The property yields an xref list of those computation which 
      are affected by the inherited computation: */
   ResetInheritedBy (KeyOf (inhComp),
     ConsDefTableKeyList (KeyOf (symComp), 
                          GetInheritedBy (KeyOf (inhComp), 
                                          NULLDefTableKeyList)));

   if (!(GetIsAccu (KeyOf (inhComp), 0))) {
      message (ERROR, CatStrInd ("Is inherited by an accumulating computation: ",
                                 GetNameSym (inhAttr, 0)),
               0, GetCoord (KeyOf (inhComp), ZeroCoord));
      message (ERROR, CatStrInd ("Inherits a non-accumulating computation: ",
                                 GetNameSym (inhAttr, 0)),
               0, GetCoord (KeyOf (symComp), ZeroCoord));
   }
#ifdef ACCUTEST
  printf ("AccumulateAnInhComp end\n");
#endif
}/* AccumulateAnInhComp */
예제 #2
0
void PolygonGroup::DebugDraw()
{
    RenderManager::Instance()->SetColor(1.0f, 0.0f, 0.0f, 1.0f);
    for (int k = 0; k < indexCount / 3; ++k)
    {
        Vector3 v0, v1, v2;
        GetCoord(indexArray[k * 3 + 0], v0);
        GetCoord(indexArray[k * 3 + 1], v1);
        GetCoord(indexArray[k * 3 + 2], v2);
        RenderHelper::Instance()->DrawLine(v0, v1);
        RenderHelper::Instance()->DrawLine(v1, v2);
        RenderHelper::Instance()->DrawLine(v0, v2);
    }
}
예제 #3
0
void SSvgWnd::ToCenter()
{
	YSRECT rWnd = GetClientRect();
	SSvgObject *pFirstObj = m_Document.GetRootObject();
	if(pFirstObj == NULL)
		return ;
	int svgw = GetCoord(pFirstObj->GetRect()->right);
	int svgh = GetCoord(pFirstObj->GetRect()->bottom);

	int x,y;
	x = (rWnd.right - svgw)/2;
	y = (rWnd.bottom - svgh)/2;
	SetOffset(x,0);
}
예제 #4
0
/* --------------------------------------------------------------------
* FUNCTION NAME: Draw
* DESCRIPTION  : Draws Combobox on console, will check whether to draw
*				  One label or the entire combobox using _isOpen.
* RETURN       : None.
* NOTES        : Polymorphic function - inherited from Widget.
* -------------------------------------------------------------------- */
void ComboBox::Draw(COORD CursorPosition, const HANDLE& console)
{
	if (!_comboNames.size())
		return;
	if (!_isSorted) {
		SortArray();
	}
	strVecItr itr = _comboNames.begin();
	if (!_isOpen) {
		_isOpen = true;
		CursorPosition = GetCoord();
		clearWidget(CursorPosition, console, GetLongestString() + 6, _comboNames.size()*HEIGHT_OF_CELL);
		while (itr->index != _selected)
			itr++;
		DrawItem(CursorPosition, console, itr, true);
	}
	else {
		while (itr != _comboNames.end())
		{
			_isOpen = false;
			if (itr->index == _selected)
				DrawItem(CursorPosition, console, itr, true);
			else
				DrawItem(CursorPosition, console, itr, false);
			CursorPosition.Y += 2;
			++itr;
		}
	}
}
예제 #5
0
void PolygonGroup::CreateBaseVertexArray()
{
	SafeDeleteArray(baseVertexArray);
	baseVertexArray = new Vector3[vertexCount];

	for (int v = 0; v < vertexCount; ++v)
	{
		GetCoord(v, baseVertexArray[v]);
	}
}
예제 #6
0
void PolygonGroup::RecalcAABBox()
{
    // recalc aabbox
    for (int vi = 0; vi < vertexCount; ++vi)
    {
        Vector3 point;
        GetCoord(vi, point);
        aabbox.AddPoint(point);
    }
}
예제 #7
0
bool RadioList::CheckPosition(COORD clickedPosition) const
{
	COORD tmp = GetCoord();
	int y = tmp.Y + (_numberOfItems * HEIGHT_OF_CELL);
	int x = tmp.X + GetLongestString() + 6;
	if (y < clickedPosition.Y || tmp.Y > clickedPosition.Y)
		return false;
	if (x < clickedPosition.X || tmp.X > clickedPosition.X)
		return false;
	return true;
}
예제 #8
0
bool CGWIC_Cell::LoadObjectStates()
{
	path filenm = GWIC_CELLSTORE_DIR;
	filenm += GetCellFileSuffix();
	filenm += ".xml";
	IXMLReader* xml = graphics->getFileSystem()->createXMLReader(filenm);
	if (!xml) {
		std::cerr << "LoadObjectStates(): can't create xml reader for " << filenm.c_str() << std::endl;
		return false;
	}
	const stringw tg_obj(L"object");
	const stringw tg_pos(L"position");
	const stringw tg_opt(L"options");
	stringw cur_tag;
	path cfile;
	CIrrStrParser pos,rot,scl;
	CGWIC_GameObject* optr = NULL;
	while (xml->read()) {
		switch (xml->getNodeType()) {
		case EXN_ELEMENT:
			if ((cur_tag.empty()) && (tg_obj.equals_ignore_case(xml->getNodeName()))) {
				cur_tag = tg_obj;
				cfile = xml->getAttributeValueSafe(L"file");
				optr = new CGWIC_GameObject(cfile,GetCoord(),graphics,physics);
				if (!optr)
					std::cerr << "Failed to create object from " << cfile.c_str() << std::endl;
				else
					objects.push_back(optr);
			} else if ((cur_tag == tg_obj) && (optr)) {
				if (tg_pos.equals_ignore_case(xml->getNodeName())) {
					pos = xml->getAttributeValueSafe(L"pos");
					rot = xml->getAttributeValueSafe(L"rot");
					scl = xml->getAttributeValueSafe(L"scale");
					optr->SetPos(pos.ToVector3f());
					optr->SetScale(scl.ToVector3f());
					optr->SetRot(rot.ToVector3f());
				} else if (tg_pos.equals_ignore_case(xml->getNodeName())) {
					optr->SetPhysical(xml->getAttributeValueAsInt(L"physical"));
					optr->SetEnabled(xml->getAttributeValueAsInt(L"enabled"));
				}
			}
			break;
		case EXN_ELEMENT_END:
			cur_tag = L"";
			optr = NULL;
			break;
		default: break;
		}
	}
	xml->drop();
	return false;
}
예제 #9
0
bool CGWIC_Cell::CreateNewObject(irr::core::vector3df pnt, irr::io::path filename)
{
	CGWIC_GameObject* nobj;
	nobj = new CGWIC_GameObject(filename,GetCoord(),graphics,physics);
	if (nobj->GetRootNode()) {
		objects.push_back(nobj);
		nobj->SetPos(pnt);
		nobj->SetEnabled(true);
		nobj->SetPhysical(true);
		return true;
	}
	delete nobj;
	std::cerr << "Couldn't create new object!" << std::endl;
	return false;
}
예제 #10
0
void RadioList::Draw(COORD CursorPosition, const HANDLE& console)
{
	if (!_numberOfItems)
		return;
	CursorPosition = GetCoord();
	node* iterator = _head;

	while (iterator)
	{
		if (iterator->index == _current->index)
			DrawItem(CursorPosition, console, iterator, true, iterator->checked);
		else
			DrawItem(CursorPosition, console, iterator, false, iterator->checked);
		CursorPosition.Y += 2;

		iterator = iterator->next;
	}
}
예제 #11
0
/* --------------------------------------------------------------------
* FUNCTION NAME: CheckPosition
* DESCRIPTION  : Recives position of click and check if is in widget.
* RETURN       : True - if is in widget, false otherwise.
* NOTES        : Polymorphic function - inherited from Widget.
* -------------------------------------------------------------------- */
bool ComboBox::CheckPosition(COORD clickedPosition) const
{
	COORD tmp = GetCoord();
	if (!_isOpen) {
		int y = tmp.Y + (_comboNames.size() * HEIGHT_OF_CELL);
		int x = tmp.X + GetLongestString() + 6;
		if (y < clickedPosition.Y || tmp.Y > clickedPosition.Y)
			return false;
		if (x < clickedPosition.X || tmp.X > clickedPosition.X)
			return false;
	}
	else {
		int y = tmp.Y + 1;
		int x = tmp.X + GetLongestString() + 6;
		if (y < clickedPosition.Y || tmp.Y > clickedPosition.Y)
			return false;
		if (x < clickedPosition.X || tmp.X > clickedPosition.X)
			return false;
	}
	
	return true;
}
예제 #12
0
float plugin::screen::GetCoord(float a, eScreenCoordTranslationSide side) {
    switch (side) {
    case SIDE_ANY:
        return GetCoord(a);
    case SIDE_LEFT:
        return GetCoordLeft(a);
    case SIDE_RIGHT:
        return GetCoordRight(a);
    case SIDE_TOP:
        return GetCoordTop(a);
    case SIDE_BOTTOM:
        return GetCoordBottom(a);
    case SIDE_CENTER_LEFT:
        return GetCoordCenterLeft(a);
    case SIDE_CENTER_RIGHT:
        return GetCoordCenterRight(a);
    case SIDE_CENTER_UP:
        return GetCoordCenterUp(a);
    case SIDE_CENTER_DOWN:
        return GetCoordCenterDown(a);
    }
    return 0.0f;
}
예제 #13
0
void PolygonGroup::ApplyMatrix(const Matrix4 & matrix)
{
    aabbox = AABBox3(); // reset bbox
    
    Matrix4 normalMatrix4;
    matrix.GetInverse(normalMatrix4);
    normalMatrix4.Transpose();
    Matrix3 normalMatrix3;
    normalMatrix3 = normalMatrix4;

    for (int32 vi = 0; vi < vertexCount; ++vi)
    {
        Vector3 vertex;
        GetCoord(vi, vertex);
        vertex = vertex * matrix;
        SetCoord(vi, vertex);
        
        Vector3 normal;
        GetNormal(vi, normal);
        normal = normal * normalMatrix3;
        SetNormal(vi, normal);
    }    
}
예제 #14
0
int
main (int argc, char **argv)
{
    char            *inFname = "stdin"; /* Name of input source */
    char            *outFname = "stdout";  /* Name of output destination */
    char            *Label;             /* Names of input coordinates */
    char            Tail[4096] = {0};   /* Rest of input line beyond coords */
    extern char     *bu_optarg;         /* argument from bu_getopt(3C) */
    FILE            *inPtr = stdin;     /* Pointer to input */
    FILE            *outPtr = stdout;   /* Pointer to output */
    double          Azim = 0.0;         /* Azimuth angle (in degrees) */
    double          Elev = 0.0;         /* Elevation angle (in degrees) */
    double          CelSiz = 1.0;       /* Size of cells (dimensionless) */
    double          Cazim;              /* Cosine of the azimuth angle */
    double          Celev;              /* Cosine of the elevation angle */
    double          Sazim;              /* Sine of the azimuth angle */
    double          Selev;              /* Sine of the elevation angle */
    double          U1;                 /* Input coords of current point */
    double          V1;                 /*   "      "    "    "      "   */
    double          W1;                 /*   "      "    "    "      "   */
    double          U2;			/* Output coords of current point */
    double          V2;                 /*   "      "    "    "      "   */
    double          W2;                 /*   "      "    "    "      "   */
    double          UU;                 /* Weight of U1 in computing U2 */
    double          UV;                 /*    "    " U1  "     "     V2 */
    double          UW;                 /*    "    " U1  "     "     W2 */
    double          VU;                 /* Weight of V1 in computing U2 */
    double          VV;                 /*    "    " V1  "     "     V2 */
    double          VW;                 /*    "    " V1  "     "     W2 */
    double          WU;                 /* Weight of W1 in computing U2 */
    double          WV;                 /*    "    " W1  "     "     V2 */
    double          WW;                 /*    "    " W1  "     "     W2 */
    int             Invert = 0;		/* Undo az-el rotation? */
    int             PlanarProj = 0;	/* Project points onto plane? */
    int             Round = 0;		/* Round the output coords? */
    int             LineNm = 0;         /* How far through input? */
    int             Ch;                 /* Input character */
    int             i;                  /* Dummy variable for loop indexing */
    extern int      bu_optind;             /* index from bu_getopt(3C) */

    /* Handle command-line options */
    while ((Ch = bu_getopt(argc, argv, OPT_STRING)) != EOF)
	switch (Ch)
	{
	    case 'a':
		if (sscanf(bu_optarg, "%lf", &Azim) != 1)
		{
		    (void) fprintf(stderr,
				   "Bad azimuth specification: '%s'\n", bu_optarg);
		    PrintUsage();
		}
		break;
	    case 'c':
		if (sscanf(bu_optarg, "%lf", &CelSiz) != 1)
		{
		    (void) fprintf(stderr,
				   "Bad cell-size specification: '%s'\n", bu_optarg);
		    PrintUsage();
		}
		break;
	    case 'e':
		if (sscanf(bu_optarg, "%lf", &Elev) != 1)
		{
		    (void) fprintf(stderr,
				   "Bad elevation specification: '%s'\n", bu_optarg);
		    PrintUsage();
		}
		break;
	    case 'i':
		Invert = 1;
		break;
	    case 'p':
		PlanarProj = 1;
		break;
	    case 'r':
		Round = 1;
		break;
	    default:
		fprintf(stderr, "Bad option '-%c'\n", Ch);
	    case '?':
		PrintUsage();
	}

    if (PlanarProj && Invert)
    {
	fputs("Incompatible options: -i and -p\n", stderr);
	PrintUsage();
    }

    /* Determine source and destination */
    if (argc - bu_optind > 0)
    {
	inFname = argv[bu_optind];
	if ((inPtr = fopen(inFname, "r")) == NULL)
	{
	    bu_exit(1, "azel:  Cannot open file '%s'\n", inFname);
	}
	if (argc - bu_optind > 1)
	{
	    outFname = argv[bu_optind + 1];
	    if ((outPtr = fopen(outFname, "w")) == NULL)
	    {
		bu_exit(1, "azel:  Cannot create file '%s'\n", outFname);
	    }
	}
	if (argc - bu_optind > 2)
	{
	    PrintUsage();
	}
    }

    /* Compute transformation coefficients */
    Cazim = cos(Azim * DEG2RAD);
    Celev = cos(Elev * DEG2RAD);
    Sazim = sin(Azim * DEG2RAD);
    Selev = sin(Elev * DEG2RAD);
    if (Invert)
    {
	UU = Celev * Cazim;
	VU = -Sazim;
	WU = -(Selev * Cazim);
	UV = Celev * Sazim;
	VV = Cazim;
	WV = -(Selev * Sazim);
	UW = Selev;
	VW = 0.0;
	WW = Celev;
    }
    else
    {
	UU = Celev * Cazim;
	VU = Celev * Sazim;
	WU = Selev;
	UV = -Sazim;
	VV = Cazim;
	WV = 0.0;
	UW = -(Selev * Cazim);
	VW = -(Selev * Sazim);
	WW = Celev;
    }

/* * * * * Filter Data * * * * */
    Label = Invert ? "DHV" : "XYZ";

    while ((Ch = fpeek(inPtr)) != EOF)
    {
/* Read U1, V1, and W1 of next point in input frame of reference */
	GetCoord(inPtr, &U1, *Label, LineNm + 1, inFname);
	GetCoord(inPtr, &V1, *(Label + 1), LineNm + 1, inFname);
	GetCoord(inPtr, &W1, *(Label + 2), LineNm + 1, inFname);

/* Compute U2, V2, and W2 for this point */
	U2 = (U1 * UU + V1 * VU + W1 * WU) / CelSiz;
	V2 = (U1 * UV + V1 * VV + W1 * WV) / CelSiz;
	W2 = (U1 * UW + V1 * VW + W1 * WW) / CelSiz;

	if (Round)
	{
	    U2 = floor(U2 + .5);
	    V2 = floor(V2 + .5);
	    W2 = floor(W2 + .5);
	}

/* Read in the rest of the line for subsequent dumping out */
	for (i = 0; (Ch = fgetc(inPtr)) != '\n'; i++)
	    if (Ch == EOF)
	    {
		Tail[i] = '\n';
		break;
	    }
	    else
		Tail[i] = Ch;
	Tail[i] = '\0';

/* Write out the filtered version of this line */
	if (! PlanarProj)
	    fprintf(outPtr, "%g\t", U2);
	fprintf(outPtr, "%g\t%g\t%s\n", V2, W2, Tail);
	LineNm++;
    }
    bu_exit (0, NULL);
}
예제 #15
0
float plugin::screen::GetCoordCenterDown(float a) {
    return GetScreenCenterY() + GetCoord(a);
}
예제 #16
0
float plugin::screen::GetCoordCenterUp(float a) {
    return GetScreenCenterY() - GetCoord(a);
}
예제 #17
0
float plugin::screen::GetCoordCenterRight(float a) {
    return GetScreenCenterX() + GetCoord(a);
}
예제 #18
0
float plugin::screen::GetCoordCenterLeft(float a) {
    return GetScreenCenterX() - GetCoord(a);
}
예제 #19
0
float plugin::screen::GetCoordBottom(float a) {
    return GetScreenHeight() - GetCoord(a);
}
예제 #20
0
float plugin::screen::GetCoordTop(float a) {
    return GetCoord(a);
}
예제 #21
0
float plugin::screen::GetCoordRight(float a) {
    return GetScreenWidth() - GetCoord(a);
}
예제 #22
0
float plugin::screen::GetCoordLeft(float a) {
    return GetCoord(a);
}
예제 #23
0
파일: Accumulate.c 프로젝트: LukeMeszar/CAS
void AccuInheritAtTreeSymbs (Environment globEnv) {
/* on entry:
       The internal representations of all single accumulating computations
       have been associated to the properties AccuLhs, AccuExecList, 
       AccuDepList of the computation key.
       The other Accu-properties are set.
       The inheritance relations in the computation scopes are established.
       The attribute types are determined.
   on exit:
       Each TREE symbol X has collected the accumulated computations from
       any CLASS Symbol it inherits from, stored in its properties AccuLhs, 
       AccuExecList, AccuDepList of X's computation key.
*/
  Binding symBind = DefinitionsOf (globEnv);

#ifdef ACCUTEST
  printf ("AccuInheritAtTreeSymbs begin\n");
#endif

  while (symBind != NoBinding) {
    DefTableKey symKey = KeyOf (symBind);
    if (GetIsNonterm (symKey, 0) && GetIsTreeSym (symKey, 0)) {
       Environment attrenv = GetAttrScope (symKey, NoEnv);
       Binding attr;
       Environment symLowScope = GetLowerScope (symKey, NoEnv);
       Environment symUpScope = GetUpperScope (symKey, NoEnv);
 
      /* search all attributes of this symbol for accumulating ones: */
         attr = DefinitionsOf (attrenv);
         while (attr != NoBinding) {
          if (InheritAttrAccu (attr)) {
             int attrId = IdnOf (attr);
             int attrCl = GetAttrClass (KeyOf (attr), NoClass);
             Environment symScope = 
                (attrCl == SYNTClass ? symLowScope : symUpScope);
             Binding inhComp, classSym;
             Binding symComp = BindingInEnv (symScope, attrId);
#ifdef ACCUTEST
  printf ("    accu attribute %s.%s\n",
     StringTable (GetNameSym (symKey, 0)),
     StringTable (attrId));
#endif
             if (symComp == NoBinding) {
                /* no symbol computation, no inherited computation 
                   create a symbol computation */
                symComp = 
                   MakeAnAccuBinding (symScope, attr, symKey, 
                                      GetCoord (symKey, ZeroCoord));
                ResetAccuLhs (KeyOf (symComp), 
                              newAttrAccSymb (symKey, KeyOf (attr), 0, 
                                              GetCoord (symKey, ZeroCoord)));
                break; /* no further action for this attr */
             } else if (EnvOf (symComp) == symScope) {
                inhComp = OverridesBinding (symComp);
                if (inhComp == NoBinding) 
                    /* a symbol computation, no inherited computation */
                    break; /* no action for this attr */
                /* else a symbol computation, an inherited computation */
             } else {
                /* no symbol computation, only inherited computations */
                /* create a symbol computation: */
                inhComp = symComp;
                symComp = 
                   MakeAnAccuBinding (symScope, attr, symKey, 
                                      GetCoord (symKey, ZeroCoord));
                ResetInheritedFrom (KeyOf (symComp), inhComp);
                ResetAccuLhs (KeyOf (symComp), 
                              newAttrAccSymb (symKey, KeyOf (attr), 0, 
                                              GetCoord (symKey, ZeroCoord)));
             }
             /* There are inherited computations to be accumulated on symComp: 
                We step through all symbols and search in their 
                computation scopes inhCompScope which 
                     Inheritsfrom (symScope, inhCompScope), 
                whether it has a computation to be accumulated on symComp.
             */
#ifdef ACCUTEST
  printf ("    there are inherited computations for %s.%s\n",
     StringTable (GetNameSym (symKey, 0)),
     StringTable (attrId));
#endif
             classSym = DefinitionsOf (globEnv);
             while (classSym != NoBinding) {
               DefTableKey k = KeyOf (classSym);
               if (k != symKey && GetIsSymbol (k, 0)) {
                  Environment inhCompScope =
                    (attrCl == SYNTClass ? 
                     GetLowerScope (k, NoEnv) : GetUpperScope (k, NoEnv));
                  if (Inheritsfrom (symScope, inhCompScope)) {
                     /* inheritance relation holds */
#ifdef ACCUTEST
  printf ("    inherits from class %s\n", StringTable (GetNameSym (k, 0)));
#endif
                     Binding attrComp = DefinitionsOf (inhCompScope);
                     while (attrComp != NoBinding) {
                       if (IdnOf (attrComp) == attrId) {
                           if (!GetIsAccu (KeyOf (attrComp), 0)) {
                             message (ERROR, 
                               CatStrInd ("Is inherited by an accumulating computation: ",
                                          attrId), 0, 
                               GetCoord (KeyOf(attrComp), ZeroCoord));
                               break;
                          } else if (GetIsTreeSym (k, 0)) {
                             message (ERROR, 
                               CatStrInd ("Can not inherit from a TREE symbol: ",
                                 attrId), 0, GetCoord (KeyOf(attrComp), ZeroCoord));
                             break;
                         } /* IsClass */
                         /* this computation is to be accumulated to symComp */

                         AccumulateAnInhComp (symComp, attrComp);

                         /* there is only one such computation in a scope: */
                         break;
                       }/* attr comps of this class symb */
                       attrComp = NextDefinition (attrComp);
                     }/* end search for a computation in a super scope */
                  }/* a super scope */
               }/* a symbol */
               classSym = NextDefinition (classSym);
             }/* a global definition */
          } /* accu attr */
          attr = NextDefinition (attr);
       }/* attributes */
    }/* IsTreeSym */
    symBind = NextDefinition (symBind);
  }/* definitions */
#ifdef ACCUTEST
  printf ("AccuInheritAtTreeSymbs end\n");
#endif
}/* AccuInheritAtTreeSymbs */
예제 #24
0
파일: brush.c 프로젝트: kellyrm/Q1
/*
=================
CheckFace

Note: this will not catch 0 area polygons
=================
*/
void CheckFace (face_t *f)
{
	int	i, j;
	vec_t	*p1, *p2;
	vec_t	d, edgedist;
	vec3_t	dir, edgenormal, facenormal;

	if (f->numpoints < 3)
		Message (MSGWARN, "CheckFace: Face with too few (%i) points at %s", f->numpoints, GetCoord (f->pts[0]));

	VectorCopy (planes[f->planenum].normal, facenormal);
	if (f->planeside)
	{
		VectorSubtract (vec3_origin, facenormal, facenormal);
	}

	for (i=0 ; i<f->numpoints ; i++)
	{
		p1 = f->pts[i];

		for (j=0 ; j<3 ; j++)
			if (p1[j] > BOGUS_RANGE || p1[j] < -BOGUS_RANGE)
				Message (MSGERR, "CheckFace: BOGUS_RANGE: %s", GetCoord (p1));

		j = i+1 == f->numpoints ? 0 : i+1;

	// check the point is on the face plane
		d = DotProduct (p1, planes[f->planenum].normal) - planes[f->planenum].dist;
		if (d < -ON_EPSILON || d > ON_EPSILON)
		{
			Message (MSGWARN, "CheckFace: Healing point %s off plane by %.3g", GetCoord (p1), d);

			// Adjust point to plane
			VectorMA (p1, -d, planes[f->planenum].normal, f->pts[i]);
			p1 = f->pts[i];
		}

	// check the edge isn't degenerate
		p2 = f->pts[j];
		VectorSubtract (p2, p1, dir);

		if (VectorLength (dir) < ON_EPSILON)
		{
			Message (MSGWARN, "CheckFace: Healing degenerate edge at %s", GetCoord (p1));
			for (j=i+1; j<f->numpoints; j++)
				VectorCopy(f->pts[j], f->pts[j-1]);
			ResizeFace (f, f->numpoints - 1);
			CheckFace(f);
			break;
		}

		CrossProduct (facenormal, dir, edgenormal);
		VectorNormalize (edgenormal);
		edgedist = DotProduct (p1, edgenormal);
		edgedist += ON_EPSILON;

	// all other points must be on front side
		for (j=0 ; j<f->numpoints ; j++)
		{
			if (j == i)
				continue;
			d = DotProduct (f->pts[j], edgenormal);
			if (d > edgedist)
				Message (MSGERR, "CheckFace: Non-convex at %s", GetCoord (p1));
		}
	}
}
예제 #25
0
파일: Accumulate.c 프로젝트: LukeMeszar/CAS
void AccumulateInherit (Environment globEnv) {
/* on entry:
       The internal representations of all single accumulating computations
       have been associated to the properties AccuLhs, AccuExecListe, 
       AccuDepList of the computation key.
       The other Accu-properties are set.
       The inheritance relation in the computation scopes are established.
       The attribute types are determined.
   on exit:
       AccuInheritAtTreeSymbs collects for every TREE symbol the inherited
         accumulated computations.
       for every rule 
          the rule the accumulating rule computations are collected, and 
          for every symbol occurrence symocc
            the accumulating computations are instantiated from the corresponding
            TREE symbols.
*/
  RuleProdList rules;
#ifdef ACCUTEST
  printf("AccumulateInherit begin\n");
#endif
  ex42 = newIntValue (42, ZeroCoord);

  AccuInheritAtTreeSymbs (globEnv);
  /* for each accu. attr. of each TREE symbol all computations inherited 
     from CLASS symbols are combined in the 3 accu properties of the TREE symbol
     now
     instantiate the computations from TREE symbols to symbol occurrences:
  */

  /* step through all productions: */
  rules = GrammarRules;
  while (rules != NULLRuleProdList)
  { RuleProd rule = HeadRuleProdList (rules);
    ProdSymbolList prod = rule->prod;
    DefTableKey ruleKey = RuleKeyOfRuleProd (rule);
    Binding rulecomp;
    Environment ruleScope = GetLowerScope (ruleKey, NoEnv);
    int symbolIndex = -1;
#ifdef ACCUTEST
  printf ("RULE %s:\n", 
     StringTable (GetNameSym (ruleKey, 0)));
#endif
    /* search the rule attributes for accumulating computations: */
    rulecomp = DefinitionsOf(ruleScope);
    while (rulecomp != NoBinding)
    { if (GetIsAccu (KeyOf (rulecomp), 0)) {
         /* The computations for this attribute have been accumulated
            in three properties; combine them into one assign: */
         ResetCompRepr 
            (KeyOf (rulecomp), MakeAccuAssign (KeyOf (rulecomp)));
      }
      rulecomp = NextDefinition(rulecomp);
    }

    /* step through all nonterminal occurrences of this production: */
    while (prod != NULLProdSymbolList) { 
      ProdSymbol sy = HeadProdSymbolList (prod);
      DefTableKey symKey = sy->u.s.symbolkey;
      if (sy->kind != IsProdLiteral && !GetIsTerm (symKey, 0)) { 
        Environment syCompScope = sy->u.s.scope;
        Environment attrenv = GetAttrScope (symKey, NoEnv);
        Binding attr = DefinitionsOf (attrenv);
        symbolIndex++;

#ifdef ACCUTEST
  printf ("   symbol no. %d %s\n", symbolIndex, 
     StringTable (GetNameSym (symKey, 0)));
#endif
        /* search all attributes of this symbol for accumulating ones: */
        while (attr != NoBinding) {
          if (GetHasAccuAsgn (KeyOf (attr), 0) &&
              ((symbolIndex > 0 && 
                GetAttrClass (KeyOf (attr), NoClass) == INHClass) ||
               (symbolIndex == 0 && 
                GetAttrClass (KeyOf (attr), NoClass) == SYNTClass))) {
             int attrId = IdnOf (attr);
             /* symbol symKey has an accumulating attribute named attrId */
             Binding symOccAttrComp = BindingInEnv (syCompScope, attrId);
             Binding symAttrComp;
             PExpr assign;

#ifdef ACCUTEST
  printf ("    attribute %s.%s\n",
     StringTable (GetNameSym (symKey, 0)),
     StringTable (GetNameSym (KeyOf (attr), 0)));
#endif
             if (symOccAttrComp == NoBinding) {
                /* no computation exists for this attr at all, create one: */
                symOccAttrComp =
                   MakeAnAccuBinding (syCompScope, attr, ruleKey, ZeroCoord);
                ResetCompRepr (KeyOf (symOccAttrComp),
                     newAssign (newAttrAccRule (sy, KeyOf (attr), 0, ZeroCoord),
                                ex42, ZeroCoord));
             } else if (EnvOf (symOccAttrComp) != syCompScope) {
               /* there are computations to be inherited */
               /* there is no computation in the symbol occurrence,
                  we create one: */
               symAttrComp = symOccAttrComp;
               symOccAttrComp = 
                 MakeAnAccuBinding (syCompScope, attr, ruleKey, 
                     GetCoord (KeyOf (symAttrComp), ZeroCoord));
               ResetInheritedFrom (KeyOf (symOccAttrComp), symAttrComp);

               assign =
                  copyExpr (MakeAccuAssign (KeyOf (symAttrComp)));
               instantiateExpr (assign, rule, sy);
               ResetCompRepr (KeyOf (symOccAttrComp), assign);
               ResetIsBottomUp (KeyOf(symOccAttrComp), 
                 GetIsBottomUp (KeyOf(symAttrComp), 0));
             } else {
                  symAttrComp = OverridesBinding (symOccAttrComp);
                  if (symAttrComp == NoBinding) {
                     /* there are no symbol computations,
                        combine the 3 properties in rule context:
                     */
                     ResetCompRepr (KeyOf (symOccAttrComp), 
                                    MakeAccuAssign (KeyOf (symOccAttrComp)));
                  } else {
                       /*  There are properties in symbol context (symAttrComp)
                           and 3 properties in the symbol occurrence (symOccAttrComp).
                           Instantiate the symbol computation:
                       */
                     assign = copyExpr (MakeAccuAssign (KeyOf(symAttrComp)));
                     instantiateExpr (assign, rule, sy);
                     /* decompose assign onto symOccAttrComp: */
                     AccumulateExpr (KeyOf (symOccAttrComp), assign);
                     /* compose the 3 properties into an assign: */
                     assign = MakeAccuAssign (KeyOf (symOccAttrComp));
                     ResetCompRepr (KeyOf (symOccAttrComp), assign);
                  }
             }
          }/* an accumulating attribute of the symbol occurrence */
          attr = NextDefinition (attr);
        }/* the attributes of the symbol occurrence */
      }/* is a non-terminal occurrence in the rule */
      if (rule->islistof) break; /* lhs only */
      prod = TailProdSymbolList (prod);
    }/* all rule elements */
    rules = TailRuleProdList (rules);
  }/* all rules */
#ifdef ACCUTEST
  printf("AccumulateInherit end\n");
#endif
}/* AccumulateInherit */
예제 #26
0
// Copyright (c) 2016-present, Facebook, Inc.
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant 
// of patent rights can be found in the PATENTS file in the same directory.
// 

#include "playout_multithread.h"
#include "tree_search.h"
#include "../local_evaluator/cnn_local_exchanger.h"
#include "../local_evaluator/cnn_exchanger.h"

// ======================== Utilities functions =================================
Move compose_move(int x, int y, Stone player) {
  Move move = { .x = x, .y = y, .m = GetCoord(x, y), .player = player };
  return move;
}

Move compose_move2(Coord m, Stone player) {
  Move move = { .x = X(m), .y = Y(m), .m = m, .player = player };
  return move;
}

// =================================== Internal datastructure ==============================
// How many channels / GPUs we have
#define MAX_MOVE 1000

typedef struct SearchHandle {
  SearchParamsV2 params;
  // Dynamic global parameters that change over time (e.g., dynkomi).
예제 #27
0
int SSvgWnd::OnMouseMove(int nFlag,SPoint point)
{
	bool bTip=false;
	if(m_iMoving > 0)
	{
		int sx=point.x - m_ptLast.x;
		int sy=point.y - m_ptLast.y;
		m_ptLast = point;
		m_iOffsetX += sx;
		m_iOffsetY += sy;
		//判断是否超出画板范围
		YSRECT rWnd = GetClientRect();
		int wndw = rWnd.right - rWnd.left;
		int wndh = rWnd.bottom - rWnd.top;
		SSvgObject *pFirstObj = m_Document.GetRootObject();
		if(pFirstObj == NULL)
			return 1;
		int svgw = GetCoord(pFirstObj->GetRect()->right);
		int svgh = GetCoord(pFirstObj->GetRect()->bottom);
		if(wndw < svgw)
		{
			//窗口宽度小于SVG宽度时
			if(m_iOffsetX < wndw-svgw)
				m_iOffsetX = wndw-svgw;
			if(m_iOffsetX > 0)
				m_iOffsetX = 0;
		}
		else
		{
			//窗口宽度大于SVG宽度时
			if(m_iOffsetX < 0)
				m_iOffsetX = 0;
			if(m_iOffsetX > wndw - svgw)
				m_iOffsetX = wndw - svgw;
		}
		if(wndh < svgh)
		{
			//窗口高度小于SVG宽度时
			if(m_iOffsetY < wndh-svgh)
				m_iOffsetY = wndh-svgh;
			if(m_iOffsetY > 0)
				m_iOffsetY = 0;
		}
		else
		{
			//窗口高度大于SVG宽度时
			if(m_iOffsetY < 0)
				m_iOffsetY = 0;
			if(m_iOffsetY > wndh - svgh)
				m_iOffsetY = wndh - svgh;
		}
		RedrawWindow();
		m_iMoving = 2;
	}
	else
	{
		float x = GetSvgCoord(point.x - m_iOffsetX);
		float y = GetSvgCoord(point.y - m_iOffsetY);
		SSvgObject *pObj = m_Document.GetRootObject();
		if(pObj)
			pObj = pObj->GetChild();
		if(pObj)
			pObj = pObj->GetNext();
		pObj = IsObjectInPoint(pObj,x,y);
		if(pObj != NULL)
		{
			SString caption = pObj->GetAttribute("caption");
			if(caption.length() > 0)
			{
				QPoint p(point.x,point.y);
				p = this->mapToGlobal(p);
				QToolTip::showText(p,caption.data());
				bTip=true;
			}
		}
	}
	if(!bTip)
	{
		QToolTip::hideText();
	}
	return 1;
}
예제 #28
0
EXPORT int   SCHEMA::SchemaMatrCos( int QntNode, WORD ListNode[], double *MatrCosOut )
{
      int i;
      CK *pCK, *pCK1;
      double a, Matr[9], B[4];
      double axx, axy, axz, ax, ayy, ayz, ay, azz, az, Eps;

      memset(MatrCosOut,0,9*sizeof(double));
      memset(Matr,0,9*sizeof(double));
      MatrCosOut[0] = 1;  MatrCosOut[4] = 1;  MatrCosOut[8] = 1;

      if ( QntNode < 3 ) return 1;
      pCK1 = GetCoord(ListNode[0]);

      axx = axy = axz = ax = ayy = ayz = ay = azz = az = 0;
      for ( i=0; i<QntNode; i++ ) {
         pCK = GetCoord(ListNode[i]);
         if ( pCK == NULL ) continue;
         axx += ( pCK->x - pCK1->x ) * ( pCK->x - pCK1->x );
         axy += ( pCK->x - pCK1->x ) * ( pCK->y - pCK1->y );
         axz += ( pCK->x - pCK1->x ) * ( pCK->z - pCK1->z );
         ax  += pCK->x - pCK1->x;
         ayy += ( pCK->y - pCK1->y ) * ( pCK->y - pCK1->y );
         ayz += ( pCK->y - pCK1->y ) * ( pCK->z - pCK1->z );
         ay  += pCK->y - pCK1->y;
         azz += ( pCK->z - pCK1->z ) * ( pCK->z - pCK1->z );
         az  += pCK->z - pCK1->z;
         }


      a = axx + ayy + azz;
      Eps = 1e-3 * a;
      if ( a < 1e-3 ) return 1;
      if ( azz < Eps ) return 0;
      memset(MatrCosOut,0,9*sizeof(double));
      if ( axx < Eps ) {
		  MatrCosOut[2] = MatrCosOut[3] = MatrCosOut[7] = 1;
		  return 0;   }
      if ( ayy < Eps ) {
		  MatrCosOut[0] = MatrCosOut[7] = 1;
		  MatrCosOut[5] = -1;
		  return 0;   }
	  
      Eps = 1e-5 * axx * ayy * azz;
	  

      Matr[0] = axx;
      Matr[1] = Matr[3] = axy;
      Matr[2] = Matr[6] = axz;
      Matr[4] = ayy;
      Matr[5] = Matr[7] = ayz;
      Matr[8] = azz;
      a = det3x3(Matr);
      if ( fabs(a) > Eps ) {
         B[0] = -ax;  B[1] = -ay;  B[2] = -az;
         EEGauss(3,Matr,1,B);
         B[3] = 1;
         goto _10;  }

      Matr[0] = axx;
      Matr[1] = Matr[3] = axz;
      Matr[2] = Matr[6] = ax;
      Matr[4] = azz;
      Matr[5] = Matr[7] = az;
      Matr[8] = QntNode;
      a = det3x3(Matr);
      if ( fabs(a) >  Eps ) {
         B[0] = -axy;  B[1] = -ayz;  B[2] = -ay;
         EEGauss(3,Matr,1,B);
         B[3] = B[2];  B[2] = B[1];  B[1] = 1;
         goto _10;  }

      Matr[0] = ayy;
      Matr[1] = Matr[3] = ayz;
      Matr[2] = Matr[6] = ay;
      Matr[4] = azz;
      Matr[5] = Matr[7] = az;
      Matr[8] = QntNode;
      a = det3x3(Matr);
      if ( fabs(a) >  Eps ) {
         B[1] = -axy;  B[2] = -axz;  B[3] = -ax;
         EEGauss(3,Matr,1,&B[1]);
         B[0] = 1;
         goto _10;  }

      Matr[0] = axx;
      Matr[1] = Matr[3] = axy;
      Matr[2] = Matr[6] = ax;
      Matr[4] = ayy;
      Matr[5] = Matr[7] = ay;
      Matr[8] = QntNode;
      a = det3x3(Matr);
      if ( fabs(a) >  Eps ) {
		  B[0] = -axz;  B[1] = -ayz;  B[2] = -az;
		  EEGauss(3,Matr,1,B);
		  B[3] = B[2];  B[2] = 1;
		  goto _10;  }
	  
      return 1;
	  
_10:  a = sqrt( B[0] * B[0] + B[1] * B[1] );
      if ( fabs(a) < 1e-5 * fabs(B[2]) ) return 1;
	  
      memset(Matr,0,9*sizeof(double));
	  
      Matr[0] = -B[1] / a;
      Matr[3] =  B[0] / a;
      a = sqrt( a * a + B[2] * B[2] );
      if ( B[2] < 0 ) { B[0] = -B[0];  B[1] = -B[1];  B[2] = -B[2];  }
      else if ( B[2] == 0 ) if ( B[1] < 0 )  { B[0] = -B[0];  B[1] = -B[1];  }
      Matr[2] = B[0] / a;    Matr[5] = B[1] / a;   Matr[8] = B[2] / a;
      ax = -B[0] * B[2];   ay = -B[1] * B[2];   az = B[0] * B[0] + B[1] * B[1];
      a = sqrt( ax * ax + ay * ay + az * az );
      Matr[1] = ax / a;   Matr[4] = ay / a;  Matr[7] = az / a;
	  memcpy(MatrCosOut,Matr,9*sizeof(double));		  
      return 0;
	  
}