Find if a point is within a triangle: Difference between revisions

m
(→‎{{header|Evaldraw}}: fix bug where point in tri wouldnt work if point in negative quadrant)
Line 1,427:
_window = 1
begin enum 1
_textLabel
end enum
 
void local fn BuildWindow
window _window, @"Find if a point is within a triangle", (0, 0, 340, 360 )
'~'1
WindowCenter(_window)
window _window, @"Find if a point is within a triangle", (0, 0, 340, 360 )
WindowCenter WindowSubclassContentView(_window)
ViewSetNeedsDisplay ViewSetFlipped( _windowContentViewTag, YES )
WindowSubclassContentView(_window)
ViewSetFlipped ViewSetNeedsDisplay( _windowContentViewTag, YES )
ViewSetNeedsDisplay( _windowContentViewTag )
subclass textLabel _textLabel, @"", ( 20, 320, 300, 20 ), _window
 
subclass textLabel _textLabel, @"", ( 20, 320, 300, 20 ), _window
end fn
 
void local fn DrawInView( tag as NSInteger )
BezierPathRef path = fn BezierPathInit
'~'1
BezierPathLineToPoint BezierPathMoveToPoint( path, fn CGPointMake( 150, 30, 300 ) )
BezierPathRef path = fn BezierPathInit
BezierPathMoveToPoint BezierPathLineToPoint( path, fn CGPointMake( 30300, 300 ) )
BezierPathLineToPoint( path, fn CGPointMake( 300150, 300 30 ) )
BezierPathClose( path )
BezierPathLineToPoint( path, fn CGPointMake( 150, 30 ) )
BezierPathStrokeFill( path, 3.0, fn ColorBlack, fn ColorGreen )
BezierPathClose( path )
AppSetProperty( @"path", path )
BezierPathStrokeFill( path, 3.0, fn ColorBlack, fn ColorGreen )
AppSetProperty( @"path", path )
end fn
 
void local fn DoMouse( tag as NSInteger )
CGPoint pt = fn EventLocationInView( tag )
'~'1
if ( fn BezierPathContainsPoint( fn AppProperty( @"path" ), pt ) )
CGPoint pt = fn EventLocationInView( tag )
ControlSetStringValue( _textLabel, fn StringWithFormat( @"Inside triangle: x = %.f y = %.f", pt.x, pt.y ) )
if ( fn BezierPathContainsPoint( fn AppProperty( @"path" ), pt ) )
else
ControlSetStringValue( _textLabel, fn StringWithFormat( @"Inside triangle: x = %.f y = %.f", pt.x, pt.y ) )
ControlSetStringValue( _textLabel, fn StringWithFormat( @"Outside triangle: x = %.f y = %.f", pt.x, pt.y ) )
else
end if
ControlSetStringValue( _textLabel, fn StringWithFormat( @"Outside triangle: x = %.f y = %.f", pt.x, pt.y ) )
end if
end fn
 
void local fn DoDialog( ev as long, tag as long )
select ( ev )
'~'1
case _viewDrawRect : fn DrawInView(tag)
select ( ev )
case _viewDrawRect case _viewMouseDown : fn DrawInViewDoMouse( tag )
case _viewMouseDown case _viewMouseMoved : fn DoMouse( tag )
end select
case _viewMouseMoved : fn DoMouse( tag )
end select
end fn
 
Line 1,479 ⟶ 1,475:
{{output}}
[[File:FB Find Point in a Triangle.png]]
 
 
 
=={{header|Go}}==
408

edits