Exemple #1
0
/* Intersects
 * test for a common area between segment and rect.
 * return true if at least a common point is found
 */
bool EDA_RECT::Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const
{
    wxPoint point2, point4;

    if( Contains( aPoint1 ) || Contains( aPoint2 ) )
        return true;

    point2.x = GetEnd().x;
    point2.y = GetOrigin().y;
    point4.x = GetOrigin().x;
    point4.y = GetEnd().y;

    //Only need to test 3 sides since a straight line cant enter and exit on same side
    if( SegmentIntersectsSegment( aPoint1, aPoint2, GetOrigin() , point2 ) )
        return true;

    if( SegmentIntersectsSegment( aPoint1, aPoint2, point2      , GetEnd() ) )
        return true;

    if( SegmentIntersectsSegment( aPoint1, aPoint2, GetEnd()    , point4 ) )
        return true;

    return false;
}
Exemple #2
0
Widget *Container::GetWidgetAt(const Point &pos)
{
	if (!Contains(pos)) return 0;

	for (RefCountedPtr<Widget> widget : GetWidgets()) {
		const Point relpos = pos - widget->GetPosition() - widget->GetDrawOffset();
		if (widget->IsContainer()) {
			Widget* w = static_cast<Container*>(widget.Get())->GetWidgetAt(relpos);
			if (w) return w;
		} else if (widget->Contains(relpos))
			return widget.Get();
	}

	return this;
}
void CPositionDisplay::Draw(const TRect& aRect) const
{
   CWindowGc& gc = SystemGc();
   gc.SetClippingRect(aRect);
   gc.SetBrushColor(iBgClr);
   gc.SetBrushStyle(CGraphicsContext::ESolidBrush);

   //gc.Clear(aRect); //paint background color.

   gc.SetPenStyle(CGraphicsContext::ESolidPen);
   gc.SetPenColor(iOutlineClr);
   gc.SetBrushColor(iFldClr);

   if(Contains(iLatControl->Rect(), aRect) || 
      Contains(iLonControl->Rect(), aRect)){
      return;
   }
   TRect bubbles[] = {BoundingRect(iLatControl->Rect(), iLonControl->Rect())};
   const TInt num = sizeof(bubbles)/sizeof(*bubbles);
   for(TInt i = 0; i < num; ++i){
      bubbles[i].Shrink(-2,-2);
      gc.DrawRoundRect(bubbles[i], TSize(8,8));
   }
}
bool PolygonItem::ProcessLeftUp(Point p, dword keyflags)
{
	bool sel = Contains(p);

	p = GetTopRender()->ViewToScene(p);

	if (sel && !IsNull(_click))
	{
		if (abs(_click.x - p.x) < 5 && abs(_click.y - p.y) < 5)
			WhenClick(this);
	}

	_click = Null;
	return IMapItem::ProcessLeftUp(p, keyflags);
}
  int GraphicsBase::MakeHitTest(const glm::vec2& point)
  {
    if (selected_) {
      for (int i = 1; i <= HandleCount(); ++i)
      {
        if (GetHandleRect(i).Contains(point))
          return i;
      }
    }

    if (Contains(point))
      return 0;

    return -1;
  }
Exemple #6
0
Window *
WindowList::FindPreviousChildControl(Window *reference)
{
    assert(reference != nullptr);
    assert(Contains(*reference));

    std::list<Window*>::const_reverse_iterator i =
        std::find(list.rbegin(), list.rend(), reference);
#ifndef ANDROID
    /* Android's NDK r5b ships a cxx-stl which does not allow comparing
       two const_reverse_iterator objects for inequality */
    assert(i != list.rend());
#endif

    return FindControl(++i, list.rend());
}
Exemple #7
0
bool Polyhedron::Intersects(const LineSegment &lineSegment) const
{
	if (Contains(lineSegment))
		return true;
	for(int i = 0; i < NumFaces(); ++i)
	{
		float t;
		Plane plane = FacePlane(i);
		bool intersects = Plane::IntersectLinePlane(plane.normal, plane.d, lineSegment.a, lineSegment.b - lineSegment.a, t);
		if (intersects && t >= 0.f && t <= 1.f)
			if (FaceContains(i, lineSegment.GetPoint(t)))
				return true;
	}

	return false;
}
Exemple #8
0
Widget *Container::GetWidgetAt(const Point &pos)
{
	if (!Contains(pos)) return 0;

	for (WidgetIterator i = WidgetsBegin(); i != WidgetsEnd(); ++i) {
		Widget *widget = (*i).Get();
		const Point relpos = pos - widget->GetPosition() - widget->GetDrawOffset();
		if (widget->IsContainer()) {
			Widget* w = static_cast<Container*>(widget)->GetWidgetAt(relpos);
			if (w) return w;
		} else if (widget->Contains(relpos))
			return widget;
	}

	return this;
}
Exemple #9
0
//______________________________________________________________________________
void CheckMultiple(const TList& list, const char* title, const char* what)
{
  // check whether the list contains each pad only once
  
  TIter next(&list);
  AliMpPad* pad;
  while ( ( pad = (AliMpPad*)next() ) )
  {
    if ( Contains(list,*pad) != 1 )
    {
      cout << title << " " << what << " pad found more than once : " << endl;
      pad->Print();
    }
  }
      
}
Exemple #10
0
bool AABB::Intersects(const LineSegment &lineSegment) const
{
	vec dir = lineSegment.b - lineSegment.a;
	float len = dir.Length();
	if (len <= 1e-4f) // Degenerate line segment? Fall back to point-in-AABB test.
		return Contains(lineSegment.a);

	float invLen = 1.f / len;
	dir *= invLen;
	float tNear = 0.f, tFar = len;
#ifdef MATH_SIMD
	return IntersectLineAABB_SSE(lineSegment.a, dir, tNear, tFar);
#else
	return IntersectLineAABB_CPP(lineSegment.a, dir, tNear, tFar);
#endif
}
Exemple #11
0
/*!	\brief Returns whether this directory or any of its subdirectories
	at any level contain the entry referred to by the supplied path name.
	Only entries that match the node flavor specified by \a nodeFlags are
	considered.
	If the BDirectory is not properly initialized, the method returns \c false.
	A non-absolute path is considered relative to the current directory.

	\note R5's implementation always returns \c true given an absolute path or 
	an unitialized directory. This implementation is not compatible with that
	behavior. Instead it converts the path into a BEntry and passes it to the
	other version of Contains().

	\param path the entry's path name. May be relative to this directory or
		   absolute.
	\param nodeFlags Any of the following:
		   - \c B_FILE_NODE: The entry must be a file.
		   - \c B_DIRECTORY_NODE: The entry must be a directory.
		   - \c B_SYMLINK_NODE: The entry must be a symbolic link.
		   - \c B_ANY_NODE: The entry may be of any kind.
	\return
	- \c true, if the entry exists, its kind does match \nodeFlags and the
	  BDirectory is properly initialized and does contain the entry at any
	  level,
	- \c false, otherwise
*/
bool
BDirectory::Contains(const char *path, int32 nodeFlags) const
{
	// check initialization and parameters
	if (InitCheck() != B_OK)
		return false;
	if (!path)
		return true;	// mimic R5 behavior
	// turn the path into a BEntry and let the other version do the work
	BEntry entry;
	if (BPrivate::Storage::is_absolute_path(path))
		entry.SetTo(path);
	else
		entry.SetTo(this, path);
	return Contains(&entry, nodeFlags);
}
    /**
     * Method FilterMatches
     *
     * Checks if the filter matches the given hotkey
     *
     * @return true on match (or if filter is disabled)
     */
    bool FilterMatches( const EDA_HOTKEY& aHotkey ) const
    {
        if( !m_valid )
            return true;

        // Match in the (translated) filter string
        const auto normedInfo = wxGetTranslation( aHotkey.m_InfoMsg ).Upper();
        if( normedInfo.Contains( m_normalised_filter_str ) )
            return true;

        const wxString keyName = KeyNameFromKeyCode( aHotkey.m_KeyCode );
        if( keyName.Upper().Contains( m_normalised_filter_str ) )
            return true;

        return false;
    }
BOOL CPolygon::UnionPosition(SFloat3* psPosition)
{
	CArrayInt	cIndices;
	int			iInsertionIndex;
	int			i;
	int			iIndex;
	
	if (mbConvex)
	{
		if (On(psPosition))
		{
			if (!Contains(psPosition))
			{
				if (HasPositionPtr(psPosition))
				{
					return TRUE;
				}

				cIndices.Init(4);
				FindIndicesOfVisibleHalfSpaces(psPosition, &cIndices);
				if (cIndices.NumElements() == 0)
				{
					//Something went wrong.
					return FALSE;
				}

				iInsertionIndex = cIndices.GetValue(1);  //End index of the first visible line.

				for (i = 2; i < cIndices.NumElements(); i+= 2)
				{
					iIndex = cIndices.GetValue(i);
					mapsPositions.RemoveAt(iIndex);
					if (iIndex < iInsertionIndex)
					{
						iInsertionIndex--;
					}
				}

				mapsPositions.InsertAt(&psPosition, iInsertionIndex);
				cIndices.Kill();
			}
			return TRUE;
		}
		return FALSE;
	}
	return FALSE;
}
Exemple #14
0
vector<Node*>* Container::AdjacentRemainingNodes(Node* node)
{
	vector<Node*>* adjacentNodes = new vector<Node*>();
	for (unsigned int i = 0; i < edges.size(); ++i) {
		Edge* edge = edges.at(i);
		Node* adjacent = NULL;
		
		if (edge->node1 == node)
			adjacent = edge->node2;
		else if (edge->node2 == node)
			adjacent = edge->node1;
		
		if (adjacent && Contains(nodes, adjacent))
			adjacentNodes->push_back(adjacent);
	}
	return adjacentNodes;
}
Exemple #15
0
float3 Frustum::UniformRandomPointInside(LCG &rng) const
{
	if (type == OrthographicFrustum)
		return FastRandomPointInside(rng);
	else
	{
		OBB o = MinimalEnclosingOBB();
		for(int numTries = 0; numTries < 1000; ++numTries)
		{
			float3 pt = o.RandomPointInside(rng);
			if (Contains(pt))
				return pt;
		}
		LOGW("Rejection sampling failed in Frustum::UniformRandomPointInside! Producing a non-uniformly distributed point inside the frustum!");
		return FastRandomPointInside(rng);
	}
}
Exemple #16
0
//______________________________________________________________________________
void XCheck(const AliMpSlat& slat)
{
  // find out which pads are not found by iterator, as compared to HasPad method
  TList l1,l2;
  l1.SetOwner(kTRUE);
  l2.SetOwner(kTRUE);
  
  AliMpSlatSegmentation seg(&slat);
  
  for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
  {
    for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
    {
      AliMpPad pad = seg.PadByIndices(i,j,kFALSE);
      if ( pad.IsValid() )
      {
        l1.Add(new AliMpPad(pad));
      }
    }
  }
  
  AliMpVPadIterator* it = seg.CreateIterator();
  
  it->First();
    
  while ( !it->IsDone() )
  {
    l2.Add(new AliMpPad(it->CurrentItem()));
    it->Next();
  }

  TIter next(&l1);
  AliMpPad* pad;
  while ( ( pad = (AliMpPad*)next() ) )
  {
    if ( Contains(l2,*pad) != 1)
    {
      cout << "The following pad is not found by iterator : " << endl;
      pad->Print();
    }
  }
  
  CheckMultiple(l2,slat.GetName(),"iterator");

  CheckMultiple(l1,slat.GetName(),"padByIndices");
}
void LinkedList::Insert(string s)
{
	if (size == 0 && head == NULL)
	{
		head = new Node(s,NULL);
		size++;
	}
	else if (Contains(s) == false) // no duplicates allowed
	{
		Node* node;

		node = new Node(s,head);
		head = node;

		size++;
	}
	
}
	void MenuBehaviour::HandleMouseClick(sf::Event::MouseButtonEvent const& e)
	{
		for (auto item = m_menuItems.begin(); item != m_menuItems.end(); ++item)
		{
			auto bounds = item->GetGlobalBounds();
			auto text = item->GetString();
			if (bounds.Contains(static_cast<float>(e.X), static_cast<float>(e.Y)))
			{
				if (text == STR_GAME_START)
					m_game.ChangeState(GameState_InGame);
				else if(text == STR_HIGHSCORE)
					m_game.ChangeState(GameState_Highscore);
				else if(text == STR_QUIT)
					m_game.Quit();
				break;
			}
		}		
	}
Exemple #19
0
bool Team::Add(Slug* slug)
{

	ASSERT(slug);

	if (!Contains(slug))
	{

		// Add the slug to the team
		slugs.push_back(slug);

		return true;

	}

	return false;

}
Exemple #20
0
bool CmPart::AddBCForVertex(const unsigned int &vertexIndex, int &error)
{
  error = ERR_FACE_NOT_FOUND;
  m_verticesBCs.insert(vertexIndex);
  for (std::vector<CmFacep>::const_iterator it = m_faces.begin();it != m_faces.end(); it++)
  {
    if(Contains((*it)->VerticesNums(),vertexIndex))
    {
      m_bcs.insert((*it)->GetIndex());
      error = ERR_NO_ERROR;
    }
  }
  if(error == ERR_NO_ERROR)
  {
    return true;
  }
  return false;
}
Exemple #21
0
int mem_Write16(uint32_t addr, uint16_t w)
{
#ifdef MEM_TRACE
    fprintf(stderr, "w16 %08x <- w=%04x\n", addr, w & 0xffff);
#endif

    size_t i;
    for(i=0; i<num_mappings; i++) {
        if(Contains(&mappings[i], addr, 2)) {
            // Unaligned.
            if (addr & 1) {
                mappings[i].phys[addr - mappings[i].base] = (u8)w;
                mappings[i].phys[addr - mappings[i].base + 1] = (u8)(w >> 8);
            }
            else
                *(uint16_t*)(&mappings[i].phys[addr - mappings[i].base]) = w;
            return 0;
        }
Exemple #22
0
float3 Polyhedron::ClosestPoint(const float3 &point) const
{
	if (Contains(point))
		return point;
	float3 closestPoint = float3::nan;
	float closestDistance = FLT_MAX;
	for(int i = 0; i < NumFaces(); ++i)
	{
		float3 closestOnPoly = FacePolygon(i).ClosestPoint(point);
		float d = closestOnPoly.DistanceSq(point);
		if (d < closestDistance)
		{
			closestPoint = closestOnPoly;
			closestDistance = d;
		}
	}
	return closestPoint;
}
/**--------------------------------------------------------------------------<BR>
C2DPolyBase::Distance <BR>
\brief The distance from the edge.
<P>---------------------------------------------------------------------------*/
double C2DPolyBase::Distance(const C2DPoint& pt) const
{
	if (m_Lines.size() == 0)
		return 0;

	double dResult = m_Lines[0].Distance(pt);
	for (unsigned int i = 1; i < m_Lines.size(); i++)
	{
		double dDist = m_Lines[i].Distance(pt);
		if (dDist < dResult)
			dResult = dDist;
	}

	if (Contains(pt))
		return -dResult;
	else
		return dResult;
}
    void FontBufferCache::Add(const std::string &text, const Point3 &position, const GameColor &color, texture_font_t *font)
    {
        HashedString hash(text.c_str());
        vertex_buffer_t *buffer = 0;
        if(Contains(text)) {
            buffer = m_vertexBufferMap.find(hash.getHashValue())->second;
            vertex_buffer_clear(buffer);
        } else {
            buffer = vertex_buffer_new("vertex:3f,tex_coord:2f,color:4f");
            m_vertexBufferMap[hash.getHashValue()] = buffer;
        }

        F32 r = color.GetX(), g = color.GetY(), b = color.GetZ(), a = color.GetW();
        F32 x = 0.0f;

        U32 size = (U32)text.size();
        for(U32 i = 0; i < size; ++i) {
            texture_glyph_t *glyph = texture_font_get_glyph(font, text[i]);
            if(glyph != NULL) {
                I32 kerning = 0;
                if(i > 0) {
                    kerning = texture_glyph_get_kerning(glyph, text[i - 1]);
                }
                x += (float)kerning;

                F32 x0 = (F32)(position.GetX() + x + glyph->offset_x);
                F32 y0 = (F32)(position.GetY() + glyph->offset_y);
                F32 x1 = (F32)(x0 + glyph->width);
                F32 y1 = (F32)(y0 - glyph->height);
                F32 s0 = glyph->s0;
                F32 t0 = glyph->t0;
                F32 s1 = glyph->s1;
                F32 t1 = glyph->t1;
                GLuint indices[6] = {0, 1, 2, 0, 2, 3};
                vertex_t vertices[4] = { { x0, y0, 0.0f,  s0, t0,  r, g, b, a },
                    { x0, y1, 0.0f,  s0, t1,  r, g, b, a },
                    { x1, y1, 0.0f,  s1, t1,  r, g, b, a },
                    { x1, y0, 0.0f,  s1, t0,  r, g, b, a }
                };
                vertex_buffer_push_back(buffer, vertices, 4, indices, 6);
                x += glyph->advance_x;
            }
        }
    }
Exemple #25
0
bool AABB::Intersects(const LineSegment &lineSegment, float &dNear, float &dFar) const
{
	vec dir = lineSegment.b - lineSegment.a;
	float len = dir.Length();
	if (len <= 1e-4f) // Degenerate line segment? Fall back to point-in-AABB test.
	{
		dNear = 0.f;
		dFar = 1.f;
		return Contains(lineSegment.a);
	}
	float invLen = 1.f / len;
	dir *= invLen;
	dNear = 0.f;
	dFar = len;
	bool hit = IntersectLineAABB(lineSegment.a, dir, dNear, dFar);
	dNear *= invLen;
	dFar *= invLen;
	return hit;
}
// KS Mar 05 - The following removal functions are very inefficient and should
// be optimized to avoid the multiple memory moves.  Actually, the remove
// qualifiers should be added as a function and optimized that once.
void CIMInstanceRep::filter(
    Boolean includeQualifiers,
    Boolean includeClassOrigin,
    const CIMPropertyList& propertyList)
{
    // Filter any qualifiers from this instance.
    if (!includeQualifiers && _qualifiers.getCount() > 0)
    {
        while (_qualifiers.getCount())
        {
            _qualifiers.removeQualifier(0);
        }
    }

    // For each property, remove if not in propertylist
    for (Uint32 i = 0 ; i < _properties.size(); i++)
    {
        CIMConstProperty p = getProperty(i);
        CIMName name = p.getName();
        Array<CIMName> pl = propertyList.getPropertyNameArray();
        if (propertyList.isNull() || Contains(pl, name))
        {
            // test ClassOrigin and possibly remove
            if (!includeClassOrigin)
            {
                _properties[i].setClassOrigin(CIMName());
            }
            // remove qualifiers if required.
            if (!includeQualifiers && _properties[i].getQualifierCount() > 0)
            {
                while (_properties[i].getQualifierCount() > 0)
                {
                    _properties[i].removeQualifier(0);
                }
            }
        }
        else
        {
            _properties.remove(i--);
        }
    }
    return;
}
Exemple #27
0
Widget* FileListBox::ClickUp(const Point2i & mousePosition, uint button)
{
  if (!Contains(mousePosition))
    return NULL;

  ItemBox::ClickUp(mousePosition, button);

  const std::string *name = (std::string*)GetSelectedValue();
  if (name && DoesFolderExist(*name)) {
    Uint32 now = SDL_GetTicks();

    // Check we didn't click too fast
    if (now - last_time > 1000)
      PopulateFileList(name->c_str());
    return NULL;
  }

  return (name) ? this : NULL;
}
Exemple #28
0
bool wxRangeDouble::Combine( const wxRangeDouble &r, bool only_if_touching )
{
    if (only_if_touching)
    {
        if (Contains(r))
        {
            *this+=r;
            return true;
        }
    }
    else
    {
        bool added = false;
        if (r.m_min < m_min) { m_min = r.m_min; added = true; }
        if (r.m_max > m_max) { m_max = r.m_max; added = true; }
        return added;
    }
    return false;
}
    bool WaiterList::AddAndSuspendWaiter(DWORD_PTR waiter, uint32 timeout)
    {
#ifdef _WIN32
        Assert(m_waiters != nullptr);
        Assert(waiter != NULL);
        Assert(!Contains(waiter));

        AgentOfBuffer agent(waiter, CreateEvent(NULL, TRUE, FALSE, NULL));
        m_waiters->Add(agent);

        csForAccess.Leave();
        DWORD result = WaitForSingleObject(agent.event, timeout);
        csForAccess.Enter();
        return result == WAIT_OBJECT_0;
#else
        // TODO for xplat
        return false;
#endif
    }
Widget* LocalTeamsSelectionBox::ClickUp(const Point2i &mousePosition, uint button)
{
  if (!Contains(mousePosition))
    return NULL;

  if (local_teams_nb->ClickUp(mousePosition, button)) {
    SetNbTeams(local_teams_nb->GetValue());
  } else {
    Widget *w = (list_box) ? list_box->ClickUp(mousePosition, button)
                           : WidgetList::ClickUp(mousePosition, button);

    for (uint i=0; i<teams_selections.size() ; i++) {

      if (teams_selections[i]->Contains(mousePosition)) {
        Widget * at = teams_selections[i];
        Rectanglei r(at->GetPosition(), Point2i(38, 38));

        // Validate where the click really landed
        if (r.Contains(mousePosition)) {
          if (button == Mouse::BUTTON_LEFT() || button == SDL_BUTTON_WHEELDOWN) {
            NextTeam(i);
          } else if (button == Mouse::BUTTON_RIGHT() || button == SDL_BUTTON_WHEELUP) {
            PrevTeam(i);
          }
          return at;
        } else {
          Rectanglei r2(at->GetPositionX(), at->GetPositionY() + 39,
                        38, 30);
          if (r2.Contains(mousePosition)) {
            teams_selections[i]->SwitchPlayerType();
            return at;
          }
        }

        return w;
      }
    }

    return w;
  }

  return NULL;
}