summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Hill.H4
-rw-r--r--src/Hill.cxx45
-rw-r--r--src/Panorama.cxx35
3 files changed, 51 insertions, 33 deletions
diff --git a/src/Hill.H b/src/Hill.H
index b3da4a6..7f7581f 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.H,v 1.13 2005/05/10 17:05:32 hofmann Exp $"
+// "$Id: Hill.H,v 1.14 2005/05/10 17:16:54 hofmann Exp $"
//
// Copyright 2005 by Johannes Hofmann
//
@@ -56,6 +56,8 @@ class Hills {
~Hills();
+ int load(const char *file);
+
void add(Hill *m);
void sort();
diff --git a/src/Hill.cxx b/src/Hill.cxx
index 02d3728..6df8d34 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Hill.cxx,v 1.12 2005/05/10 17:05:32 hofmann Exp $"
+// "$Id: Hill.cxx,v 1.13 2005/05/10 17:16:54 hofmann Exp $"
//
// Hill routines.
//
@@ -24,9 +24,12 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <math.h>
#include "Hill.H"
+static double pi_d, deg2rad;
+
Hill::Hill(const char *n, double p, double l, double h) {
name = strdup(n);
phi = p;
@@ -58,8 +61,48 @@ Hills::Hills() {
num = 0;
cap = 100;
m = (Hill **) malloc(cap * sizeof(Hill *));
+
+ pi_d = asin(1.0) * 2.0;
+ deg2rad = pi_d / 180.0;
+}
+
+int
+Hills::load(const char *file) {
+ FILE *fp;
+ char buf[4000];
+ char *vals[10];
+ char **ap, *bp;
+ double phi, lam, height;
+ Hill *m;
+
+ fp = fopen(file, "r");
+ if (!fp) {
+ perror("fopen");
+ return 1;
+ }
+
+ while (fgets(buf, sizeof(buf), fp)) {
+ bp = buf;
+ for (ap = vals; (*ap = strsep(&bp, ",")) != NULL;)
+ if (++ap >= &vals[10])
+ break;
+
+ phi = atof(vals[3]) * deg2rad;
+ lam = atof(vals[4]) * deg2rad;
+
+ height = atof(vals[5]);
+
+ m = new Hill(vals[1], phi, lam, height);
+
+ add(m);
+ }
+
+ fclose(fp);
+
+ return 0;
}
+
Hills::~Hills() {
if (m) {
free(m);
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index 38f2037..a9ab97b 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Panorama.cxx,v 1.37 2005/05/10 17:06:50 hofmann Exp $"
+// "$Id: Panorama.cxx,v 1.38 2005/05/10 17:16:54 hofmann Exp $"
//
// Panorama routines.
//
@@ -69,43 +69,16 @@ Panorama::~Panorama() {
delete(mountains);
}
+
int
Panorama::load_file(const char *name) {
- FILE *fp;
- char buf[4000];
- char *vals[10];
- char **ap, *bp;
- double phi, lam, height;
- Hill *m;
-
visible_mountains->clear();
mountains->clobber();
-
-
- fp = fopen(name, "r");
- if (!fp) {
- perror("fopen");
- return 1;
- }
- while (fgets(buf, sizeof(buf), fp)) {
- bp = buf;
- for (ap = vals; (*ap = strsep(&bp, ",")) != NULL;)
- if (++ap >= &vals[10])
- break;
-
- phi = atof(vals[3]) * deg2rad;
- lam = atof(vals[4]) * deg2rad;
-
- height = atof(vals[5]);
-
- m = new Hill(vals[1], phi, lam, height);
-
- mountains->add(m);
+ if (mountains->load(name) != 0) {
+ return 1;
}
- fclose(fp);
-
update_angles();
return 0;