File: graph.h

package info (click to toggle)
gplanarity 17906-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 732 kB
  • sloc: ansic: 8,776; makefile: 131; perl: 17; sed: 2
file content (146 lines) | stat: -rw-r--r-- 4,215 bytes parent folder | download | duplicates (7)
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
135
136
137
138
139
140
141
142
143
144
145
146
/*
 *
 *  gPlanarity: 
 *     The geeky little puzzle game with a big noodly crunch!
 *    
 *     gPlanarity copyright (C) 2005 Monty <monty@xiph.org>
 *     Original Flash game by John Tantalo <john.tantalo@case.edu>
 *     Original game concept by Mary Radcliffe
 *
 *  gPlanarity is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  gPlanarity is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with Postfish; see the file COPYING.  If not, write to the
 *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * 
 */

#define V_RADIUS_SQ (V_RADIUS*V_RADIUS)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

typedef struct vertex {
  int num;
  int x;
  int y;
  int orig_x;
  int orig_y;

  int active;
  int selected_volatile;
  int selected;
  int grabbed;
  int attached_to_grabbed;
  int fading;
  struct edge_list *edges;
  struct vertex *next;
} vertex;

typedef struct intersection {
  struct intersection *prev;
  struct intersection *next;
  struct intersection *paired;
  double x;
  double y;
} intersection;

typedef struct edge{
  vertex *A;
  vertex *B;

  int active;

  intersection i; // correct, not a pointer
  struct edge *next;
} edge;

typedef struct edge_list{
  edge *edge;
  struct edge_list *next;
} edge_list;

typedef struct graph {
  vertex *verticies;
  int     vertex_num;
  edge *edges;
  long active_intersections;

  int num_edges;
  int num_edges_active;

  int width;
  int height;
  int orig_width;
  int orig_height;

  // scoring related metadata
  long  original_intersections;
  float intersection_mult;
  int   objective;
  int   objective_lessthan;
  float objective_mult;

} graph;

typedef struct graphmeta{
  int num;
  char *id;
  char *desc;
  void (*gen)(graph *,int arg);
  int gen_arg;
  int unlock_plus;
} graphmeta;

#include <stdio.h>

extern vertex *new_board(graph *g, int num_v);
extern vertex *find_vertex(graph *g, int x, int y);

extern edge_list *add_edge_to_list(edge_list *l, edge *e);
extern void release_edge_list(edge_list *el);
extern edge *new_edge(vertex *A, vertex *B);
extern void release_edge_list(edge_list *el);
extern void insert_edge(graph *g, edge *e);
extern int intersectsV(vertex *L1, vertex *L2, vertex *M1, vertex *M2, 
		       double *xo, double *yo);
extern int intersects(int L1x, int L1y, int L2x, int L2y,
		      int M1x, int M1y, int M2x, int M2y,
		      double *xo, double *yo);
extern void move_vertex(graph *g, vertex *v, int x, int y);
extern void grab_vertex(graph *g, vertex *v);
extern void grab_selected(graph *g);
extern void ungrab_vertex(graph *g,vertex *v);
extern void ungrab_verticies(graph *g);
extern void activate_vertex(graph *g, vertex *v);
extern void deactivate_vertex(graph *g, vertex *v);
extern void select_verticies(graph *g, int x1, int y1, int x2, int y2);
extern void deselect_verticies(graph *g);
extern void move_selected_verticies(graph *g, int dx, int dy);
extern void scale_verticies(graph *g, float amount);
extern void randomize_verticies(graph *g);
extern edge *add_edge(graph *g,vertex *A, vertex *B);
extern int exists_edge(vertex *a, vertex *b);
extern int num_selected_verticies(graph *g);
extern void check_verticies(graph *g);
extern void impress_location(graph *g);
extern void commit_volatile_selection(graph *g);
extern void activate_verticies(graph *g);
extern int graph_write(graph *g, FILE *f);
extern int graph_read(graph *g, FILE *f);
extern void graph_release(graph *g);

extern int   graphscore_get_score(graph *g);
extern int   graphscore_get_raw_score(graph *g);
extern int   graphscore_get_multiplier_percent(graph *g);
extern int   graphscore_get_bonus(graph *g);
extern char *graphscore_objective_string(graph *g);
extern void graph_resize(graph *g, int width, int height);