tkadkghdlf commited on
Commit
caa2b1f
·
verified ·
1 Parent(s): 1c02843

Sync DemoService 66beeb6f15cf727373b911e9b3e9d2083b0874aa

Browse files
api/ai-service/tests/test_gpx_shape_templates.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The demo's GPX examples must remain usable without exposing their location."""
2
+ import json
3
+ import ast
4
+ import random
5
+ from pathlib import Path
6
+
7
+
8
+ ROOT = Path(__file__).resolve().parents[3]
9
+ TEMPLATES = ROOT / "router" / "ai" / "data" / "gpx_shape_templates.json"
10
+
11
+
12
+ def test_dog_and_star_gpx_examples_are_normalized_and_closed():
13
+ data = json.loads(TEMPLATES.read_text(encoding="utf-8"))
14
+ # Two of the 35 dog GPX files have identical geometry.
15
+ assert len(data["dog"]) == 33
16
+ assert len(data["symbol_star"]) == 14
17
+ for outlines in data.values():
18
+ assert len({tuple(map(tuple, outline)) for outline in outlines}) == len(outlines)
19
+ for outline in outlines:
20
+ assert 5 <= len(outline) <= 25
21
+ assert outline[0] == outline[-1]
22
+ assert all(-0.51 <= value <= 0.51 for point in outline for value in point)
23
+
24
+
25
+ def test_generator_selects_the_packaged_gpx_outlines():
26
+ script = ROOT / "router" / "ai" / "scripts" / "clip_osm_region_test.py"
27
+ tree = ast.parse(script.read_text(encoding="utf-8-sig"))
28
+ names = {"_load_gpx_shape_templates", "guided_waypoints_for_label"}
29
+ functions = ast.Module(
30
+ body=[node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name in names],
31
+ type_ignores=[],
32
+ )
33
+ scope = {"__file__": str(script), "Path": Path, "json": json, "random": random,
34
+ "LABEL_GUIDED_WAYPOINTS": {}}
35
+ exec(compile(functions, str(script), "exec"), scope)
36
+ scope["GPX_SHAPE_TEMPLATES"] = scope["_load_gpx_shape_templates"]()
37
+ for label in ("dog", "symbol_star"):
38
+ assert scope["guided_waypoints_for_label"](label) in scope["GPX_SHAPE_TEMPLATES"][label]
main/app/route-search/page.tsx CHANGED
@@ -387,6 +387,29 @@ const SHAPE_OPTIONS: ShapeOption[] = [
387
  [0.0034, 0],
388
  ],
389
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  ];
391
 
392
  const normalizeLocationText = (value: string): string =>
 
387
  [0.0034, 0],
388
  ],
389
  },
390
+ {
391
+ key: "dog",
392
+ label: "강아지",
393
+ // Preview silhouette adapted from the normalized dog GPX examples.
394
+ offsets: [
395
+ [-0.0027, -0.0012], [-0.0012, -0.0008], [-0.0012, 0.0007],
396
+ [-0.0016, 0.0011], [-0.0027, 0.0022], [-0.0025, 0.0030],
397
+ [-0.0013, 0.0022], [0.0011, 0.0022], [0.0014, -0.0008],
398
+ [0.0027, -0.0017], [0.0023, -0.0030], [0.0015, -0.0030],
399
+ [0.0015, -0.0016], [-0.0012, -0.0009], [-0.0027, -0.0012],
400
+ ],
401
+ },
402
+ {
403
+ key: "symbol_star",
404
+ label: "별",
405
+ // Preview silhouette adapted from the normalized five-point star GPX examples.
406
+ offsets: [
407
+ [-0.0028, -0.0018], [-0.0016, -0.0004], [-0.0025, 0.0014],
408
+ [-0.0016, 0.0014], [-0.0002, 0.0018], [0.0009, 0.0030],
409
+ [0.0010, 0.0009], [0.0028, 0.0002], [0.0008, -0.0008],
410
+ [0.0008, -0.0030], [-0.0005, -0.0014], [-0.0028, -0.0018],
411
+ ],
412
+ },
413
  ];
414
 
415
  const normalizeLocationText = (value: string): string =>
router/ai/data/gpx_shape_templates.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"dog":[[[-0.24778,0.48537],[-0.17076,0.45618],[-0.21878,0.40456],[-0.1411,0.35679],[-0.18711,0.29011],[-0.0969,0.30684],[-0.04852,0.28849],[-0.06404,0.23927],[0.06667,0.19407],[0.33816,0.213],[0.31896,0.08917],[0.06419,0.07436],[-0.01553,-0.19502],[0.20698,-0.33964],[0.14454,-0.41756],[0.11713,-0.35363],[-0.14395,-0.31498],[-0.168,-0.48557],[-0.21592,-0.5],[-0.1603,0.11345],[-0.22839,0.13606],[-0.2063,0.20514],[-0.34498,0.33028],[-0.26776,0.44416],[-0.24778,0.48537]],[[-0.18078,0.4521],[0.35077,0.35651],[0.1992,-0.5],[0.112,-0.35215],[0.22656,-0.34061],[-0.02389,-0.186],[-0.316,-0.17713],[-0.35658,-0.08823],[-0.28129,0.00044],[0.00848,-0.0782],[0.13194,0.13279],[0.02041,0.37699],[-0.14317,0.43805],[-0.18078,0.4521]],[[-0.2037,0.45506],[-0.08066,0.3022],[-0.13864,0.19854],[-0.03128,0.11468],[0.12212,0.19486],[0.16112,0.0136],[0.18989,0.27375],[0.20499,0.20513],[0.36038,0.33075],[0.36724,0.44133],[0.49948,0.42117],[0.36,0.22241],[0.35771,-0.18917],[0.05273,-0.12855],[-0.1395,-0.22726],[-0.27465,-0.45506],[-0.5,-0.37484],[-0.49745,-0.24494],[-0.26781,-0.24624],[-0.28892,0.00056],[-0.23261,-0.03492],[-0.14664,0.19856],[-0.25869,0.37458],[-0.20367,0.43351],[-0.2037,0.45506]],[[-0.18729,0.48027],[-0.05744,0.31894],[-0.11862,0.20954],[-0.00532,0.12104],[0.15657,0.20565],[0.19774,0.01435],[0.2281,0.28891],[0.24404,0.21649],[0.41061,0.44519],[0.5,0.44323],[0.49897,0.33082],[0.40764,0.23472],[0.40522,-0.19965],[0.08334,-0.13567],[-0.11954,-0.23984],[-0.26217,-0.48027],[-0.5,-0.3956],[-0.49731,-0.25851],[-0.25495,-0.25987],[-0.12707,0.20955],[-0.18726,0.45752],[-0.18729,0.48027]],[[-0.29435,0.10795],[-0.33875,-0.02585],[-0.18688,-0.49638],[0.04315,-0.05012],[0.23098,-0.27664],[0.34486,-0.27917],[0.11912,0.25543],[0.28609,0.33822],[0.27546,0.45632],[0.07869,0.5],[-0.07644,0.04971],[-0.29068,-0.01203],[-0.29431,0.08249],[-0.29435,0.10795]],[[-0.23895,0.42403],[-0.29076,0.35975],[-0.15012,0.2949],[-0.18336,-0.07145],[-0.41647,-0.17377],[-0.39872,-0.42191],[-0.24374,-0.5],[-0.14779,-0.3468],[-0.25264,-0.29487],[0.3786,-0.25388],[0.41721,-0.16087],[0.11152,-0.07125],[0.04679,0.08243],[0.33799,0.49777],[0.18493,0.5],[0.13858,0.37087],[-0.23651,0.42205],[-0.23895,0.42403]],[[-0.23895,0.42403],[-0.29076,0.35975],[-0.15013,0.2949],[-0.18336,-0.07145],[-0.41647,-0.17377],[-0.39872,-0.42191],[-0.24374,-0.5],[-0.14779,-0.3468],[-0.25264,-0.29487],[0.05883,-0.27389],[0.0498,-0.18248],[0.09911,-0.27206],[0.3786,-0.25388],[0.41721,-0.16087],[0.11152,-0.07125],[0.10123,0.16823],[0.0472,0.08428],[0.338,0.49777],[0.18493,0.5],[0.13858,0.37087],[-0.23651,0.42205],[-0.23895,0.42403]],[[-0.29075,0.4482],[0.46658,0.41641],[0.15898,0.21032],[0.17838,-0.03623],[0.09054,-0.05268],[0.40071,-0.05552],[0.47769,-0.202],[-0.24229,-0.25467],[-0.12485,-0.36034],[-0.19852,-0.49008],[-0.39816,-0.43658],[-0.47746,-0.22459],[-0.05971,0.21332],[-0.15926,0.4228],[-0.30417,0.44283],[-0.29075,0.4482]],[[-0.29075,0.4482],[0.35091,0.41174],[0.15945,0.19175],[0.21924,-0.05446],[0.40387,-0.05722],[0.47769,-0.202],[-0.24229,-0.25467],[-0.12485,-0.36034],[-0.19852,-0.49008],[-0.39816,-0.43658],[-0.47746,-0.22459],[-0.05971,0.21332],[-0.15926,0.4228],[-0.30417,0.44283],[-0.29075,0.4482]],[[-0.13309,0.47358],[-0.25164,0.49944],[-0.21904,0.34431],[-0.1228,0.44004],[0.08884,0.21331],[-0.01651,-0.02589],[-0.35301,-0.10611],[-0.28649,-0.19687],[0.01116,-0.15516],[0.23814,-0.5],[0.35301,-0.23894],[0.19764,-0.18658],[0.24513,0.31913],[-0.05998,0.4807],[-0.13309,0.47358]],[[0.03494,0.49996],[0.1353,0.14094],[-0.0705,-0.00705],[-0.36005,0.11687],[-0.09217,-0.23597],[-0.20994,-0.37543],[-0.16936,-0.46888],[0.02355,-0.5],[0.07095,-0.14154],[0.36005,0.18727],[0.04037,0.5],[0.03494,0.49996]],[[0.028,0.49672],[-0.05057,0.42439],[0.06968,0.38189],[0.00223,0.35957],[0.07276,0.06393],[-0.08217,0.02156],[-0.2325,0.14761],[-0.3319,0.07736],[0.04694,-0.22213],[-0.03157,-0.2576],[0.00624,-0.5],[0.18851,-0.40039],[0.10847,-0.18244],[0.23359,0.07663],[0.33118,0.09083],[0.028,0.49544],[0.028,0.49672]],[[-0.41051,0.44273],[-0.22464,0.5],[-0.11676,0.39354],[-0.19326,0.39272],[0.1073,0.38993],[0.14967,0.49058],[0.17186,-0.09353],[0.41069,-0.32825],[0.31441,-0.32702],[0.33023,-0.47843],[0.25157,-0.5],[0.16714,-0.26316],[-0.13885,-0.20196],[-0.06474,-0.15918],[-0.37161,-0.22685],[-0.3403,-0.12639],[-0.05876,-0.0864],[-0.03404,0.2408],[-0.19995,0.19168],[-0.19154,0.36596],[-0.41026,0.44077],[-0.41051,0.44273]],[[0.25095,0.43784],[0.41555,0.45374],[0.39901,0.34667],[0.49999,0.33825],[0.32888,0.21946],[0.23737,-0.33461],[0.15285,-0.35228],[0.16785,-0.18121],[-0.25332,-0.19786],[-0.49419,-0.44767],[-0.40573,-0.32014],[-0.45868,0.12884],[-0.36771,0.38586],[-0.36102,0.06501],[0.01962,0.06425],[0.25125,0.43521],[0.25095,0.43784]],[[0.1828,0.42683],[0.06847,0.2384],[-0.25953,0.2052],[-0.29578,0.10107],[-0.38712,0.23094],[-0.47743,0.20421],[-0.38618,0.16509],[-0.47438,-0.00634],[-0.10968,-0.01052],[0.11601,-0.24401],[-0.07084,-0.42057],[0.5,-0.17646],[0.16814,-0.03595],[0.06568,0.23436],[0.19693,0.42666],[0.1828,0.42683]],[[-0.41004,0.30492],[-0.227,0.22703],[-0.18693,0.04654],[-0.01514,0.03286],[0.01049,0.13176],[0.17695,0.13186],[0.22303,0.29648],[0.12926,0.41983],[0.21188,0.45867],[0.28764,-0.03118],[0.5,-0.08087],[0.26507,-0.08083],[0.16308,-0.20867],[-0.12668,-0.1933],[-0.20891,-0.37422],[-0.46162,-0.43124],[-0.5,-0.35867],[-0.36408,-0.32137],[-0.42857,-0.1584],[-0.26923,-0.01302],[-0.31016,0.18549],[-0.41206,0.22585],[-0.41004,0.30492]],[[-0.03913,0.5],[0.06156,0.49441],[0.13463,0.23665],[0.33361,0.05263],[0.28337,-0.0172],[0.2844,0.08424],[0.19034,0.07429],[0.06988,-0.07622],[0.12697,-0.36128],[-0.05939,-0.5],[-0.13926,-0.37086],[0.00273,-0.25806],[-0.33325,0.14077],[-0.11624,0.04674],[0.02549,0.09396],[-0.03903,0.49609],[-0.03913,0.5]],[[0.02113,0.47424],[-0.03818,0.47573],[0.0584,0.21887],[0.02487,0.07955],[-0.11342,0.03347],[-0.18994,0.05076],[-0.18871,0.1235],[-0.32517,0.12522],[0.00266,-0.26393],[-0.07062,-0.38568],[-0.13588,-0.374],[-0.05795,-0.5],[0.12389,-0.36464],[0.06819,-0.0865],[0.18572,0.06035],[0.2775,0.07006],[0.2765,-0.02892],[0.32551,0.03922],[0.28848,0.11713],[0.22675,0.1195],[0.20261,0.21881],[0.13136,0.21878],[0.10371,0.40181],[0.02369,0.4742],[0.02113,0.47424]],[[-0.27853,0.49414],[0.22491,0.32623],[0.08699,0.20019],[0.16994,0.18414],[0.16713,0.00465],[0.22382,0.04368],[0.19446,-0.11405],[0.36366,-0.21793],[0.24079,-0.5],[0.12475,-0.37979],[0.21359,-0.25627],[-0.36692,-0.14308],[-0.33594,-0.04699],[-0.09196,-0.05055],[0.00275,0.15094],[-0.24458,0.33394],[-0.14303,0.40172],[-0.28345,0.40211],[-0.27303,0.48052],[-0.27853,0.49414]],[[-0.27853,0.49414],[0.21523,0.30895],[0.08699,0.20019],[0.16994,0.18414],[0.16713,0.00465],[0.22382,0.04368],[0.19446,-0.11405],[0.36692,-0.24382],[0.24079,-0.5],[0.12475,-0.37979],[0.21359,-0.25627],[-0.36692,-0.14308],[-0.33594,-0.04699],[-0.09196,-0.05055],[0.00275,0.15094],[-0.24458,0.33394],[-0.14303,0.40172],[-0.28345,0.40211],[-0.27303,0.48052],[-0.27853,0.49414]],[[-0.32038,-0.14563],[-0.30037,-0.25653],[-0.16011,-0.15387],[0.06467,-0.22592],[0.03436,-0.34763],[0.29909,-0.49698],[0.34499,-0.31284],[0.21951,-0.18642],[0.28609,0.34921],[-0.22483,0.48406],[-0.26226,0.41728],[-0.06682,0.40381],[-0.03525,0.26833],[0.10249,0.22195],[0.02098,-0.07991],[-0.3076,-0.1023],[-0.32038,-0.14563]],[[-0.10408,0.35911],[-0.12805,0.15559],[0.16502,-0.00541],[0.5,0.19572],[0.19551,-0.18048],[0.16675,-0.35705],[0.10164,-0.35819],[0.1678,-0.2149],[-0.04151,-0.13883],[-0.5,-0.19891],[-0.10407,0.35592],[-0.10408,0.35911]],[[-0.00998,0.5],[-0.0156,0.25873],[-0.43122,0.15977],[-0.18039,0.11146],[-0.06649,-0.11866],[-0.07416,-0.22748],[-0.27605,-0.25431],[-0.34813,-0.41642],[0.01848,-0.31183],[0.38044,-0.49848],[0.43301,-0.28358],[0.12305,-0.13552],[0.12328,0.17674],[-0.00879,0.20311],[-0.01008,0.44412],[-0.00998,0.5]],[[-0.00998,0.5],[-0.0156,0.25873],[-0.43122,0.15977],[-0.18032,0.05888],[-0.05745,0.10828],[-0.0573,-0.00911],[-0.18047,-0.00879],[-0.08948,-0.0311],[-0.07416,-0.22748],[-0.27605,-0.25431],[-0.34813,-0.41642],[0.01848,-0.31183],[0.38044,-0.49848],[0.43301,-0.28358],[0.12305,-0.13552],[0.12328,0.17674],[-0.00879,0.20311],[-0.01008,0.44412],[-0.00998,0.5]],[[-0.02772,0.3321],[0.12662,0.5],[0.20404,0.43423],[0.14083,0.10674],[0.35162,-0.14176],[0.1347,-0.09544],[0.02921,-0.14227],[0.07738,-0.22992],[-0.0496,-0.14386],[-0.11071,-0.5],[-0.35187,0.14301],[-0.23096,-0.07656],[0.03051,0.15524],[-0.03045,0.32715],[-0.02772,0.3321]],[[-0.02772,0.3321],[0.12662,0.5],[0.20404,0.43423],[0.14083,0.10674],[0.35162,-0.14176],[0.11695,-0.03246],[-0.10032,-0.07644],[-0.17916,-0.18322],[-0.11071,-0.5],[-0.35187,0.14301],[-0.23096,-0.07656],[0.07786,0.2427],[-0.03045,0.32715],[-0.02772,0.3321]],[[-0.30239,0.24995],[-0.26567,-0.3155],[-0.38807,-0.43216],[-0.16636,-0.49999],[-0.08101,-0.20249],[0.0959,-0.05779],[0.29476,-0.03401],[0.3261,-0.19708],[0.38807,-0.16653],[0.24781,0.05575],[0.33607,0.21192],[0.26897,0.5],[0.27889,0.35551],[0.18125,0.35715],[0.11327,0.17397],[-0.11774,0.177],[-0.11717,0.06246],[-0.26262,0.24957],[-0.30239,0.24995]],[[-0.26944,0.15152],[-0.17645,0.30927],[-0.11593,0.30556],[-0.15989,0.22402],[0.11152,0.11706],[0.20922,0.12072],[0.40506,0.24336],[0.37581,0.1665],[0.5,0.04526],[0.39137,0.04375],[0.21717,-0.17288],[0.25579,-0.23273],[0.12142,-0.30993],[0.05843,-0.25215],[0.07829,-0.14628],[-0.18691,-0.01095],[-0.29744,-0.10533],[-0.42669,-0.12084],[-0.46928,-0.22503],[-0.46239,-0.08096],[-0.4187,-0.09603],[-0.40235,0.00373],[-0.31332,0.00513],[-0.28039,0.11955],[-0.26944,0.15152]],[[-0.26944,0.15152],[-0.17645,0.30927],[-0.11593,0.30556],[-0.15989,0.22402],[0.11152,0.11706],[0.20922,0.12072],[0.40506,0.24336],[0.37581,0.1665],[0.5,0.04526],[0.39137,0.04375],[0.21717,-0.17288],[0.25579,-0.23273],[0.12142,-0.30993],[0.05843,-0.25215],[0.07829,-0.14628],[-0.18691,-0.01095],[-0.29744,-0.10533],[-0.42669,-0.12084],[-0.46928,-0.22503],[-0.45517,-0.05847],[-0.40235,0.00373],[-0.31332,0.00513],[-0.28039,0.11955],[-0.26944,0.15152]],[[0.13473,0.35495],[-0.49985,0.24055],[-0.26282,0.23916],[-0.11457,0.0471],[-0.06755,-0.23361],[-0.28926,-0.27252],[-0.26004,-0.36974],[0.23067,-0.22231],[0.42315,-0.3425],[0.5,-0.16024],[0.23104,-0.09792],[0.05979,0.08322],[-0.01731,0.27257],[0.11843,0.35115],[0.13473,0.35495]],[[0.13473,0.35495],[-0.49985,0.24055],[-0.26282,0.23916],[-0.37166,0.22337],[-0.11457,0.0471],[-0.06755,-0.23361],[-0.28926,-0.27252],[-0.26004,-0.36974],[0.23067,-0.22231],[0.42315,-0.3425],[0.5,-0.16024],[0.23104,-0.09792],[0.05979,0.08322],[-0.01731,0.27257],[0.11843,0.35115],[0.13473,0.35495]],[[-0.40831,0.24853],[0.10147,0.39627],[-0.02476,0.29966],[0.0005,0.13769],[0.08918,0.14954],[0.20771,-0.05405],[0.49474,-0.12472],[0.45087,-0.33056],[0.28789,-0.17589],[0.32196,-0.25556],[0.0173,-0.24593],[-0.21479,-0.39627],[-0.07001,-0.22441],[-0.1045,-0.04026],[-0.34113,0.22467],[-0.49661,0.17232],[-0.4479,0.24623],[-0.40831,0.24853]],[[-0.40831,0.24853],[0.13223,0.38822],[-0.02476,0.29966],[0.0005,0.13769],[0.08918,0.14954],[0.20771,-0.05405],[0.41367,-0.12158],[0.43128,-0.04805],[0.45087,-0.33056],[0.28789,-0.17589],[0.32196,-0.25556],[0.0173,-0.24593],[-0.21479,-0.39627],[-0.02984,-0.2028],[-0.1992,0.13239],[-0.33186,0.12586],[-0.34113,0.22467],[-0.49661,0.17232],[-0.4479,0.24623],[-0.40831,0.24853]]],"symbol_star":[[[0.34832,0.30805],[0.42029,0.30471],[0.43991,0.22853],[0.27193,0.00669],[0.38263,-0.09003],[0.40583,-0.22769],[0.47151,-0.24197],[0.43634,-0.31364],[0.17498,-0.23487],[0.03529,-0.25558],[0.02336,-0.40296],[-0.11159,-0.5],[-0.14041,-0.17607],[-0.46451,0.0076],[-0.19789,0.12318],[-0.15447,0.5],[-0.03217,0.42553],[0.03869,0.26278],[0.27238,0.28221],[0.29512,0.32953],[0.34832,0.30805]],[[-0.30561,0.46279],[-0.05947,0.32229],[-0.05995,0.26906],[0.03382,0.26749],[0.03658,0.31493],[0.2323,0.42115],[0.32103,0.41734],[0.23395,0.26586],[0.27528,0.26265],[0.251,0.164],[0.32288,0.09364],[0.30422,0.0248],[0.5,-0.14383],[0.15713,-0.16174],[0.03457,-0.46278],[-0.06119,-0.41902],[-0.13092,-0.14321],[-0.49989,-0.13528],[-0.22582,0.08658],[-0.22068,0.18714],[-0.31531,0.26412],[-0.31412,0.4629],[-0.30561,0.46279]],[[0.43645,0.13586],[0.34293,0.10152],[0.1525,0.13917],[0.0382,0.5],[-0.13935,0.16256],[-0.46423,0.17634],[-0.48563,0.12017],[-0.26332,-0.09318],[-0.40402,-0.41907],[-0.29153,-0.42769],[-0.27417,-0.36931],[-0.08186,-0.29736],[0.12753,-0.39399],[0.20527,-0.5],[0.25554,-0.48395],[0.21096,-0.10848],[0.29831,-0.10629],[0.31502,-0.03528],[0.47377,0.05302],[0.44665,0.12739],[0.43645,0.13586]],[[0.28334,0.07459],[0.20162,0.10512],[0.22536,0.2672],[0.17479,0.29339],[0.2588,0.48245],[0.18379,0.48023],[-0.02244,0.27981],[-0.34864,0.4245],[-0.26288,0.0665],[-0.4971,-0.19638],[-0.11868,-0.21715],[0.02956,-0.49493],[0.09095,-0.22572],[0.18517,-0.24048],[0.11176,-0.16428],[0.4971,-0.09129],[0.2946,0.07042],[0.28334,0.07459]],[[-0.11056,0.5],[0.13007,0.24167],[0.45625,0.3233],[0.30681,0.04831],[0.25742,0.06689],[0.24137,0.02256],[0.24942,-0.04058],[0.36094,-0.08261],[0.35164,-0.22208],[0.4325,-0.25338],[0.40691,-0.3219],[0.05242,-0.21705],[-0.06413,-0.36203],[-0.05605,-0.42326],[-0.17492,-0.5],[-0.21615,-0.12175],[-0.27762,-0.12976],[-0.43624,0.01213],[-0.45625,-0.06224],[-0.42027,0.07058],[-0.32552,0.06872],[-0.26755,0.14613],[-0.21818,0.11779],[-0.11801,0.48082],[-0.11056,0.5]],[[0.22597,0.47113],[0.27236,0.45144],[0.28509,0.32918],[0.20833,0.12436],[0.48877,-0.01857],[0.48352,-0.08946],[0.41214,-0.06185],[0.23483,-0.17172],[0.16996,-0.14745],[0.06708,-0.47113],[-0.01781,-0.4177],[-0.00141,-0.35961],[-0.11743,-0.18934],[-0.5,-0.21213],[-0.34042,-0.08067],[-0.24463,0.08442],[-0.35032,0.38723],[-0.07716,0.25703],[0.04229,0.29718],[0.08948,0.40854],[0.18454,0.37037],[0.21893,0.45416],[0.22597,0.47113]],[[-0.41629,0.11418],[-0.45876,0.09586],[-0.42525,0.0174],[-0.20636,-0.15688],[-0.2696,-0.25773],[-0.22379,-0.34237],[-0.32467,-0.44574],[-0.29294,-0.5],[1e-05,-0.30572],[0.29723,-0.46161],[0.31589,-0.26011],[0.23316,-0.21444],[0.25668,-0.14823],[0.21132,-0.12182],[0.35125,0.02624],[0.39573,0.00657],[0.45876,0.12565],[0.11391,0.16835],[0.02431,0.48818],[-0.13197,0.18207],[-0.41425,0.1127],[-0.41629,0.11418]],[[0.44306,0.36928],[0.45541,0.28254],[0.27532,-0.0362],[0.49367,-0.39263],[0.42089,-0.26077],[0.43428,-0.3469],[0.19321,-0.22098],[0.09811,-0.23921],[-0.13811,-0.49917],[-0.14561,-0.15369],[-0.46978,-0.02416],[-0.47847,0.02409],[-0.32345,0.11618],[-0.21038,0.11323],[-0.1374,0.5],[0.03653,0.36139],[0.01998,0.30105],[0.21514,0.23228],[0.23524,0.28716],[0.42196,0.31946],[0.44306,0.36928]],[[0.44707,-0.02264],[0.4917,-0.04849],[0.42323,-0.11145],[0.17885,-0.13062],[0.04842,-0.5],[-0.12991,-0.17032],[-0.20221,-0.21367],[-0.4917,-0.17243],[-0.35134,-0.04291],[-0.38326,0.04989],[-0.33683,0.0255],[-0.23853,0.10372],[-0.3626,0.2916],[-0.33932,0.4223],[-0.06044,0.26257],[0.25625,0.5],[0.21607,0.13067],[0.41243,-0.01493],[0.44707,-0.02264]],[[0.27944,0.12962],[0.29776,0.17128],[0.5,0.15208],[0.31856,-0.06998],[0.24023,-0.07195],[0.34939,-0.46565],[-0.08073,-0.27419],[-0.0906,-0.3833],[-0.2435,-0.48351],[-0.31157,-0.46973],[-0.25351,-0.39463],[-0.23641,-0.1159],[-0.5,0.08249],[-0.39168,0.13217],[-0.21863,0.10987],[-0.11697,0.19332],[-0.03268,0.49357],[0.01847,0.34589],[0.14271,0.22661],[0.12495,0.17314],[0.27362,0.11872],[0.27944,0.12962]],[[0.2003,0.47971],[0.10466,0.37539],[0.02464,0.37085],[-0.00098,0.2935],[-0.06943,0.30607],[-0.03902,0.3441],[-0.09089,0.28877],[-0.16923,0.30728],[-0.34638,0.41421],[-0.34061,0.19826],[-0.23364,0.13593],[-0.5,-0.20693],[-0.14858,-0.20911],[0.01912,-0.49962],[0.17655,-0.08916],[0.40791,-0.12443],[0.5,-0.06347],[0.2025,0.14449],[0.26218,0.20866],[0.21473,0.22048],[0.25903,0.49714],[0.20988,0.47336],[0.2003,0.47971]],[[0.48001,-0.02591],[0.24566,0.1327],[0.26533,0.46709],[0.14608,0.49504],[-0.00285,0.29774],[-0.3471,0.44056],[-0.40916,0.38469],[-0.32851,0.30042],[-0.35919,0.23512],[-0.29448,0.18658],[-0.31363,0.13432],[-0.2612,0.11473],[-0.48001,-0.18477],[-0.39369,-0.24007],[-0.29451,-0.1893],[-0.09334,-0.22429],[0.03346,-0.5],[0.1143,-0.47656],[0.16482,-0.14427],[0.42241,-0.13581],[0.47951,-0.02898],[0.48001,-0.02591]],[[0.46435,-0.08016],[0.49105,-0.14626],[0.16248,-0.15169],[0.17616,-0.23052],[0.11424,-0.20635],[0.0578,-0.48398],[-0.00752,-0.49438],[-0.12945,-0.17812],[-0.42888,-0.12842],[-0.48203,-0.16349],[-0.5,-0.1181],[-0.23613,0.13382],[-0.34526,0.48122],[0.03381,0.29816],[0.27289,0.49438],[0.31493,0.44265],[0.23112,0.1105],[0.44276,-0.07505],[0.46435,-0.08016]],[[0.46435,-0.08016],[0.49105,-0.14626],[0.16248,-0.15169],[0.17616,-0.23052],[0.11424,-0.20635],[0.0578,-0.48398],[-0.00752,-0.49438],[-0.12945,-0.17812],[-0.42888,-0.12842],[-0.48203,-0.16349],[-0.5,-0.1181],[-0.23613,0.13382],[-0.34526,0.48122],[-0.00756,0.30264],[0.27289,0.49438],[0.31493,0.44265],[0.23112,0.1105],[0.44276,-0.07505],[0.46435,-0.08016]]]}
router/ai/scripts/build_gpx_shape_templates.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Convert reviewed GPX runs into location-free outlines for road routing.
2
+
3
+ Usage: python build_gpx_shape_templates.py GPX_DIRECTORY OUTPUT_JSON
4
+ The source GPX files stay on the developer's machine; only normalized outlines
5
+ are shipped to the demo service.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import math
12
+ import sys
13
+ import xml.etree.ElementTree as ET
14
+ from pathlib import Path
15
+
16
+
17
+ LABELS = {"dog_standing": "dog", "star_five": "symbol_star"}
18
+
19
+
20
+ def point_segment_distance(point, start, end):
21
+ dx, dy = end[0] - start[0], end[1] - start[1]
22
+ length_squared = dx * dx + dy * dy
23
+ if length_squared == 0:
24
+ return math.dist(point, start)
25
+ amount = max(0.0, min(1.0, ((point[0] - start[0]) * dx + (point[1] - start[1]) * dy) / length_squared))
26
+ return math.dist(point, (start[0] + amount * dx, start[1] + amount * dy))
27
+
28
+
29
+ def simplify(points, tolerance):
30
+ if len(points) < 3:
31
+ return points
32
+ furthest = max(range(1, len(points) - 1), key=lambda i: point_segment_distance(points[i], points[0], points[-1]))
33
+ if point_segment_distance(points[furthest], points[0], points[-1]) <= tolerance:
34
+ return [points[0], points[-1]]
35
+ return simplify(points[:furthest + 1], tolerance)[:-1] + simplify(points[furthest:], tolerance)
36
+
37
+
38
+ def normalized_outline(path: Path):
39
+ track = [
40
+ (float(node.attrib["lat"]), float(node.attrib["lon"]))
41
+ for node in ET.parse(path).iter()
42
+ if node.tag.rsplit("}", 1)[-1] == "trkpt"
43
+ ]
44
+ if len(track) < 12 or any(not all(math.isfinite(value) for value in point) for point in track):
45
+ raise ValueError(f"Invalid GPX track: {path.name}")
46
+ latitude = sum(point[0] for point in track) / len(track)
47
+ longitude = sum(point[1] for point in track) / len(track)
48
+ east_m = 111_320 * math.cos(math.radians(latitude))
49
+ xy = [((lon - longitude) * east_m, (latitude - lat) * 111_320) for lat, lon in track]
50
+ width = max(x for x, _ in xy) - min(x for x, _ in xy)
51
+ height = max(y for _, y in xy) - min(y for _, y in xy)
52
+ extent = max(width, height)
53
+ if extent < 100:
54
+ raise ValueError(f"GPX outline is too small: {path.name}")
55
+ middle_x = (max(x for x, _ in xy) + min(x for x, _ in xy)) / 2
56
+ middle_y = (max(y for _, y in xy) + min(y for _, y in xy)) / 2
57
+ points = [((x - middle_x) / extent, (y - middle_y) / extent) for x, y in xy]
58
+ # The first and last GPX points coincide. Simplify the open stroke first,
59
+ # then close it, so a repeated endpoint cannot erase the full outline.
60
+ points = simplify(points[:-1], 0.035)
61
+ if len(points) > 24:
62
+ points = simplify(points, 0.065)
63
+ if len(points) > 24:
64
+ points = [points[round(index * (len(points) - 1) / 23)] for index in range(24)]
65
+ if len(points) < 5:
66
+ raise ValueError(f"GPX outline lost its shape: {path.name}")
67
+ points.append(points[0])
68
+ return [[round(x, 5), round(y, 5)] for x, y in points]
69
+
70
+
71
+ def build(source: Path):
72
+ outlines = {label: [] for label in LABELS.values()}
73
+ seen = {label: set() for label in LABELS.values()}
74
+ for path in sorted(source.glob("*.gpx")):
75
+ for fragment, label in LABELS.items():
76
+ if fragment in path.name:
77
+ outline = normalized_outline(path)
78
+ signature = tuple(map(tuple, outline))
79
+ if signature not in seen[label]:
80
+ seen[label].add(signature)
81
+ outlines[label].append(outline)
82
+ break
83
+ if any(not items for items in outlines.values()):
84
+ raise ValueError("Expected both dog_standing and star_five GPX files")
85
+ return outlines
86
+
87
+
88
+ if __name__ == "__main__":
89
+ if len(sys.argv) != 3:
90
+ raise SystemExit("Usage: build_gpx_shape_templates.py GPX_DIRECTORY OUTPUT_JSON")
91
+ source, output = Path(sys.argv[1]), Path(sys.argv[2])
92
+ templates = build(source)
93
+ output.parent.mkdir(parents=True, exist_ok=True)
94
+ output.write_text(json.dumps(templates, separators=(",", ":")) + "\n", encoding="utf-8")
95
+ print({label: len(items) for label, items in templates.items()})
router/ai/scripts/clip_osm_region_test.py CHANGED
@@ -45,7 +45,7 @@ GATV2_WEIGHT_DEFAULT = 0.25
45
  IMAGE_PROTO_WEIGHT_DEFAULT = 1.0
46
  TEXT_PROTO_WEIGHT_DEFAULT = 0.0
47
  SOFTMAX_TEMPERATURE = 0.22
48
- STRICT_CLOSED_LABELS = {"cloud", "fish", "apple", "face"}
49
  SOFT_CLOSED_LABELS = {"cup", "ice_cream", "t_shirt", "candle", "dog"}
50
  PSEUDO_LABEL_MIN_RERANK_SCORE = 0.10
51
  PSEUDO_LABEL_MIN_CLIP_SCORE = 0.70
@@ -133,8 +133,35 @@ LABEL_GUIDED_WAYPOINTS: dict[str, list[tuple[float, float]]] = {
133
  (0.34, 0.24), (0.16, 0.22), (0.06, 0.38), (-0.08, 0.28),
134
  (-0.22, 0.28), (-0.36, 0.18), (-0.42, 0.06),
135
  ],
 
 
 
 
 
136
  }
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  LABEL_PROMPTS = {
139
  "cup": ["a route shaped like a cup", "an outline of a cup", "a line drawing of a cup"],
140
  "face": ["a route shaped like a face", "an outline of a face", "a line drawing of a face"],
@@ -153,6 +180,7 @@ LABEL_PROMPTS = {
153
  "apple": ["a route shaped like an apple", "an outline of an apple", "a line drawing of an apple"],
154
  "candle": ["a route shaped like a candle", "an outline of a candle", "a line drawing of a candle"],
155
  "dog": ["a route shaped like a dog", "an outline of a dog", "a line drawing of a dog"],
 
156
  }
157
 
158
  _CACHE_LOCK = threading.Lock()
@@ -708,6 +736,8 @@ def rotate_xy(x: float, y: float, angle_rad: float) -> tuple[float, float]:
708
  def guided_waypoints_for_label(label: str | None) -> list[tuple[float, float]]:
709
  if not label:
710
  return []
 
 
711
  return LABEL_GUIDED_WAYPOINTS.get(label, [])
712
 
713
 
@@ -1106,6 +1136,12 @@ def draw_template_mask(label: str, size: int = CANVAS_SIZE) -> np.ndarray:
1106
  cv2.line(m, (int(0.25 * s), int(0.55 * s)), (int(0.12 * s), int(0.42 * s)), 255, max(3, thick // 2))
1107
  cv2.line(m, (int(0.36 * s), int(0.70 * s)), (int(0.32 * s), int(0.84 * s)), 255, max(3, thick // 2))
1108
  cv2.line(m, (int(0.58 * s), int(0.70 * s)), (int(0.62 * s), int(0.84 * s)), 255, max(3, thick // 2))
 
 
 
 
 
 
1109
  else:
1110
  raise ValueError(f"Unsupported route label template: {label}")
1111
 
 
45
  IMAGE_PROTO_WEIGHT_DEFAULT = 1.0
46
  TEXT_PROTO_WEIGHT_DEFAULT = 0.0
47
  SOFTMAX_TEMPERATURE = 0.22
48
+ STRICT_CLOSED_LABELS = {"cloud", "fish", "apple", "face", "symbol_star"}
49
  SOFT_CLOSED_LABELS = {"cup", "ice_cream", "t_shirt", "candle", "dog"}
50
  PSEUDO_LABEL_MIN_RERANK_SCORE = 0.10
51
  PSEUDO_LABEL_MIN_CLIP_SCORE = 0.70
 
133
  (0.34, 0.24), (0.16, 0.22), (0.06, 0.38), (-0.08, 0.28),
134
  (-0.22, 0.28), (-0.36, 0.18), (-0.42, 0.06),
135
  ],
136
+ "symbol_star": [
137
+ (0.00, -0.48), (0.11, -0.15), (0.46, -0.15), (0.18, 0.06),
138
+ (0.29, 0.42), (0.00, 0.20), (-0.29, 0.42), (-0.18, 0.06),
139
+ (-0.46, -0.15), (-0.11, -0.15), (0.00, -0.48),
140
+ ],
141
  }
142
 
143
+
144
+ def _load_gpx_shape_templates() -> dict[str, list[list[tuple[float, float]]]]:
145
+ """Load GPS-free outlines extracted from the supplied GPX tracks."""
146
+ path = Path(__file__).resolve().parents[1] / "data" / "gpx_shape_templates.json"
147
+ if not path.is_file():
148
+ return {}
149
+ try:
150
+ payload = json.loads(path.read_text(encoding="utf-8"))
151
+ return {
152
+ label: [
153
+ [(float(x), float(y)) for x, y in outline]
154
+ for outline in payload.get(label, [])
155
+ if 5 <= len(outline) <= 25
156
+ ]
157
+ for label in ("dog", "symbol_star")
158
+ }
159
+ except (OSError, ValueError, TypeError, KeyError):
160
+ return {}
161
+
162
+
163
+ GPX_SHAPE_TEMPLATES = _load_gpx_shape_templates()
164
+
165
  LABEL_PROMPTS = {
166
  "cup": ["a route shaped like a cup", "an outline of a cup", "a line drawing of a cup"],
167
  "face": ["a route shaped like a face", "an outline of a face", "a line drawing of a face"],
 
180
  "apple": ["a route shaped like an apple", "an outline of an apple", "a line drawing of an apple"],
181
  "candle": ["a route shaped like a candle", "an outline of a candle", "a line drawing of a candle"],
182
  "dog": ["a route shaped like a dog", "an outline of a dog", "a line drawing of a dog"],
183
+ "symbol_star": ["a route shaped like a five-point star", "an outline of a star", "a line drawing of a star"],
184
  }
185
 
186
  _CACHE_LOCK = threading.Lock()
 
736
  def guided_waypoints_for_label(label: str | None) -> list[tuple[float, float]]:
737
  if not label:
738
  return []
739
+ if label in GPX_SHAPE_TEMPLATES and GPX_SHAPE_TEMPLATES[label]:
740
+ return random.choice(GPX_SHAPE_TEMPLATES[label]).copy()
741
  return LABEL_GUIDED_WAYPOINTS.get(label, [])
742
 
743
 
 
1136
  cv2.line(m, (int(0.25 * s), int(0.55 * s)), (int(0.12 * s), int(0.42 * s)), 255, max(3, thick // 2))
1137
  cv2.line(m, (int(0.36 * s), int(0.70 * s)), (int(0.32 * s), int(0.84 * s)), 255, max(3, thick // 2))
1138
  cv2.line(m, (int(0.58 * s), int(0.70 * s)), (int(0.62 * s), int(0.84 * s)), 255, max(3, thick // 2))
1139
+ elif label == "symbol_star":
1140
+ pts = np.array([
1141
+ [int((0.5 + x * 0.6) * s), int((0.5 + y * 0.6) * s)]
1142
+ for x, y in LABEL_GUIDED_WAYPOINTS["symbol_star"]
1143
+ ], dtype=np.int32)
1144
+ cv2.polylines(m, [pts.reshape(-1, 1, 2)], isClosed=True, color=255, thickness=thick)
1145
  else:
1146
  raise ValueError(f"Unsupported route label template: {label}")
1147