Obscurity
2015-04-25 16:57:38
I came in need of a function that would return whether or not a point was between two points. This would be used to tell if, say, a fence existed between a player and a tree. So I originally wrote a function that would return true for the following - Z is between X and Y:

However, using this graphic provided by Ian, you can see that the function mentioned in the first paragraph would mark those trees as invalid.
So I decided to modify it and narrow the search area:

This gave me the need to write a function to tell if a point existed between an array of points. In this case, the 4 vertices of the rectangle you see above. So, tPoint.isInPoly():

However, using this graphic provided by Ian, you can see that the function mentioned in the first paragraph would mark those trees as invalid.
So I decided to modify it and narrow the search area:

This gave me the need to write a function to tell if a point existed between an array of points. In this case, the 4 vertices of the rectangle you see above. So, tPoint.isInPoly():
function tPoint.isInPoly(funcPoint:array of tPoint):boolean;
var
index,
indexMinus:int32=0;
begin
indexMinus:=high(funcPoint);
for index to high(funcPoint) do
begin
if ((funcPoint[index].y>self.y)<>(funcPoint[indexMinus].y>self.y)) and (self.x<(funcPoint[indexMinus].x-funcPoint[index].x)*(self.y-funcPoint[index].y)/(funcPoint[indexMinus].y-funcPoint[index].y)+funcPoint[index].x) then
result:=not result;
indexMinus:=index;
end;
end;