--- a
+++ b/distortion.h
@@ -0,0 +1,68 @@
+/*
+A library for calibrating gemteric screen distortions, and adjusting
+for these distortions
+*/
+
+#pragma once
+
+#include <vect.h>
+#include <ideo.h>
+
+struct distortion_options {
+	v2 grid_center;
+	v2 cell_size;
+	unsigned int n_grid_x, n_grid_y;
+	double calc_power;		// exponent used in calculating node weights as a function of distance
+	double max_weight;		// maximum weight: the power function used in the calculation blows up at zero
+	//unsigned int degree;
+
+	distortion_options()
+	{
+		grid_center = v2(0);
+		cell_size = v2(3, 3);
+		n_grid_x = 7;
+		n_grid_y = 5;
+		calc_power = 2;
+		max_weight = 1.0e+10;
+		//degree = 3;
+	}
+};
+
+class distortion {
+public:
+	distortion();
+	distortion(const distortion_options &opt);
+	~distortion();
+
+	void show_grid(ideo *pid);
+	void set_node(int i, int j, const v2 &pos);
+	void move_node(int i, int j, const v2 &disp);
+
+	bool calc(const v2 &phys, v2 &log);		// calculates the logical position necessary for point to be at corresponding physical position
+
+	// if file name is empty, uses default file
+	void save(const string &fn = "", const string &comment = "", bool append = false);
+	void load(const string &fn = "");
+	void get_comment(string &comment)	{ comment = _comment; }
+
+	/*
+	void fit();
+	void show_fit(ideo *pid);
+	*/
+
+	void calibrate(ideo *pid);		// returns true when done
+
+private:
+	void init(const distortion_options &opt);
+	void make_grid(v2 **&g);
+	void free_grid(v2 **&g);
+
+	distortion_options _opt;
+	v2 **_grid0;				// these are the physical positions (fixed) of the nodes
+	v2 **_grid;					// these are the logical position (adjusted) which result in the node being in the corresponding physical position
+	string _comment;
+	/*
+	bool _fit;
+	multi_coeff_t _fit_coeff[2];
+	*/
+};