separate visuals from integration tests

This commit is contained in:
Motiejus Jakštys 2021-05-19 22:57:50 +03:00 committed by Motiejus Jakštys
parent 55bc1cc042
commit 8811e55728
4 changed files with 119 additions and 110 deletions

View File

@ -1,6 +1,5 @@
OSM ?= lithuania-latest.osm.pbf
#WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Merkys'
WHERE ?= name='Šalčia' OR name='Visinčia'
WHERE ?= name='Visinčia' OR name='Šalčia' OR name='Nemunas' OR name='Merkys'
#WHERE ?= name like '%'
SLIDES = slides-2021-03-29.pdf
@ -88,7 +87,7 @@ $(1).pdf: layer2img.py Makefile $(2)
)
endef
$(foreach fig,$(FIGURES),$(eval $(call FIG_template,$(fig),.faux_test)))
$(foreach fig,$(RIVERS), $(eval $(call FIG_template,$(fig),.faux_test-rivers)))
$(foreach fig,$(RIVERS), $(eval $(call FIG_template,$(fig),.faux_visuals)))
test-figures_1SELECT = wm_figures
@ -160,17 +159,21 @@ salvis-overlaid-visvalingam-64-chaikin-50k_WIDTHDIV = 2
salvis-overlaid-visvalingam-64-chaikin-50k_QUADRANT = 1
.faux_test-rivers: test-rivers.sql wm.sql Makefile .faux_db
bash db -v scaledwidth=$(SCALEDWIDTH) -f $<
.faux_db: db init.sql rivers.sql
bash db start
bash db -f init.sql -f rivers.sql
touch $@
.faux_test: test.sql wm.sql .faux_db
bash db -f $<
touch $@
.faux_db: db init.sql
bash db start
bash db -f init.sql -f rivers.sql
.faux_visuals: visuals.sql wm.sql Makefile .faux_db
bash db -v scaledwidth=$(SCALEDWIDTH) -f $<
touch $@
.faux_test-rivers: test-rivers.sql wm.sql Makefile .faux_db
bash db -f $<
touch $@
################################
@ -219,8 +222,8 @@ mj-msc-gray.pdf: mj-msc.pdf
.PHONY: clean
clean: ## Clean the current working directory
-bash db stop
-rm -r .faux_test .faux_aggregate-rivers .faux_test-rivers .faux_db \
version.inc.tex vars.inc.tex version.aux version.fdb_latexmk \
-rm -r .faux_test .faux_aggregate-rivers .faux_test-rivers .faux_visuals \
.faux_db version.inc.tex vars.inc.tex version.aux version.fdb_latexmk \
_minted-mj-msc \
$(shell git ls-files -o mj-msc*) \
$(addsuffix .pdf,$(FIGURES)) \

File diff suppressed because one or more lines are too long

View File

@ -1,100 +1,5 @@
\i wm.sql
-- wm_bbox clips a geometry by a bounding box around a given object,
-- matching dimensions of A-class paper (1 by sqrt(2).
drop function if exists wm_bbox;
create function wm_bbox(
center geometry,
scaledwidth float
) returns geometry as $$
declare
halfX float;
halfY float;
begin
halfX = scaledwidth / 2;
halfY = halfX * sqrt(2);
return st_envelope(
st_union(
st_translate(center, halfX, halfY),
st_translate(center, -halfX, -halfY)
)
);
end $$ language plpgsql;
-- wm_quadrant divides the given geometry to 4 rectangles
-- and returns the requested quadrant following cartesian
-- convention:
-- +----------+
-- | II | I |
--- +----------+
-- | III | IV |
-- +-----+----+
-- matching dimensions of A-class paper (1 by sqrt(2).
drop function if exists wm_quadrant;
create function wm_quadrant(
geom geometry,
quadrant integer
) returns geometry as $$
declare
xmin float;
xmax float;
ymin float;
ymax float;
begin
xmin = st_xmin(geom);
xmax = st_xmax(geom);
ymin = st_ymin(geom);
ymax = st_ymax(geom);
if quadrant = 1 or quadrant = 2 then
ymin = (ymin + ymax)/2;
else
ymax = (ymin + ymax)/2;
end if;
if quadrant = 2 or quadrant = 3 then
xmax = (xmin + xmax)/2;
else
xmin = (xmin + xmax)/2;
end if;
return st_intersection(
geom,
st_makeenvelope(xmin, ymin, xmax, ymax, st_srid(geom))
);
end $$ language plpgsql;
delete from wm_visuals where name like 'salvis%';
insert into wm_visuals(name, way) values('salvis', (
select st_intersection(
(select st_union(way) from wm_rivers where name in ('Šalčia', 'Visinčia')),
wm_bbox(
st_closestpoint(
(select way from wm_rivers where name='Šalčia'),
(select way from wm_rivers where name='Visinčia')
),
:scaledwidth
)
)
));
do $$
declare
i integer;
geom1 geometry;
geom2 geometry;
begin
foreach i in array array[16, 64, 256] loop
geom1 = st_simplify((select way from wm_visuals where name='salvis'), i);
geom2 = st_simplifyvw((select way from wm_visuals where name='salvis'), i*i);
insert into wm_visuals(name, way) values
('salvis-douglas-' || i, geom1),
('salvis-douglas-' || i || '-chaikin', st_chaikinsmoothing(geom1, 5)),
('salvis-visvalingam-' || i, geom2),
('salvis-visvalingam-' || i || '-chaikin', st_chaikinsmoothing(geom2, 5));
end loop;
end $$ language plpgsql;
\set ON_ERROR_STOP on
SET plpgsql.extra_errors TO 'all';
do $$
declare

100
visuals.sql Normal file
View File

@ -0,0 +1,100 @@
\set ON_ERROR_STOP on
SET plpgsql.extra_errors TO 'all';
-- wm_bbox clips a geometry by a bounding box around a given object,
-- matching dimensions of A-class paper (1 by sqrt(2)).
drop function if exists wm_bbox;
create function wm_bbox(
center geometry,
scaledwidth float
) returns geometry as $$
declare
halfX float;
halfY float;
begin
halfX = scaledwidth / 2;
halfY = halfX * sqrt(2);
return st_envelope(
st_union(
st_translate(center, halfX, halfY),
st_translate(center, -halfX, -halfY)
)
);
end $$ language plpgsql;
-- wm_quadrant divides the given geometry to 4 rectangles
-- and returns the requested quadrant following cartesian
-- convention:
-- +----------+
-- | II | I |
--- +----------+
-- | III | IV |
-- +-----+----+
-- matching dimensions of A-class paper (1 by sqrt(2).
drop function if exists wm_quadrant;
create function wm_quadrant(
geom geometry,
quadrant integer
) returns geometry as $$
declare
xmin float;
xmax float;
ymin float;
ymax float;
begin
xmin = st_xmin(geom);
xmax = st_xmax(geom);
ymin = st_ymin(geom);
ymax = st_ymax(geom);
if quadrant = 1 or quadrant = 2 then
ymin = (ymin + ymax)/2;
else
ymax = (ymin + ymax)/2;
end if;
if quadrant = 2 or quadrant = 3 then
xmax = (xmin + xmax)/2;
else
xmin = (xmin + xmax)/2;
end if;
return st_intersection(
geom,
st_makeenvelope(xmin, ymin, xmax, ymax, st_srid(geom))
);
end $$ language plpgsql;
delete from wm_visuals where name like 'salvis%';
insert into wm_visuals(name, way) values('salvis', (
select st_intersection(
(select st_union(way) from wm_rivers where name in ('Šalčia', 'Visinčia')),
wm_bbox(
st_closestpoint(
(select way from wm_rivers where name='Šalčia'),
(select way from wm_rivers where name='Visinčia')
),
:scaledwidth
)
)
));
do $$
declare
i integer;
geom1 geometry;
geom2 geometry;
begin
foreach i in array array[16, 64, 256] loop
geom1 = st_simplify((select way from wm_visuals where name='salvis'), i);
geom2 = st_simplifyvw((select way from wm_visuals where name='salvis'), i*i);
insert into wm_visuals(name, way) values
('salvis-douglas-' || i, geom1),
('salvis-douglas-' || i || '-chaikin', st_chaikinsmoothing(geom1, 5)),
('salvis-visvalingam-' || i, geom2),
('salvis-visvalingam-' || i || '-chaikin', st_chaikinsmoothing(geom2, 5));
end loop;
end $$ language plpgsql;
insert into wm_demo (name, way) select name, ST_SimplifyWM(way, 75, null, name) from wm_visuals where name='salvis';