Fix missing import in finiterectlat-scatter.py
[qpms.git] / oldtests / lattice / 2d_triangular_lattice.c
blobbb196d63da731808875cd13ec876b473f3226fdb
1 #include <qpms/lattices.h>
2 #include <stdio.h>
3 #include <float.h>
5 void dump_points2d_rordered(const points2d_rordered_t *ps, char *filename) {
6 FILE *f = fopen(filename, "w");
7 for (size_t i = 0; i < ps->nrs; ++i) {
8 fprintf(f, "# r = %.16g\n", ps->rs[i]);
9 for (ptrdiff_t j = ps->r_offsets[i]; j < ps->r_offsets[i+1]; ++j)
10 fprintf(f, "%.16g %.16g\n", ps->base[j].x, ps->base[j].y);
12 fclose(f);
15 int main() {
16 triangular_lattice_gen_t *g = triangular_lattice_gen_init(5, TRIANGULAR_HORIZONTAL, false,0);
17 dump_points2d_rordered(&(g->ps), "triang_h_empty.out");
19 points2d_rordered_t *p = points2d_rordered_scale(&(g->ps), 1.5464);
20 dump_points2d_rordered(p, "triang_h_empty_scaled.out");
22 points2d_rordered_free(p);
23 triangular_lattice_gen_free(g);
25 g = triangular_lattice_gen_init(5, TRIANGULAR_HORIZONTAL, false,0);
26 triangular_lattice_gen_extend_to_steps(g, 5);
27 dump_points2d_rordered(&(g->ps), "triang_h_s5.out");
28 triangular_lattice_gen_extend_to_steps(g, 20);
29 dump_points2d_rordered(&(g->ps), "triang_h_s20.out");
30 triangular_lattice_gen_extend_to_steps(g, 160);
31 dump_points2d_rordered(&(g->ps), "triang_h_s160.out");
32 triangular_lattice_gen_extend_to_steps(g, 20);
33 dump_points2d_rordered(&(g->ps), "triang_h_s160_20.out");
34 p = points2d_rordered_scale(&(g->ps), -.2);
35 dump_points2d_rordered(p, "triang_h_s160_20_scaled.out");
37 points2d_rordered_t v = points2d_rordered_annulus(p, 15, true, 17, true);
38 dump_points2d_rordered(&v, "triang_h_ann_i15-i17.out");
39 v = points2d_rordered_annulus(p, 15, false, 17, true);
40 dump_points2d_rordered(&v, "triang_h_ann_x15-i17.out");
41 v = points2d_rordered_annulus(p, 15, false, 17, false);
42 dump_points2d_rordered(&v, "triang_h_ann_x15-x17.out");
43 v = points2d_rordered_annulus(p, 15, true, 17, false);
44 dump_points2d_rordered(&v, "triang_h_ann_i15-x17.out");
46 points2d_rordered_free(p);
47 triangular_lattice_gen_free(g);
50 g = triangular_lattice_gen_init(7, TRIANGULAR_VERTICAL, true,1);
51 triangular_lattice_gen_extend_to_steps(g, 7);
52 dump_points2d_rordered(&(g->ps), "triang_v_plus_s7.out");
53 p = points2d_rordered_scale(&(g->ps), 1/7.);
54 triangular_lattice_gen_free(g);
55 dump_points2d_rordered(p, "triang_v_plus_s7_scaled_out");
56 points2d_rordered_free(p);
57 g = triangular_lattice_gen_init(7, TRIANGULAR_VERTICAL, true,-1);
58 triangular_lattice_gen_extend_to_steps(g, 7);
59 dump_points2d_rordered(&(g->ps), "triang_v_minus_s7.out");
60 p = points2d_rordered_scale(&(g->ps), 1/7.);
61 triangular_lattice_gen_free(g);
62 dump_points2d_rordered(p, "triang_v_minus_s7_scaled.out");
63 points2d_rordered_free(p);
65 honeycomb_lattice_gen_t *h = honeycomb_lattice_gen_init_h(1, TRIANGULAR_HORIZONTAL);
66 dump_points2d_rordered(&(h->ps), "hex_h_empty.out");
67 honeycomb_lattice_gen_extend_to_steps(h, 7);
68 dump_points2d_rordered(&(h->ps), "hex_h_s7.out");
69 point2d shift = {0, h->h};
70 p = points2d_rordered_shift(&(h->ps), shift, DBL_EPSILON, h->h * DBL_EPSILON);
71 dump_points2d_rordered(p, "hex_h_s7_shifted.out");
72 points2d_rordered_free(p);
73 honeycomb_lattice_gen_extend_to_steps(h, 120);
74 dump_points2d_rordered(&(h->ps), "hex_h_s120.out");
75 honeycomb_lattice_gen_free(h);
77 h = honeycomb_lattice_gen_init_a(1, TRIANGULAR_VERTICAL);
78 honeycomb_lattice_gen_extend_to_steps(h, 5);
79 dump_points2d_rordered(&(h->ps), "hex_v_s5.out");
80 honeycomb_lattice_gen_free(h);
82 return 0;