本文整理汇总了C++中SEG类的典型用法代码示例。如果您正苦于以下问题:C++ SEG类的具体用法?C++ SEG怎么用?C++ SEG使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SEG类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pushoutForce
static VECTOR2I pushoutForce( const SHAPE_CIRCLE& aA, const SEG& aB, int aClearance )
{
VECTOR2I f( 0, 0 );
const VECTOR2I c = aA.GetCenter();
const VECTOR2I nearest = aB.NearestPoint( c );
const int r = aA.GetRadius();
int dist = ( nearest - c ).EuclideanNorm();
int min_dist = aClearance + r;
if( dist < min_dist )
{
for( int corr = 0; corr < 5; corr++ )
{
f = ( aA.GetCenter() - nearest ).Resize( min_dist - dist + corr );
if( aB.Distance( c + f ) >= min_dist )
break;
}
}
return f;
}
示例2: solve
void solve()
{
int N, Q, cmd, p, q;
ll val;
scanf("%d %d",&N, &Q);
SEG st = SEG(N);
for(int i = 0; i < Q; i++)
{
scanf("%d",&cmd);
if(cmd == 0)
{
scanf("%d %d %lld",&p, &q, &val);
//cout << p << " " << q << val << endl;
st.update(p-1,q-1,val);
}
else
{
scanf("%d %d",&p, &q);
printf("%lld\n",st.query(p-1,q-1));
}
}
return;
}
示例3: Find
int SHAPE_LINE_CHAIN::Split( const VECTOR2I& aP )
{
int ii = -1;
int min_dist = 2;
ii = Find( aP );
if( ii >= 0 )
return ii;
for( int s = 0; s < SegmentCount(); s++ )
{
const SEG seg = CSegment( s );
int dist = seg.Distance( aP );
// make sure we are not producing a 'slightly concave' primitive. This might happen
// if aP lies very close to one of already existing points.
if( dist < min_dist && seg.A != aP && seg.B != aP )
{
min_dist = dist;
ii = s;
}
}
if( ii >= 0 )
{
m_points.insert( m_points.begin() + ii + 1, aP );
return ii + 1;
}
return -1;
}
示例4: gridOffset
VECTOR2I GRID_HELPER::AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg )
{
OPT_VECTOR2I pts[6];
const VECTOR2D gridOffset( GetOrigin() );
const VECTOR2D gridSize( GetGrid() );
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
pts[0] = aSeg.A;
pts[1] = aSeg.B;
pts[2] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 1, 0 ) ) );
pts[3] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 0, 1 ) ) );
int min_d = std::numeric_limits<int>::max();
for( int i = 0; i < 4; i++ )
{
if( pts[i] && aSeg.Contains( *pts[i] ) )
{
int d = (*pts[i] - aPoint).EuclideanNorm();
if( d < min_d )
{
min_d = d;
nearest = *pts[i];
}
}
}
return nearest;
}
示例5: SegDistanceCorrect
/**
* Predicate to check expected distance between two segments
* @param aSegA the first #SEG
* @param aSegB the second #SEG
* @param aExp expected distance
* @return does the distance calculated agree?
*/
bool SegDistanceCorrect( const SEG& aSegA, const SEG& aSegB, int aExp )
{
const int AtoB = aSegA.Distance( aSegB );
const int BtoA = aSegB.Distance( aSegA );
bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
if( AtoB != BtoA )
{
std::stringstream ss;
ss << "Segment distance is not the same in both directions: expected " << aExp << ", got "
<< AtoB << " & " << BtoA;
BOOST_TEST_INFO( ss.str() );
}
else if( !ok )
{
std::stringstream ss;
ss << "Distance incorrect: expected " << aExp << ", got " << AtoB;
BOOST_TEST_INFO( ss.str() );
}
// Sanity check: the collision should be consistent with the distance
ok = ok && SegCollideCorrect( aSegA, aSegB, 0, aExp == 0 );
return ok;
}
示例6: TestAreaIntersection
bool BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_test )
{
// see if areas are on same layer
if( area_ref->GetLayer() != area_to_test->GetLayer() )
return false;
SHAPE_POLY_SET* poly1 = area_ref->Outline();
SHAPE_POLY_SET* poly2 = area_to_test->Outline();
// test bounding rects
BOX2I b1 = poly1->BBox();
BOX2I b2 = poly2->BBox();
if( ! b1.Intersects( b2 ) )
return false;
// Now test for intersecting segments
for( auto segIterator1 = poly1->IterateSegmentsWithHoles(); segIterator1; segIterator1++ )
{
// Build segment
SEG firstSegment = *segIterator1;
for( auto segIterator2 = poly2->IterateSegmentsWithHoles(); segIterator2; segIterator2++ )
{
// Build second segment
SEG secondSegment = *segIterator2;
// Check whether the two segments built collide
if( firstSegment.Collide( secondSegment, 0 ) )
return true;
}
}
// If a contour is inside another contour, no segments intersects, but the zones
// can be combined if a corner is inside an outline (only one corner is enough)
for( auto iter = poly2->IterateWithHoles(); iter; iter++ )
{
if( poly1->Contains( *iter ) )
return true;
}
for( auto iter = poly1->IterateWithHoles(); iter; iter++ )
{
if( poly2->Contains( *iter ) )
return true;
}
return false;
}
示例7: Collide
bool SHAPE_ARC::Collide( const SEG& aSeg, int aClearance ) const
{
int minDist = aClearance + m_width / 2;
auto centerDist = aSeg.Distance( m_pc );
auto p1 = GetP1();
if( centerDist < minDist )
return true;
auto ab = (aSeg.B - aSeg.A );
auto ac = ( m_pc - aSeg.A );
auto lenAbSq = ab.SquaredEuclideanNorm();
auto lambda = (double) ac.Dot( ab ) / (double) lenAbSq;
if( lambda >= 0.0 && lambda <= 1.0 )
{
VECTOR2I p;
p.x = (double) aSeg.A.x * lambda + (double) aSeg.B.x * (1.0 - lambda);
p.y = (double) aSeg.A.y * lambda + (double) aSeg.B.y * (1.0 - lambda);
auto p0pdist = ( m_p0 - p ).EuclideanNorm();
if( p0pdist < minDist )
return true;
auto p1pdist = ( p1 - p ).EuclideanNorm();
if( p1pdist < minDist )
return true;
}
auto p0dist = aSeg.Distance( m_p0 );
if( p0dist > minDist )
return true;
auto p1dist = aSeg.Distance( p1 );
if( p1dist > minDist )
return false;
return true;
}
示例8: dragged
void EC_CONVERGING::Apply( EDIT_LINE& aHandle )
{
// The dragged segment endpoints
EDIT_POINT& origin = aHandle.GetOrigin();
EDIT_POINT& end = aHandle.GetEnd();
if( m_colinearConstraint )
{
m_colinearConstraint->Apply( origin );
m_colinearConstraint->Apply( end );
}
// The dragged segment
SEG dragged( origin.GetPosition(), origin.GetPosition() + m_draggedVector );
// Do not allow points on the adjacent segments move freely
m_originSideConstraint->Apply();
m_endSideConstraint->Apply();
EDIT_POINT& prevOrigin = *m_editPoints.Previous( origin, false );
EDIT_POINT& nextEnd = *m_editPoints.Next( end, false );
// Two segments adjacent to the dragged segment
SEG originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() );
SEG endSide = SEG( end.GetPosition(), nextEnd.GetPosition() );
// First intersection point (dragged segment against origin side)
if( OPT_VECTOR2I originIntersect = dragged.IntersectLines( originSide ) )
origin.SetPosition( *originIntersect );
// Second intersection point (dragged segment against end side)
if( OPT_VECTOR2I endIntersect = dragged.IntersectLines( endSide ) )
end.SetPosition( *endIntersect );
// Check if adjacent segments intersect (did we dragged the line to the point that it may
// create a selfintersecting polygon?)
originSide = SEG( origin.GetPosition(), prevOrigin.GetPosition() );
endSide = SEG( end.GetPosition(), nextEnd.GetPosition() );
if( OPT_VECTOR2I originEndIntersect = endSide.Intersect( originSide ) )
{
origin.SetPosition( *originEndIntersect );
end.SetPosition( *originEndIntersect );
}
}
示例9: CSegment
bool SHAPE_LINE_CHAIN::PointOnEdge( const VECTOR2I& aP ) const
{
if( SegmentCount() < 1 )
return m_points[0] == aP;
for( int i = 1; i < SegmentCount(); i++ )
{
const SEG s = CSegment( i );
if( s.A == aP || s.B == aP )
return true;
if( s.Distance( aP ) <= 1 )
return true;
}
return false;
}
示例10: dragDir
VECTOR2I PNS_LINE::snapToNeighbourSegments( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I &aP,
int aIndex, int aThreshold ) const
{
VECTOR2I snap_p[2];
DIRECTION_45 dragDir( aPath.CSegment( aIndex ) );
int snap_d[2] = { -1, -1 };
if( aThreshold == 0 )
return aP;
if( aIndex >= 2 )
{
SEG s = aPath.CSegment( aIndex - 2 );
if( DIRECTION_45( s ) == dragDir )
snap_d[0] = s.LineDistance( aP );
snap_p[0] = s.A;
}
if( aIndex < aPath.SegmentCount() - 2 )
{
SEG s = aPath.CSegment( aIndex + 2 );
if( DIRECTION_45( s ) == dragDir )
snap_d[1] = s.LineDistance(aP);
snap_p[1] = s.A;
}
VECTOR2I best = aP;
int minDist = INT_MAX;
for( int i = 0; i < 2; i++ )
{
if( snap_d[i] >= 0 && snap_d[i] < minDist && snap_d[i] <= aThreshold )
{
minDist = snap_d[i];
best = snap_p[i];
}
}
return best;
}
示例11: fresh
void fresh( SEG &T,SEG &L,SEG &R ) {
int i,j,x,y;
memset(T.V,0,sizeof T.V);
for(j=0;j<3;j++)
for(x=0;x<3;x++)if(g[j][x])
for(i=0;i<3;i++)
for(y=0;y<3;y++)
T.V[i][y]+=L.V[i][j]*R.V[x][y]%MOD;
T.fresh();
}
示例12: CSegment
int SHAPE_LINE_CHAIN::PathLength( const VECTOR2I& aP ) const
{
int sum = 0;
for( int i = 0; i < SegmentCount(); i++ )
{
const SEG seg = CSegment( i );
int d = seg.Distance( aP );
if( d <= 1 )
{
sum += ( aP - seg.A ).EuclideanNorm();
return sum;
}
else
sum += seg.Length();
}
return -1;
}
示例13: if
bool SHAPE_LINE_CHAIN::CheckClearance( const VECTOR2I& aP, const int aDist) const
{
if( !PointCount() )
return false;
else if( PointCount() == 1 )
return m_points[0] == aP;
for( int i = 0; i < SegmentCount(); i++ )
{
const SEG s = CSegment( i );
if( s.A == aP || s.B == aP )
return true;
if( s.Distance( aP ) <= aDist )
return true;
}
return false;
}
示例14: pushoutForce
static VECTOR2I pushoutForce( const SHAPE_CIRCLE& aA, const SEG& aB, int aClearance )
{
VECTOR2I nearest = aB.NearestPoint( aA.GetCenter() );
VECTOR2I f (0, 0);
int dist = ( nearest - aA.GetCenter() ).EuclideanNorm();
int min_dist = aClearance + aA.GetRadius();
if( dist < min_dist )
f = ( aA.GetCenter() - nearest ).Resize ( min_dist - dist + 10 );
return f;
}
示例15: SegCollideCorrect
/**
* Predicate to check expected collision between two segments
* @param aSegA the first #SEG
* @param aSegB the second #SEG
* @param aClearance the collision clearance
* @param aExp expected collision
* @return does the distance calculated agree?
*/
bool SegCollideCorrect( const SEG& aSegA, const SEG& aSegB, int aClearance, bool aExp )
{
const bool AtoB = aSegA.Collide( aSegB, aClearance );
const bool BtoA = aSegB.Collide( aSegA, aClearance );
const bool ok = ( AtoB == aExp ) && ( BtoA == aExp );
if( AtoB != BtoA )
{
std::stringstream ss;
ss << "Segment collision is not the same in both directions: expected " << aExp << ", got "
<< AtoB << " & " << BtoA;
BOOST_TEST_INFO( ss.str() );
}
else if( !ok )
{
std::stringstream ss;
ss << "Collision incorrect: expected " << aExp << ", got " << AtoB;
BOOST_TEST_INFO( ss.str() );
}
return ok;
}