Find if a point is within a triangle: Difference between revisions
Find if a point is within a triangle (view source)
Revision as of 07:17, 31 August 2023
, 8 months ago→{{header|FutureBasic}}: Indent code
(→{{header|Evaldraw}}: fix bug where point in tri wouldnt work if point in negative quadrant) |
m (→{{header|FutureBasic}}: Indent code) |
||
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 )▼
WindowCenter(_window)
▲window _window, @"Find if a point is within a triangle", (0, 0, 340, 360 )
▲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▼
▲BezierPathRef path = fn BezierPathInit
BezierPathLineToPoint( path, fn CGPointMake(
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 )▼
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 )▼
case _viewDrawRect : fn DrawInView(tag)
▲select ( ev )
end select▼
▲end select
end fn
Line 1,479 ⟶ 1,475:
{{output}}
[[File:FB Find Point in a Triangle.png]]
=={{header|Go}}==
|