File: make-filter-test

package info (click to toggle)
tippecanoe 2.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 148,236 kB
  • sloc: cpp: 44,069; ansic: 2,057; makefile: 454; perl: 129; python: 62; sh: 4
file content (134 lines) | stat: -rwxr-xr-x 5,947 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/perl

use strict;

open(GEOJSON, ">feature-filter/in.json");
open(FILTER, ">feature-filter/filter");

sub calchash {
	my $h = 0;
	my $s = $_[0];
	while ($s =~ s/^(.)//) {
		$h = ($h * 37 + ord($1)) & ((1 << 32) - 1);
	}
	return $h;
}

my $filter = "";
my $hash = 0;

print FILTER "{\n";
my $first = 1;

open(IN, "../../mapbox-gl-js/test/unit/style-spec/feature_filter.test.js");
while (<IN>) {
	if (/const f[0-9]* = filter\((.*)\);/) {
		$filter = $1;
		$filter =~ s/'/"/g;
		$hash = "layer" . calchash($filter);

		unless ($filter =~ /apply/) {
			if ($first) {
				$first = 0;
			} else {
				print FILTER ",\n";
			}

			print FILTER "\"$hash\": $filter,\n";
			print FILTER "\"not$hash\": [ \"none\", $filter ]\n";
		}
	}

	if (/t.equal\(f[0-9]*\({(.*)}\), ([a-z]+)\);/) {
		unless ($filter =~ /apply/) {
			my $prop = $1;
			my $matched = $2;

			if ($prop =~ /properties/) {
				next if $prop =~ /undefined/;

				$prop =~ s/properties/"properties"/g;
				$prop =~ s/foo/"foo"/g;
				$prop =~ s/id/"id"/g;
				$prop =~ s/undefined/null/g;
				$prop =~ s/'/"/g;

				my $qprop = "$prop, $filter";
				$qprop =~ s/"/\\"/g;

				if ($matched eq "true") {
					$prop =~ s/}/, \"rule\": \"$qprop\"}/;
					$prop =~ s/^"properties": {,/"properties": {/;

					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
				} else {
					$prop =~ s/}/, \"rule\": \"not $qprop\"}/;
					$prop =~ s/^"properties": {,/"properties": {/;

					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
				}
			} elsif ($prop =~ /id/) {
				$prop =~ s/id/"id"/g;
				$prop =~ s/'/"/g;

				my $qprop = "$prop, $filter";
				$qprop =~ s/"/\\"/g;

				if ($matched eq "true") {
					$qprop = "\"properties\": { \"rule\": \"$qprop\" }";

					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $prop, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $prop, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
				} else {
					$qprop = "\"properties\": { \"rule\": \"not $qprop\" }";

					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $prop, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
					print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $prop, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
				}
			} elsif ($prop =~ /type: (.)/) {
				my $type = $1;

				my $qprop = "$prop, $filter";
				$qprop =~ s/"/\\"/g;

				if ($matched eq "true") {
					$qprop = "\"properties\": { \"rule\": \"$qprop\" }";
				} else {
					$qprop = "\"properties\": { \"rule\": \"not $qprop\" }";
				}

				if ($type == 1) {
					if ($matched eq "true") {
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
					} else {
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $qprop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
					}
				} elsif ($type == 2) {
					if ($matched eq "true") {
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $qprop, \"geometry\": { \"type\": \"LineString\", \"coordinates\": [ [ 0, 0 ], [ 1, 1 ] ] } }\n";
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $qprop, \"geometry\": { \"type\": \"LineString\", \"coordinates\": [ [ -100, 0 ], [ -101, 1 ] ] } }\n";
					} else {
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $qprop, \"geometry\": { \"type\": \"LineString\", \"coordinates\": [ [ 0, 0 ], [ 1, 1 ] ] } }\n";
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $qprop, \"geometry\": { \"type\": \"LineString\", \"coordinates\": [ [ -100, 0 ], [ -101, 1 ] ] } }\n";
					}
				} else {
					if ($matched eq "true") {
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $qprop, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ 0, 0 ], [ 1, 1 ], [ 1, 0 ], [ 0, 0 ] ] ] } }\n";
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $qprop, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ -100, 0 ], [ -101, 1 ], [ -101, 0 ], [-100, 0 ] ] ] } }\n";
					} else {
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $qprop, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ 0, 0 ], [ 1, 1 ], [ 1, 0 ], [ 0, 0 ] ] ] } }\n";
						print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $qprop, \"geometry\": { \"type\": \"Polygon\", \"coordinates\": [ [ [ -100, 0 ], [ -101, 1 ], [ -101, 0 ], [-100, 0 ] ] ] } }\n";
					}
				}
			} else {
				print "$prop\n";
			}
		}
	}
}

print FILTER "}\n";