map utilities #282

Parent #72Owner #29Flags readSource hellcore/hellcore.db

Aliases: map utilities

10 verbs · 11 properties · 0 children

Verbs

VerbSpecFlagsDefinerLines
point_in_polythis none thisrxd#28229
distancethis none thisrxd#2824
distance_sqrthis none thisrxd#2824
distance_from_segment closest_point_on_segmentthis none thisrxd#28218
coords_to_latlongthis none thisrxd#28216
latlong_to_coordsthis none thisrxd#28214
dist_from_deg_oldthis none thisrxd#2829
midpointthis none thisrxd#2824
segments_intersectthis none thisrxd#28220
paththis none thisrxd#28226

Properties

PropertyDefinerFlagsOwnerValue
help_msg#72rc#29<clear>
aliases#1rc#29{"map utilities"}
description#1rc#29<clear>
object_size#1r#29{5900, 1298434625}
hidden_verbs#1rc#29<clear>
phelp_msg#1rc#29<clear>
weight#1rc#29<clear>
owner_verbs#1rc#29<clear>
plural_name#1rc#29<clear>
client_image#1rc#29<clear>
listening#1rc#29<clear>

Ancestry

Ancestors (nearest first): #72 Generic Utilities Package#1 root

Children: none

Call graph

calls n282_1 #282:distance n282_2 #282:distance_sqr n282_1->n282_2 n282_3 #282:distance_from_segment n282_3->n282_1 n282_6 #282:dist_from_deg_old n282_6->n282_1

Source

point_in_poly

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1"point_in_poly(point, poly)";
2"point is {x,y}";
3"poly is a list of points";
4"all coordinates are floats";
5"returns 1 if the point is inside the polygon";
6point = args[1];
7poly = args[2];
8x = point[1];
9y = point[2];
10i = 0;
11oddnodes = 0;
12for i in [1..length(poly)]
13j = i + 1;
14if (j > length(poly))
15j = 1;
16endif
17"player:tell(\"For y = \", y, \" and vertex1 at \", poly[i][2], \" and v2 at \", poly[j][2], \"...\");";
18if (((poly[i][2] < y) && (poly[j][2] >= y)) || ((poly[j][2] < y) && (poly[i][2] >= y)))
19"player:tell(\"yes\");";
20nodex = poly[i][1] + (((poly[j][1] - poly[i][1]) * (y - poly[i][2])) / (poly[j][2] - poly[i][2]));
21"nodex = poly[i][1] + (((y - poly[i][2]) / (poly[j][2] - poly[i][2])) * (poly[j][1] - poly[i][1]));";
22"player:tell(\"nodex = \", tostr(nodex));";
23if (nodex < x)
24"player:tell(\"found a node\");";
25oddnodes = (oddnodes + 1) % 2;
26endif
27endif
28endfor
29return oddnodes;

distance

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

Source

1"distance between two points";
2a = args[1];
3b = args[2];
4return sqrt(tofloat(this:distance_sqr(a, b)));

distance_sqr

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

Source

1"square of the distance between two points";
2a = args[1];
3b = args[2];
4return ((a[1] - b[1]) ^ 2) + ((a[2] - b[2]) ^ 2);

distance_from_segment closest_point_on_segment

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1"distance from a point to the closest point on a line segment";
2point = args[1];
3seg = args[2];
4xdelta = seg[2][1] - seg[1][1];
5ydelta = seg[2][2] - seg[1][2];
6u = (((point[1] - seg[1][1]) * xdelta) + ((point[2] - seg[1][2]) * ydelta)) / ((xdelta ^ 2.0) + (ydelta ^ 2.0));
7if (u < 0.0)
8cpoint = {seg[1][1], seg[1][2]};
9elseif (u > 1.0)
10cpoint = {seg[2][1], seg[2][2]};
11else
12cpoint = {seg[1][1] + (u * xdelta), seg[1][2] + (u * ydelta)};
13endif
14if (verb == "closest_point_on_segment")
15return cpoint;
16endif
17dist = this:distance(point, cpoint);
18return dist;

coords_to_latlong

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1"args: {INT x, INT y}, {INT lat-origin, INT long-origin}, INT meters-per-unit";
2x = args[1][1];
3y = args[1][2];
4longo = 121.5;
5lato = 38.0;
6mpu = 10;
7if (length(args) > 1)
8longo = args[2][1];
9lato = args[2][2];
10mpu = args[3];
11endif
12long = longo - (tofloat(x * mpu) / 87000.0);
13lat = lato - (tofloat(y * mpu) / 111000.0);
14long = tofloat(toint(long * 10000.0)) / 10000.0;
15lat = tofloat(toint(lat * 10000.0)) / 10000.0;
16return {long, lat};

latlong_to_coords

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1"args: {INT long, INT lat}, {INT long-origin, INT lat-origin}, INT meters-per-unit";
2long = args[1][1];
3lat = args[1][2];
4longo = 121.5;
5lato = 38.0;
6mpu = 10;
7if (length(args) > 1)
8longo = args[2][1];
9lato = args[2][2];
10mpu = args[3];
11endif
12x = toint((87000.0 * (longo - long)) / tofloat(mpu));
13y = toint((111000.0 * (lato - lat)) / tofloat(mpu));
14return {x, y};

dist_from_deg_old

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1"Copied from map utilities (#401881):distance_from_segment by Gilmore (#98) Sun Aug  9 21:25:27 2009 CDT";
2"distance from a point to the closest point on a line segment";
3point = args[1];
4seg = args[2];
5ab = {seg[2][1] - seg[1][1], seg[2][2] - seg[1][2]};
6length = this:distance(seg[1], seg[2]);
7cross = (ab[1] * (point[2] - seg[1][2])) - (ab[2] * (point[1] - seg[1][1]));
8dist = min(this:distance(seg[1], point), this:distance(seg[2], point), abs(cross / length));
9return dist;

midpoint

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1seg = args[1];
2x = tofloat(seg[1][1] + seg[2][1]) / 2.0;
3y = tofloat(seg[1][2] + seg[2][2]) / 2.0;
4return {toint(x), toint(y)};

segments_intersect

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1"Given two line segments, return whether they intersect.";
2segs = args;
3points = {segs[1][1], segs[1][2], segs[2][1], segs[2][2]};
4denom = tofloat(((points[4][2] - points[3][2]) * (points[2][1] - points[1][1])) - ((points[4][1] - points[3][1]) * (points[2][2] - points[1][2])));
5nume_a = tofloat(((points[4][1] - points[3][1]) * (points[4][2] - points[3][2])) - ((points[4][2] - points[3][2]) * (points[1][1] - points[3][1])));
6nume_b = tofloat(((points[2][1] - points[1][1]) * (points[1][2] - points[3][2])) - ((points[3][2] - points[1][2]) * (points[1][1] - points[3][1])));
7if (denom == 0.0)
8if ((nume_a == 0.0) && (nume_b == 0.0))
9return 1;
10endif
11return 0;
12endif
13ua = nume_a / denom;
14ub = nume_b / denom;
15if ((((ua >= 0.0) && (ua <= 1.0)) && (ub >= 0.0)) && (ub <= 1.0))
16intersection_x = toint(tofloat(points[1][1]) + (ua * tofloat(points[2][1] - points[1][1])));
17intersection_y = toint(tofloat(points[1][2]) + (ua * tofloat(points[2][2] - points[1][2])));
18return 1;
19endif
20return 0;

path

Spec this none thisFlags rxdOwner #361Definer #282

Referenced by

none

Source

1{source, where} = args;
2dl = {};
3searching = 1;
4found = 0;
5cursor = source;
6while (searching && (!found))
7hop = cursor:next_hop_to(where);
8if (!valid(hop))
9searching = 0;
10elseif (hop in dl)
11searching = 0;
12else
13dl = {@dl, hop};
14cursor = hop.otherside.location;
15if (length(dl) > 99)
16searching = 0;
17elseif (cursor == where)
18found = 1;
19endif
20endif
21endwhile
22if (found)
23return dl;
24else
25return E_NONE;
26endif