示例#1
0
bool ON_Polyline::IsClosed( double tolerance ) const
{
    bool rc = false;
    const int count = m_count-1;
    int i;
    if ( count >= 3 )
    {
        if ( tolerance > 0.0 )
        {
            if ( m_a[0].DistanceTo(m_a[count]) <= tolerance ) {
                for ( i = 1; i < count; i++ ) {
                    if (   m_a[i].DistanceTo(m_a[0]) > tolerance
                            && m_a[i].DistanceTo(m_a[count]) > tolerance )
                    {
                        rc = true;
                        break;
                    }
                }
            }
        }
        else {
            if ( 0 == ON_ComparePoint(3,false,&m_a[0].x,&m_a[count].x) ) {
                for ( i = 1; i < count; i++ ) {
                    if (    ON_ComparePoint(3,false,&m_a[i].x,&m_a[0].x)
                            && ON_ComparePoint(3,false,&m_a[i].x,&m_a[count].x) )
                    {
                        rc = true;
                        break;
                    }
                }
            }
        }
    }
    return rc;
}
示例#2
0
RH_C_FUNCTION int ONC_ComparePoint(int dim, bool is_rat, ON_3DPOINT_STRUCT a, ON_3DPOINT_STRUCT b)
{
  const ON_3dPoint* _A = (const ON_3dPoint*)&a;
  const ON_3dPoint* _B = (const ON_3dPoint*)&b;
  int rat = is_rat?TRUE:FALSE;
  return ON_ComparePoint(dim, rat, &(_A->x), &(_B->x));
}
示例#3
0
ON_BOOL32 
ON_Surface::IsClosed(int dir) const
{
  ON_Interval d = Domain(dir);
  if ( d.IsIncreasing() && Dimension() <= 3 ) {
    const int span_count = SpanCount(dir?0:1);
    const int span_degree = Degree(dir?0:1);
    if ( span_count > 0 && span_degree > 0 ) {
      ON_SimpleArray<double> s(span_count+1);
      s.SetCount(span_count+1);
      int n = 2*span_degree+1;
      double delta = 1.0/n;
      ON_3dPoint P, Q;
      P.Zero();
      Q.Zero();
      int hintP[2] = {0,0};
      int hintQ[2] = {0,0};
      double *u0, *u1, *v0, *v1;
      double t;
      ON_Interval sp;
      if ( dir ) {
        v0 = &d.m_t[0];
        v1 = &d.m_t[1];
        u0 = &t;
        u1 = &t;
      }
      else {
        u0 = &d.m_t[0];
        u1 = &d.m_t[1];
        v0 = &t;
        v1 = &t;
      }
      if ( GetSpanVector( dir?0:1, s.Array() ) ) {
        int span_index, i;
        for ( span_index = 0; span_index < span_count; span_index++ ) {
          sp.Set(s[span_index],s[span_index+1]);
          for ( i = 0; i < n; i++ ) {
            t = sp.ParameterAt(i*delta);
            if ( !Evaluate( *u0, *v0, 1, 3, P, 0, hintP ) )
              return false;
            if ( !Evaluate( *u1, *v1, 2, 3, Q, 0, hintQ ) )
              return false;
            if ( ON_ComparePoint( 3, 0, &P.x, &Q.x ) )
              return false;
          }
        }
      }
    }
  }
  return false;
}
bool ON_Brep::IsValidForV2( const ON_BrepEdge& edge ) const
{
    int ei = edge.m_edge_index;
    if ( ei < 0 || ei >= m_E.Count() )
        return false;
    if ( &edge != &m_E[ei] )
        return false;
    if ( edge.ProxyCurveIsReversed() )
        return false;
    if ( edge.Domain() != edge.ProxyCurveDomain() )
        return false;
    const ON_Curve * curve = edge.EdgeCurveOf();
    if ( curve != edge.ProxyCurve() )
        return false;
    const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(curve);
    if ( 0 == nurbs_curve )
        return false;
    if ( !nurbs_curve->IsClamped(2) )
        return false;
    if ( nurbs_curve->m_dim != 3 )
        return false;
    if ( nurbs_curve->m_is_rat )
    {
        // 2 June 2003 Dale Lear - RR 8809 fix
        //    V2 likes end weights to be 1.0
        if ( nurbs_curve->m_cv[3] != 1.0 || nurbs_curve->CV(nurbs_curve->m_cv_count-1)[3] != 1.0 )
        {
            return false;
        }
    }

    if ( curve->Domain() != edge.Domain() )
        return false;

    // 14 April 2003 Dale Lear
    //     RR 8808 - V2 requires edges to be strictly closed/open
    if (    nurbs_curve->m_cv_count >= 4
            && 0 == ON_ComparePoint( nurbs_curve->m_dim, nurbs_curve->m_is_rat, nurbs_curve->m_cv, nurbs_curve->CV(nurbs_curve->m_cv_count-1) )
       )
    {
        if ( edge.m_vi[0] != edge.m_vi[1] )
            return false;
    }
    else if (edge.m_vi[0] == edge.m_vi[1] )
    {
        return false;
    }

    return true;
}
bool ON_Brep::IsValidForV2( const ON_BrepTrim& trim ) const
{
    int ti = trim.m_trim_index;
    if ( ti < 0 || ti >= m_T.Count() )
        return false;
    if ( &trim != &m_T[ti] )
        return false;
    if ( trim.ProxyCurveIsReversed() )
        return false;
    if ( trim.Domain() != trim.ProxyCurveDomain() )
        return false;
    const ON_Curve * curve = trim.TrimCurveOf();
    if ( curve != trim.ProxyCurve() )
        return false;
    const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(curve);
    if ( 0 == nurbs_curve )
        return false;
    if ( !nurbs_curve->IsClamped(2) )
        return false;
    if ( nurbs_curve->m_dim != 2 )
        return false;
    if ( nurbs_curve->m_is_rat )
    {
        // 2 June 2003 Dale Lear - RR 8809 fix
        //    V2 likes end weights to be 1.0
        if ( nurbs_curve->m_cv[2] != 1.0 || nurbs_curve->CV(nurbs_curve->m_cv_count-1)[2] != 1.0 )
        {
            return false;
        }
    }

    if (    nurbs_curve->m_cv_count >= 4
            && 0 == ON_ComparePoint( nurbs_curve->m_dim, nurbs_curve->m_is_rat, nurbs_curve->m_cv, nurbs_curve->CV(nurbs_curve->m_cv_count-1) )
       )
    {
        // 14 April 2003 Dale Lear
        //     RR 8843 - V2 wants ends of this trim farther apart
        if ( trim.m_vi[0] != trim.m_vi[1] )
        {
            const ON_BrepLoop* loop = Loop(trim.m_li);
            if ( 0 != loop && loop->m_ti.Count() > 1 )
                return false;
        }
    }

    if ( curve->Domain() != trim.Domain() )
        return false;

    return true;
}