int FindIfInside(Point polygon[],int n,Point p){ Point extreme={inf,p.y}; int i=0; int next; int count=0; do{ next=(i+1)%n; if(FindIfIntersect(polygon[i],polygon[next],p,extreme )){ if(FindOrient(polygon[i],polygon[next],p)==0){ //printf("\nHere for i : %d next : %d",i,next); return IsOnLine(polygon[i],p,polygon[next]); } count++; } i=next; }while(i!=0); //printf("\nCount is : %d",count); return count&1; }
double Dist2(const Line2d & g, const Line2d & h ) { double dd = 0.0, d1,d2,d3,d4; Point2d cp = CrossPoint(g,h); if ( Parallel(g,h) || !IsOnLine(g,cp) || !IsOnLine(h,cp) ) { d1 = Dist2(g.P1(),h.P1()); d2 = Dist2(g.P1(),h.P2()); d3 = Dist2(g.P2(),h.P1()); d4 = Dist2(g.P2(),h.P2()); if (d1<d2) d2 = d1; if (d3<d4) d4 = d3; dd = ( d2 < d4 ) ? d2 : d4; } return dd; }
int FindIfIntersect(Point p1,Point q1,Point p2,Point q2){ int o1=FindOrient(p1,q1,p2); int o2=FindOrient(p1,q1,q2); int o3=FindOrient(p2,q2,p1); int o4=FindOrient(p2,q2,q1); if(o1!=o2 && o3!=o4){ return 1; } if(o1==0 && IsOnLine(p1,p2,q1)){ return 1; } if(o2==0 && IsOnLine(p1,q2,q1)){ return 1; } if(o3==0 && IsOnLine(p2,p1,q2)){ return 1; } if(o4==0 && IsOnLine(p2,q1,q2)){ return 1; } return 0; }
int Polygon2d :: IsOn (const Point2d & p) const { int i; for (i = 1; i <= points.Size(); i++) { const Point2d & p1 = points.Get(i); const Point2d & p2 = points.Get(i%points.Size()+1); if (IsOnLine (Line2d(p1, p2), p)) return 1; } return 0; /* CURSOR c; Point2d * p1, * p2; p2 = points[points.Last()]; for (c = points.First(); c != points.Head(); c++) { p1 = p2; p2 = points[c]; if (IsOnLine (Line2d(*p1, *p2), p)) return 1; } return 0; */ }
void ExportMixerPanel::OnMouseEvent(wxMouseEvent & event) { if( event.ButtonDown() ) { CaptureMouse(); bool reset = true; //check tracks for( int i = 0; i < mMixerSpec->GetNumTracks(); i++ ) if( mTrackRects[ i ].Inside( event.m_x, event.m_y ) ) { reset = false; if( mSelectedTrack == i ) mSelectedTrack = -1; else { mSelectedTrack = i; if( mSelectedChannel != -1 ) mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ] = !mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ]; } goto found; } //check channels for( int i = 0; i < mMixerSpec->GetNumChannels(); i++ ) if( mChannelRects[ i ].Inside( event.m_x, event.m_y ) ) { reset = false; if( mSelectedChannel == i ) mSelectedChannel = -1; else { mSelectedChannel = i; if( mSelectedTrack != -1 ) mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ] = !mMixerSpec->mMap[ mSelectedTrack ][ mSelectedChannel ]; } goto found; } //check links for( int i = 0; i < mMixerSpec->GetNumTracks(); i++ ) for( int j = 0; j < mMixerSpec->GetNumChannels(); j++ ) if( mMixerSpec->mMap[ i ][ j ] && IsOnLine( wxPoint( event.m_x, event.m_y ), wxPoint( mTrackRects[ i ].x + mBoxWidth, mTrackRects[ i ].y + mTrackHeight / 2 ), wxPoint( mChannelRects[ j ].x, mChannelRects[ j ].y + mChannelHeight / 2 ) ) ) mMixerSpec->mMap[ i ][ j ] = false; found: if( reset ) mSelectedTrack = mSelectedChannel = -1; Refresh( false ); } if( event.ButtonUp() ) { if( HasCapture() ) ReleaseMouse(); } }
int PTRIANGLE2D :: IsOn (const Point2d & p) const { return IsOnLine (Line2d (*p1, *p2), p) || IsOnLine (Line2d (*p1, *p3), p) || IsOnLine (Line2d (*p2, *p3), p); }
int TRIANGLE2D :: IsOn (const Point2d & p) const { return IsOnLine (Line2d (p1, p2), p) || IsOnLine (Line2d (p1, p3), p) || IsOnLine (Line2d (p2, p3), p); }