コード例 #1
0
/** Do line segments (x1, y1)--(x2, y2) and (x3, y3)--(x4, y4) intersect? */
bool DoLineSegmentsIntersect(int x1, int y1, int x2, int y2,
                             int x3, int y3, int x4, int y4) {
  char d1 = ComputeDirection(x3, y3, x4, y4, x1, y1);
  char d2 = ComputeDirection(x3, y3, x4, y4, x2, y2);
  char d3 = ComputeDirection(x1, y1, x2, y2, x3, y3);
  char d4 = ComputeDirection(x1, y1, x2, y2, x4, y4);
  return (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) &&
          ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0))) ||
         (d1 == 0 && IsOnSegment(x3, y3, x4, y4, x1, y1)) ||
         (d2 == 0 && IsOnSegment(x3, y3, x4, y4, x2, y2)) ||
         (d3 == 0 && IsOnSegment(x1, y1, x2, y2, x3, y3)) ||
         (d4 == 0 && IsOnSegment(x1, y1, x2, y2, x4, y4));
}
コード例 #2
0
ファイル: geometry.cpp プロジェクト: nslo/path-planning-2d
/** Do line segments (x1, y1)--(x2, y2) and (x3, y3)--(x4, y4) intersect? */
bool edge_edge_intersect(double x1, double y1, double x2, double y2,
        double x3, double y3, double x4, double y4)
{
    char d1 = ComputeDirection(x3, y3, x4, y4, x1, y1);
    char d2 = ComputeDirection(x3, y3, x4, y4, x2, y2);
    char d3 = ComputeDirection(x1, y1, x2, y2, x3, y3);
    char d4 = ComputeDirection(x1, y1, x2, y2, x4, y4);

    return (((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) &&
            ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0))) ||
        (d1 == 0 && IsOnSegment(x3, y3, x4, y4, x1, y1)) ||
        (d2 == 0 && IsOnSegment(x3, y3, x4, y4, x2, y2)) ||
        (d3 == 0 && IsOnSegment(x1, y1, x2, y2, x3, y3)) ||
        (d4 == 0 && IsOnSegment(x1, y1, x2, y2, x4, y4));
}
コード例 #3
0
ファイル: connectionselection.cpp プロジェクト: alex-games/a1
ConnectionSelection::ConnectionSelection(MapFrontend* mf, double mx, double my, int layer)
{
	m_admin = NULL;
	m_first = true;
	
	m_connectionDescriptor[0].room = NULL;
	m_connectionDescriptor[1].room = NULL;
 	
 	Coordinate c(GLtoMap(mx), GLtoMap(my), layer);
 	mf->lookingForRooms(this, c, c );
 	m_connectionDescriptor[0].direction = ComputeDirection(mx, my);
}
コード例 #4
0
ファイル: connectionselection.cpp プロジェクト: alex-games/a1
void ConnectionSelection::setSecond(MapFrontend* mf, double mx, double my, int layer)
{
	m_first = false;
 	Coordinate c(GLtoMap(mx), GLtoMap(my), layer);
 	if (m_connectionDescriptor[1].room != NULL)
  	{
  		if (m_connectionDescriptor[1].room != m_connectionDescriptor[0].room)
  			m_admin->releaseRoom(this, m_connectionDescriptor[1].room->getId());
		m_connectionDescriptor[1].room = NULL;
  	}
 	mf->lookingForRooms(this, c, c );
	m_connectionDescriptor[1].direction = ComputeDirection(mx, my);	
	//if (m_connectionDescriptor[1].direction == ED_UNKNOWN) m_connectionDescriptor[1].direction = ED_NONE;	
}
コード例 #5
0
ファイル: mfoutline.cpp プロジェクト: MaTriXy/tess-two
/**
 * This routine searches through the specified outline, computes
 * a slope for each vector in the outline, and marks each
 * vector as having one of the following directions:
 *   N, S, E, W, NE, NW, SE, SW
 * This information is then stored in the outline and the
 * outline is returned.
 * @param Outline   micro-feature outline to analyze
 * @param MinSlope  controls "snapping" of segments to horizontal
 * @param MaxSlope  controls "snapping" of segments to vertical
 * @return none
 * @note Exceptions: none
 * @note History: 7/21/89, DSJ, Created.
 */
void FindDirectionChanges(MFOUTLINE Outline,
                          FLOAT32 MinSlope,
                          FLOAT32 MaxSlope) {
  MFEDGEPT *Current;
  MFEDGEPT *Last;
  MFOUTLINE EdgePoint;

  if (DegenerateOutline (Outline))
    return;

  Last = PointAt (Outline);
  Outline = NextPointAfter (Outline);
  EdgePoint = Outline;
  do {
    Current = PointAt (EdgePoint);
    ComputeDirection(Last, Current, MinSlope, MaxSlope);

    Last = Current;
    EdgePoint = NextPointAfter (EdgePoint);
  }
  while (EdgePoint != Outline);

}                                /* FindDirectionChanges */