Recent

Author Topic: A slightly about crosscompiler issue  (Read 2587 times)

krolikbest

  • Full Member
  • ***
  • Posts: 246
A slightly about crosscompiler issue
« on: October 10, 2018, 02:29:04 pm »
Hello

doing on Windows some graphic task and having a need to find if mouse click is inside a polygon I use in Delphi !VCL! (not tested under Lazarus):
Code: Pascal  [Select][+][-]
  1. function PointInPolygon(Point: TPoint; const Polygon: array of TPoint): Boolean;
  2. var
  3.   rgn: HRGN;
  4. begin
  5.   rgn := CreatePolygonRgn(Polygon[0], Length(Polygon), WINDING);
  6.   Result := PtInRegion(rgn, Point.X, Point.Y);
  7.   DeleteObject(rgn);
  8. end;
  9.  
It is not my code but found on stackoverflow.com. The question is (especially in Delphi, but perhaps in Lazarus as well) what about different OS than Windows.  Should I find out some algorithm or maybe there already are some libraries that copes with such problems because it is not the only I expect to find.
I only mention that try to write simply prog in FireMonkey...

balazsszekely

  • Guest
Re: A slightly about crosscompiler issue
« Reply #1 on: October 10, 2018, 02:56:43 pm »
The following code is cross-platform with Lazarus:
Code: Pascal  [Select][+][-]
  1. uses LCLIntf, LCLType;
  2.  
  3. function PointInPolygon(Point: TPoint; const Polygon: array of TPoint): Boolean;
  4. var
  5.   rgn: HRGN;
  6. begin
  7.   rgn := CreatePolygonRgn(@Polygon[0], Length(Polygon), WINDING);
  8.   Result := PtInRegion(rgn, Point.X, Point.Y);
  9.   DeleteObject(rgn);
  10. end;

It should work with firemonkey too, if not switch to Lazarus.  :)


Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: A slightly about crosscompiler issue
« Reply #2 on: October 10, 2018, 02:59:24 pm »
This is an interesting topic I never explored. So I did some searching.

Searching the forum, I found this:
http://forum.lazarus.freepascal.org/index.php/topic,18655.msg105510.html#msg105510

Searching the Wikipedia, I found this:
https://en.wikipedia.org/wiki/Point_in_polygon

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: A slightly about crosscompiler issue
« Reply #3 on: October 10, 2018, 03:11:19 pm »
Should I find out some algorithm or maybe there already are some libraries that copes with such problems because it is not the only I expect to find.
The code above is compiled when
Code: Pascal  [Select][+][-]
  1. uses Types, LclType, LCLIntf;
No Windows unit, so it's cross-platform code. But of course it is necessary to check on the desired platforms.

 

TinyPortal © 2005-2018