SRL Archive - OSR Help

Check if tile inside irregular area


Bixby Sayz

2011-08-03 21:28:25

Is there a (relatively) easy way to tell if a tile lies inside a really irregular shaped area?

NCDS

2011-08-03 21:50:34

If you know your exact location you could check between distances.

Bixby Sayz

2011-08-03 22:47:43

Google is your friend. Just don't ask me to explain it.

My head hurts now and I think I need to go lie down.

Edit: Faster more accurate version for those who might have a use for it.

{*******************************************************************************
function IsPointInPolygon(const Pt: TPoint; Polygon: TPointArray): boolean;
By: Lord Soth (DaniWeb Forums)
[url]http://www.daniweb.com/software-development/pascal-and-delphi/code/216805[/url]
Description: Returns true if point lies inside or on the border of polygon.
Modified By: Bixby Sayz
Note: Based on [url]http://paulbourke.net/geometry/insidepoly/[/url]
*******************************************************************************}
function IsPointInPolygon(const Pt: TPoint; Polygon: TPointArray): boolean;
var
I, J: integer;
begin
result := FALSE;

J := High(Polygon);
for I := Low(Polygon) to High(Polygon) do
begin
if (
(
((Polygon[I].Y <= Pt.Y) and (Pt.Y < Polygon[J].Y))
or
((Polygon[J].Y <= Pt.Y) and (Pt.Y < Polygon[I].Y))
)
and
(Pt.X < ((Polygon[J].X - Polygon[I].X) * (Pt.Y - Polygon[I].Y) / (Polygon[J].Y - Polygon[I].Y) + Polygon[I].X))
) then
result := not result;
J := I;
end;
end;

TomTuff

2011-08-03 22:48:33

PointInAbstractBox in Math.scar of SRL

E: InAbstractBox
function InAbstractBox(x1, y1, x2, y2, x3, y3, x4, y4: Integer; x, y: Integer):
Boolean;
var
U, D, R, L: Boolean;
UB, DB, LB, RB, UM, DM, LM, RM: Extended;
begin
UM := (-y1 - -y2) div (x1 - x2);
DM := (-y4 - -y3) div (x4 - x3);
if x1 - x4 <> 0 then
begin
LM := (-y1 - -y4) div (x1 - x4);
end else
begin
LM := Pi;
end;
if x2 - x3 <> 0 then
begin
RM := (-y2 - -y3) div (x2 - x3);
end else
begin
RM := Pi;
end;
UB := -(UM * x1) + -y1;
RB := -(RM * x2) + -y2;
DB := -(DM * x3) + -y3;
LB := -(LM * x4) + -y4;
if (UM * x + UB >= -y) then U := True;
if (DM * x + DB <= -y) then D := True;
if (RM <> Pi) and (RM >= 0) and (RM * x + RB <= -y) then R := True;
if (RM <> Pi) and (RM < 0) and (RM * x + RB >= -y) then R := True;
if (RM = Pi) and (x < x2) then R := True;
if (LM <> Pi) and (LM >= 0) and (LM * x + LB >= -y) then L := True;
if (LM <> Pi) and (LM < 0) and (LM * x + LB <= -y) then L := True;
if (LM = Pi) and (x > x1) then L := True;
if U and D and L and R then Result := True;
end;

Wanted

2011-08-03 22:54:36

If it's more irregular than something that can be defined as a polygon you could use something like InTPA, and if you're lazy you could always use a screen image and draw in exactly what you need with paint and write a script to export/debug the points into an array.

Bixby Sayz

2011-08-04 07:14:02

From: TomTuff
PointInAbstractBox in Math.scar of SRL

Had a look at that. Shape is more irregular than that. As always spent a couple hours pouring through the includes before asking.

From: IceFire908
If it's more irregular than something that can be defined as a polygon you could use something like InTPA, and if you're lazy you could always use a screen image and draw in exactly what you need with paint and write a script to export/debug the points into an array.


Thats what I thought of originally. But reading the description it shoulds like it only returns a match if the point is exactly contained in the TPA. I want to know if the point is inside the shape defined by the TPA.

Wasn't sure how to go about the export/load points and was sure I'd screw it up. The function above seems to work, so I'm going to write a test script and see if truly does want I want.

Wanted

2011-08-04 14:10:37

From: Bixby Sayz
Had a look at that. Shape is more irregular than that. As always spent a couple hours pouring through the includes before asking.



Thats what I thought of originally. But reading the description it shoulds like it only returns a match if the point is exactly contained in the TPA. I want to know if the point is inside the shape defined by the TPA.

Wasn't sure how to go about the export/load points and was sure I'd screw it up. The function above seems to work, so I'm going to write a test script and see if truly does want I want.


If it's not definable as a polygon, then you'll need every point inside the shape and use TPAInATPA. Use SaveScreenShot and open the image up in paint, shade in the map or whatever completely black, then make the shape you want white. Use FindColors with FilterPointsPie (with the radius/center of MM) to get a list of points that are in the unshaded region. It may be tricky getting the points to be same if they would if they were on the regular client, maybe add some preset offsets to the exported coordinates before they are debugged.