Пример #1
0
void main()
{
	GraphLnk gl;
	InitGraph(&gl);
	InsertVertex(&gl,'A');
	InsertVertex(&gl,'B');
	InsertVertex(&gl,'C');
	InsertVertex(&gl,'D');
	InsertVertex(&gl,'E');

	InsertEdge(&gl,'A','B');
	InsertEdge(&gl,'A','D');
	InsertEdge(&gl,'B','C');
	InsertEdge(&gl,'B','E');
	InsertEdge(&gl,'C','D');
	InsertEdge(&gl,'C','E');
	ShowGraph(&gl);

	//RemoveEdge(&gl,'A','C');
	//RemoveVertex(&gl,'C');
	ShowGraph(&gl);

	//int v = GetFirstNeighbor(&gl,'A');
	int v = GetNextNeighbor(&gl,'B','A');

	DestroyGraph(&gl);
}
Пример #2
0
BOOL C4Shape::LineConnect(int32_t tx, int32_t ty, int32_t cvtx, int32_t ld,
                          int32_t oldx, int32_t oldy) {
#ifdef C4ENGINE

  if (VtxNum < 2) return FALSE;

  // No modification
  if ((VtxX[cvtx] == tx) && (VtxY[cvtx] == ty)) return TRUE;

  // Check new path
  int32_t ix, iy;
  if (PathFree(tx, ty, VtxX[cvtx + ld], VtxY[cvtx + ld], &ix, &iy)) {
    // Okay, set vertex
    VtxX[cvtx] = tx;
    VtxY[cvtx] = ty;
    return TRUE;
  } else {
    // Intersected, find bend vertex
    bool found = false;
    int32_t cix;
    int32_t ciy;
    for (int irange = 4; irange <= 12; irange += 4)
      for (cix = ix - irange / 2; cix <= ix + irange; cix += irange)
        for (ciy = iy - irange / 2; ciy <= iy + irange; ciy += irange) {
          if (PathFree(cix, ciy, tx, ty) &&
              PathFree(cix, ciy, VtxX[cvtx + ld], VtxY[cvtx + ld])) {
            found = true;
            goto out;
          }
        }
  out:
    if (!found) {
      // try bending directly at path the line took
      // allow going through vehicle in this case to allow lines through castles
      // and elevator shafts
      cix = oldx;
      ciy = oldy;
      if (!PathFreeIgnoreVehicle(cix, ciy, tx, ty) ||
          !PathFreeIgnoreVehicle(cix, ciy, VtxX[cvtx + ld], VtxY[cvtx + ld]))
        if (!PathFreeIgnoreVehicle(cix, ciy, tx, ty) ||
            !PathFreeIgnoreVehicle(cix, ciy, VtxX[cvtx + ld], VtxY[cvtx + ld]))
          return FALSE;  // Found no bend vertex
    }
    // Insert bend vertex
    if (ld > 0) {
      if (!InsertVertex(cvtx + 1, cix, ciy)) return FALSE;
    } else {
      if (!InsertVertex(cvtx, cix, ciy)) return FALSE;
      cvtx++;
    }
    // Okay, set vertex
    VtxX[cvtx] = tx;
    VtxY[cvtx] = ty;
    return TRUE;
  }
#endif

  return FALSE;
}
Пример #3
0
//----------------------------------------------------------------------------
bool MTMesh::Insert (int label0, int label1, int label2)
{
	// Insert the triangle.
	int t = InsertTriangle(label0, label1, label2);
	if (t == -1)
	{
		// The triangle already exists.
		return true;
	}

	// Insert the vertices of the triangle.
	int v0 = InsertVertex(label0);
	int v1 = InsertVertex(label1);
	int v2 = InsertVertex(label2);

	// Insert the edges of the triangle.
	int e0 = InsertEdge(label0, label1);
	int e1 = InsertEdge(label1, label2);
	int e2 = InsertEdge(label2, label0);

	// Set the connections among the components.
	MTTriangle& triangle = mTriangles[t];
	MTVertex& vertex0 = mVertices[v0];
	MTVertex& vertex1 = mVertices[v1];
	MTVertex& vertex2 = mVertices[v2];
	MTEdge& edge0 = mEdges[e0];
	MTEdge& edge1 = mEdges[e1];
	MTEdge& edge2 = mEdges[e2];

	// Attach edges to vertices.
	vertex0.InsertEdge(e2);
	vertex0.InsertEdge(e0);
	vertex1.InsertEdge(e0);
	vertex1.InsertEdge(e1);
	vertex2.InsertEdge(e1);
	vertex2.InsertEdge(e2);
	edge0.Vertex(0) = v0;
	edge0.Vertex(1) = v1;
	edge1.Vertex(0) = v1;
	edge1.Vertex(1) = v2;
	edge2.Vertex(0) = v2;
	edge2.Vertex(1) = v0;

	// Attach triangles to vertices.
	vertex0.InsertTriangle(t);
	vertex1.InsertTriangle(t);
	vertex2.InsertTriangle(t);
	triangle.Vertex(0) = v0;
	triangle.Vertex(1) = v1;
	triangle.Vertex(2) = v2;

	// Attach triangle to edges.
	AttachTriangleToEdge(t, triangle, 0, e0, edge0);
	AttachTriangleToEdge(t, triangle, 1, e1, edge1);
	AttachTriangleToEdge(t, triangle, 2, e2, edge2);

	return true;
}
void PhraseOrientation::InsertPhraseVertices(HSentenceVertices & topLeft,
                                             HSentenceVertices & topRight,
                                             HSentenceVertices & bottomLeft,
                                             HSentenceVertices & bottomRight,
                                             int startF, int startE, int endF, int endE)
{

  InsertVertex(topLeft, startF, startE);
  InsertVertex(topRight, endF, startE);
  InsertVertex(bottomLeft, startF, endE);
  InsertVertex(bottomRight, endF, endE);
}
Пример #5
0
void ClipEdge(float_point_type P1, float_point_type P2, win_edge_type edge, float_polygon_type &poly_out)
{
	float_point_type Pi;
	if (Visible(P1, edge)) // P is at the same side of window
		InsertVertex(poly_out, P1.x, P1.y);
	if (LineIntersectiom(P1, P2, edge))
	{
		Pi = Intersection(P1, P2, edge);
		InsertVertex(poly_out, Pi.x, Pi.y);
	}

}
void result_insert_arc(
		GRAPHIC_TYPE* graphic,
		VERTEX_TYPE* start_vertex,
		VERTEX_TYPE* end_vertex,
		int arc_weight) {
	VERTEX_TYPE* graphic_start_vertex = GetVertex(*graphic, start_vertex -> value);
	if (graphic_start_vertex == NULL) {
		InsertVertex(graphic, start_vertex -> value, &graphic_start_vertex);
	}
	VERTEX_TYPE* graphic_end_vertex = GetVertex(*graphic, end_vertex -> value);
	if (graphic_end_vertex == NULL) {
		InsertVertex(graphic, end_vertex -> value, &graphic_end_vertex);
	}
	InsertArc(graphic, graphic_start_vertex, graphic_end_vertex, arc_weight);
}
Пример #7
0
void MouseUpDraw() {
	if (shape == Line || shape == Poly) {
		DrawLineXor(p0_x, p0_y, p1_x, p1_y);
		DrawLine(p0_x, p0_y, p1_x, p1_y);
		p0_x = p1_x = mouse_x;
		p0_y = p1_y = mouse_y;
		if (shape == Poly) {
			if (polygon.n > 0 &&
				(polygon.vertex[polygon.n - 1].x != p0_x
				|| polygon.vertex[polygon.n - 1].y != p0_y))
				InsertVertex(polygon, p0_x, p0_y);
		}
		else if (shape == Line) {
			float xf1, yf1, xf2, yf2;
			GetWorldCoordinates(x_1, y_1, &xf1, &yf1);
			GetWorldCoordinates(x_2, y_2, &xf2, &yf2);
			entities.push_back(new LineEntity(xf1, yf1, xf2, yf2));
		}
	}
	if (shape == Circle) {
		DrawCircle(p0_x, p0_y, r);
		float x0, y0, rx, ry;
		GetWorldCoordinates(x_1, y_1, &x0, &y0);
		GetWorldCoordinates(x_1 + r, y_1 + r, &rx, &ry);
		rx = abs(rx - x0);
		ry = abs(ry - y0);
		entities.push_back(new EllipseEntity(x0, y0, rx, ry));
	}
	mouse_action = NO_ACTION;
}
Пример #8
0
void insertAllVert()
{
    int i;
    for(i=0; i<n; i++)
    {
        InsertVertex(i);
    }
}
void result_insert_arc(
		AdjacentMultipleListGraphic graphic,
		int start_vertex_index,
		int end_vertex_index,
		int weight,
		AdjacentMultipleListGraphic* result) {
	ElementType start_vertex_value = (graphic -> vertex_list + start_vertex_index) -> value;
	ElementType end_vertex_value = (graphic -> vertex_list + end_vertex_index) -> value;

	AdjacentMultipleListGraphicVertex* start_vertex = GetVertex(*result, start_vertex_value);
	AdjacentMultipleListGraphicVertex* end_vertex = GetVertex(*result, end_vertex_value);
	if (start_vertex == NULL)
		InsertVertex(result, start_vertex_value, &start_vertex);
	if (end_vertex == NULL)
		InsertVertex(result, end_vertex_value, &end_vertex);

	InsertArc(result, start_vertex, end_vertex, weight);
}
Пример #10
0
//----------------------------------------------------------------------------
void SegmentGraph::InsertEdge (const RPoint2& point0, const RPoint2& point1)
{
    // Insert vertices into the vertex set.  If the points already exist,
    // the function call is just a lookup; otherwise, new vertices are
    // allocated.
    Vertex* vertex0 = InsertVertex(point0);
    Vertex* vertex1 = InsertVertex(point1);

    Edge edge(vertex0, vertex1);
    std::set<Edge>::iterator iter = mEdgeSet.find(edge);
    if (iter == mEdgeSet.end())
    {
        // The edge does not exist, insert it into the set.
        mEdgeSet.insert(edge);

        // Update the vertex-adjacency information.
        vertex0->InsertAdjacent(vertex1);
        vertex1->InsertAdjacent(vertex0);
    }
}
Пример #11
0
void main()
{
	GraphMtx gm;
	InitGraph(&gm);
	InsertVertex(&gm,'A');
	InsertVertex(&gm,'B');
	InsertVertex(&gm,'C');
	InsertVertex(&gm,'D');
	InsertVertex(&gm,'E');
	InsertVertex(&gm,'F');

	InsertEdge(&gm,'A','B',6);
	InsertEdge(&gm,'A','C',1);
	InsertEdge(&gm,'A','D',5);
	InsertEdge(&gm,'B','C',5);
	InsertEdge(&gm,'B','E',3);
	InsertEdge(&gm,'C','D',5);
	InsertEdge(&gm,'C','E',6);
	InsertEdge(&gm,'C','F',4);
	InsertEdge(&gm,'D','F',2);
	InsertEdge(&gm,'E','F',6);
	ShowGraph(&gm);

	//MinSpanTree_Prim(&gm,'E');
	MinSpanTree_Kruskal(&gm);
}
Пример #12
0
/*************************************************************************
 *                                                                       *
 *  Check to see a polygon is selected or not.				 *
 *  There are two possiblities:                                          *
 *       1. Positioning a cursor at either vertex will RESIZE it. 	 *
 *       2. Positioning a cursor near a line segment will split segment. *
 *       3. Positioning a cursor inside a polygon will MOVE polygon.     *
 *                                                                       *
 *  If a polygon is selected, it will set the 'acttype' variable.        *
 *  Return TRUE or FALSE.                                                *
 *									*/
Flag
Polygon::is_selected(short x, short y)
{
#define Vertex_Check(a,b,p,q,v)  com_point_in_rect(a, b, p-v, q-v, p+v, q+v)
  int i, index;
  
  // ------ Check to RESIZE a polygon -----
  // Note that basex and basey are not used
  int dist= 0;
  int d, dx, dy;
  int isfound = FALSE;
  if (force_acttype != ROI_MOVE){
      for (i=0; i<npnts; i++){
	  if (Vertex_Check(x, y, pnt[i].x, pnt[i].y, aperture)){
	      dx = (x - pnt[i].x);
	      dy = (y - pnt[i].y);
	      d = dx * dx + dy * dy;
	      if (isfound == FALSE || d < dist){
		  isfound = TRUE;
		  dist = d;
		  vertex_selected = i;
	      }
	      acttype = ROI_RESIZE;
	  }
      }
  }
  if (isfound){
      return(TRUE);
  }
  
  // ---- Check polygon MOVE or vertex insertion -----
  index = LocateSegment(aperture/2, x, y);
  if ( index != -1) {
    // Then user wants to split this segment and insert and new vertex
    InsertVertex(index, x, y);
    acttype = ROI_RESIZE;
    vertex_selected = index+1;
    return(TRUE);
  } else if (com_point_in_rect(x, y, x_min, y_min, x_max, y_max) &&
	     point_inside_polygon(yedge[y-y_min], x))    {
    acttype = ROI_MOVE;
    return(TRUE);
  }
  
  return(FALSE);
}
Пример #13
0
void MouseDownDraw() {
	switch (shape) {
	case Line:
		p0_x = p1_x = mouse_x;
		p0_y = p1_y = mouse_y;
		break;
	case Poly:
		if (polygon.n == 0)
		{
			p0_x = p1_x = mouse_x;
			p0_y = p1_y = mouse_y;
			InsertVertex(polygon, p0_x, p0_y);
		}
		break;
	case Circle:
		p0_x = p1_x = mouse_x;
		p0_y = p1_y = mouse_y;
		r = 0;
		break;
	}
}