Skip to content
Snippets Groups Projects
Commit 7fbcadc7 authored by mika's avatar mika
Browse files

dwyer uses svg + code cleanup

parent a8555878
No related branches found
No related tags found
No related merge requests found
...@@ -55,9 +55,9 @@ typedef int EDGE_PTR; ...@@ -55,9 +55,9 @@ typedef int EDGE_PTR;
typedef unsigned short VERTEX_PTR; typedef unsigned short VERTEX_PTR;
struct VEC2 { /*struct VEC2 {
double x,y; double x,y;
}; };*/
struct VERTEX { struct VERTEX {
struct VEC2 v; struct VEC2 v;
...@@ -533,8 +533,11 @@ else { /* Quicksort */ ...@@ -533,8 +533,11 @@ else { /* Quicksort */
/* plots a site on your favorite device. */ /* plots a site on your favorite device. */
plot_site(v) VERTEX_PTR v; { plot_site(v) VERTEX_PTR v; {
#ifdef POSTSCRIPT
printf("p%d drawsite\n", v);
#endif
#ifdef OUTPUTFILE #ifdef OUTPUTFILE
fprintf(out, "p%d drawsite\n", v); svgDrawSite(va[v].v);
#endif #endif
} }
...@@ -545,6 +548,9 @@ plot_dt_edge(e) ...@@ -545,6 +548,9 @@ plot_dt_edge(e)
#ifdef POSTSCRIPT #ifdef POSTSCRIPT
printf("p%d p%d drawseg\n", orig(e), dest(e)); printf("p%d p%d drawseg\n", orig(e), dest(e));
#endif #endif
#ifdef OUTPUTFILE
svgDrawLine(va[orig(e)].v, va[dest(e)].v);
#endif
} }
BOOLEAN forward(e, base) BOOLEAN forward(e, base)
...@@ -727,6 +733,9 @@ struct VEC2 v1, v2; ...@@ -727,6 +733,9 @@ struct VEC2 v1, v2;
#ifdef POSTSCRIPT #ifdef POSTSCRIPT
printf("%f %f %f %f drawline\n", v1.x, v1.y, v2.x, v2.y); printf("%f %f %f %f drawline\n", v1.x, v1.y, v2.x, v2.y);
#endif #endif
#ifdef OUTPUTFILE
svgDrawLine(v1, v2);
#endif
} }
plot_infinite_vd_edge(e) plot_infinite_vd_edge(e)
...@@ -1114,6 +1123,9 @@ EDGE_PTR e; ...@@ -1114,6 +1123,9 @@ EDGE_PTR e;
#ifdef POSTSCRIPT #ifdef POSTSCRIPT
printf("p%d p%d drawseg\n", orig(e), dest(e)); printf("p%d p%d drawseg\n", orig(e), dest(e));
#endif #endif
#ifdef OUTPUTFILE
svgDrawLine(va[orig(e)].v, va[dest(e)].v);
#endif
} }
dumpedge(e) EDGE_PTR e; dumpedge(e) EDGE_PTR e;
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
#include "helper.h" #include "helper.h"
void svgDrawLine(edge l, char *color) {
void svgDrawLine(vertex a, vertex b) {
#ifdef OUTPUTFILE #ifdef OUTPUTFILE
fprintf(out, "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:rgb(%s);stroke-width:1\" />\n", l.a.x*W, l.a.y*H, l.b.x*W, l.b.y*H, color); fprintf(out, "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:purple;stroke-width:1\" />\n", a.x*W, a.y*H, b.x*W, b.y*H);
#endif #endif
} }
...@@ -27,7 +29,7 @@ void svgDrawTriangle(vertex a, vertex b, vertex c) { ...@@ -27,7 +29,7 @@ void svgDrawTriangle(vertex a, vertex b, vertex c) {
void svgDrawSite(vertex v) { void svgDrawSite(vertex v) {
#ifdef OUTPUTFILE #ifdef OUTPUTFILE
fprintf(out, "<circle cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />", v.x*W, v.y*H, 2); fprintf(out, "<circle cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />", v.x*W, v.y*H, 2.0);
#endif #endif
} }
......
...@@ -8,13 +8,19 @@ ...@@ -8,13 +8,19 @@
#ifndef HELPER_H_ #ifndef HELPER_H_
#define HELPER_H_ #define HELPER_H_
#define OUTPUTFILE "output.html"
#include <stdio.h> #include <stdio.h>
#define W 1000 #define W 2000
#define H 1000 #define H 2000
#define M 255
typedef struct { #ifdef OUTPUTFILE
FILE *out;
#endif
typedef struct VEC2{
double x, y; double x, y;
} vertex; } vertex;
...@@ -22,7 +28,7 @@ typedef struct { ...@@ -22,7 +28,7 @@ typedef struct {
vertex a; vertex a;
vertex b; vertex b;
vertex c; vertex c;
}; } blub;
typedef struct { typedef struct {
vertex center; vertex center;
...@@ -36,8 +42,9 @@ typedef struct { ...@@ -36,8 +42,9 @@ typedef struct {
void writeSvgStart (); void writeSvgStart ();
void writeSvgEnd (); void writeSvgEnd ();
void svgDrawLine(edge, char *); void svgDrawLine(vertex, vertex);
void svgDrawCircle(circle); void svgDrawCircle(circle);
void svgDrawTriangle(vertex, vertex, vertex); void svgDrawTriangle(vertex, vertex, vertex);
void svgDrawSite(vertex);
#endif /* HELPER_H_ */ #endif /* HELPER_H_ */
...@@ -5,21 +5,16 @@ ...@@ -5,21 +5,16 @@
* Author: Mika * Author: Mika
*/ */
#define OUTPUTFILE "output.html" #include "main.h"
#include "delaunay.h"
#include "voronoi.h"
#ifdef OUTPUTFILE
FILE *out;
#endif
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
//input: 1. function 0=cws_delaunay 2. # of points, 3. # of executions //input: 1. function 0=cws_delaunay 2. # of points, 3. # of executions
//create_image(); //create_image();
//write_ppm ( "sine.ppm" ); //write_ppm ( "sine.ppm" );
int numberOfPoints = 10000; int numberOfPoints = 20;
int function = 0; int function = 2;
int executions = 1; int executions = 1;
if(argc > 0) { if(argc > 0) {
//printf("%s\n", argv[0]); //printf("%s\n", argv[0]);
...@@ -33,7 +28,7 @@ int main(int argc, char *argv[]) { ...@@ -33,7 +28,7 @@ int main(int argc, char *argv[]) {
vertex points[numberOfPoints]; vertex points[numberOfPoints];
generatePoints(points, numberOfPoints); generatePoints(points, numberOfPoints);
printf("%u\n", sizeof(points)); printf("%lu\n", sizeof(points));
fflush(stdout); fflush(stdout);
//drawPoints(points, numberOfPoints); //drawPoints(points, numberOfPoints);
......
/*
* main.h
*
* Created on: Dec 5, 2018
* Author: mika
*/
#ifndef MAIN_H_
#define MAIN_H_
#include "delaunay.h"
#include "voronoi.h"
#include "helper.h"
#endif /* MAIN_H_ */
...@@ -13,11 +13,10 @@ circle center(vertexCircle vc) { ...@@ -13,11 +13,10 @@ circle center(vertexCircle vc) {
circle c = circleFrom3Points(vc.a, vc.b, vc.c); circle c = circleFrom3Points(vc.a, vc.b, vc.c);
return c; return c;
} }
int reportEdge(edge l) { int reportEdge(vertex a, vertex b) {
//svgDrawCircle(a,out); //svgDrawCircle(a,out);
//svgDrawCircle(b,out); //svgDrawCircle(b,out);
char *color = "0,0,255"; svgDrawLine(a, b);
svgDrawLine(l, color);
return 0; return 0;
} }
...@@ -91,12 +90,12 @@ void voronoiCws(vertex* S, int size) { ...@@ -91,12 +90,12 @@ void voronoiCws(vertex* S, int size) {
} else { } else {
if(!outOfBorder(currentV)) { if(!outOfBorder(currentV)) {
#ifdef OUTPUTFILE #ifdef OUTPUTFILE
reportEdge((edge){currentV, lastV}, out); reportEdge(currentV, lastV);
#endif #endif
} }
if(k == j0) { if(k == j0) {
#ifdef OUTPUTFILE #ifdef OUTPUTFILE
reportEdge((edge){currentV, firstV}); reportEdge(currentV, firstV);
#endif #endif
} }
} }
...@@ -110,14 +109,14 @@ void voronoiCws(vertex* S, int size) { ...@@ -110,14 +109,14 @@ void voronoiCws(vertex* S, int size) {
} else { } else {
if(!outOfBorder(lastV)) { if(!outOfBorder(lastV)) {
#ifdef OUTPUTFILE #ifdef OUTPUTFILE
reportEdge((edge){currentV, lastV}, out); reportEdge(currentV, lastV);
#endif #endif
} }
} }
currentV = findBorderVertex(S[i], S[k]); currentV = findBorderVertex(S[i], S[k]);
if(k == j0) { if(k == j0) {
if(!outOfBorder(firstV)) { if(!outOfBorder(firstV)) {
reportEdge((edge){currentV, firstV}); reportEdge(currentV, firstV);
} }
} }
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define SRC_VORONOI_H_ #define SRC_VORONOI_H_
#include "delaunay.h" #include "delaunay.h"
#include "helper.h"
/** /**
...@@ -50,7 +51,7 @@ edgeCircle clockwiseNextVoronoiEdge(edgeCircle e); ...@@ -50,7 +51,7 @@ edgeCircle clockwiseNextVoronoiEdge(edgeCircle e);
*/ */
edgeCircle nextVoronoiEdgeOnBoudary(edgeCircle e); edgeCircle nextVoronoiEdgeOnBoudary(edgeCircle e);
int reportEdge(edge l); int reportEdge(vertex, vertex);
void voronoiCws(vertex* S, int size); void voronoiCws(vertex* S, int size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment