123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- TITLE
- C Week 2 Project
- Esty (Katherine) Thomas
- Goal:
- The problem in this project was to address the problem that
- a data structure full of pointers can't meaningfully be
- written to disk and then reconstructed with any guarantee
- that each pointer will still refer to the same object. The
- specific type of data used was the components of polyhedrons:
- faces, edges, and vertices. Each face contains a pointer to
- another face and an edge, and each edge contains pointers to two
- vertices and another edge.
- The general strategy suggested, the one that I took, was to
- create 'printable' versions of the face & edge structs (as the
- vertices have no pointers), stick them in arrays, and replace
- the pointers with array indices.
- Methods:
- Pointerly edges and faces, and vertices, are implemented as in the
- provided code, except instead of a name they have an 'id', which is
- incremented with each new face, edge, or vertex (type-specific).
- Matrices are mostly implemented as in the provided code, with additions
- and modifications from my Week 1 project (but no radical changes).
- "Printable" edges and faces are implemented as suggested, with array
- indices standing in for pointers. The normal vector for a face is not
- calculated; a (0,0,0) vector stands in as default.
- When a new printable edge or face is created, and when a new vertex is
- created, it is added to an array of its type at the index of its ID number.
- These arrays are initialized at 50, as suggested in the assignment.
- As previously implied, the pointer fields of the edge and face structs are
- replaced by the ID number of the struct pointed to, in the printable version.
- The edge and face creation routines are recursive, creating new edges and faces
- as needed, checking against the master arrays. These routines do not touch the
- vertices, since those are already in their array and are presumed to not change.
- The routine which prints everything to a file ('printificate") is iterative,
- printing first all the faces and then all the edges. Matrices and vertices are
- printed inside the descriptions of the face or edge to which they belong.
- My test program creates four vertices describing a quadrilateral, the edges
- connecting them, and the face formed by the edges. It calls printificate on this
- 2-D figure, which works as desired. It then attempts to call my reconstruct-from-file
- function ('readificate') on the output file, which completely fails, because my
- understanding of fscanf is evidently insufficient, as is my understanding of what
- is going wrong with the program. This lack of understanding means that readificate
- is a horribly tangled mess of code, in addition to not working. It is very much non-modular
- and generally inferior in every way.
- TRANSCRIPT:
- esty-thomass-macbook:173C2 esty$ make
- gcc -c -g FEV.c
- gcc -o runmytest -g mytest.o matrix.o FEV.o
- esty-thomass-macbook:173C2 esty$ ./runmytest
- Formatting error (matrix, face)
-
- CONTENTS OF OUTTEST:
- VERTICES: 4
- EDGES: 4
- FACES: 1
- FACE: Type: 10, ID: 0
- MATRIX: Normal Direction Type: 13 , Dims 1, 3
- 0.00 0.00 0.00
- ~
- Next Edge: 0.
- Next Face: -1.
- ~~~~
- EDGE: Type: 11, ID: 0
- MATRIX: Edge Direction Type: 13 , Dims 3, 1
- 3.00
- 0.00
- 0.00
- ~
- VERTEX: From Vertex Type: 12 , ID: 0
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 4.00
- 0.00
- 0.00
- ~
- ~~
- VERTEX: To Vertex Type: 12 , ID: 1
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 1.00
- 0.00
- 0.00
- ~
- ~~
- Next Edge: 1.
- ~~~
- EDGE: Type: 11, ID: 1
- MATRIX: Edge Direction Type: 13 , Dims 3, 1
- 0.00
- -1.00
- 0.00
- ~
- VERTEX: From Vertex Type: 12 , ID: 1
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 1.00
- 0.00
- 0.00
- ~
- ~~
- VERTEX: To Vertex Type: 12 , ID: 2
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 1.00
- 1.00
- 0.00
- ~
- ~~
- Next Edge: 2.
- ~~~
- EDGE: Type: 11, ID: 2
- MATRIX: Edge Direction Type: 13 , Dims 3, 1
- 1.00
- 0.00
- 0.00
- ~
- VERTEX: From Vertex Type: 12 , ID: 2
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 1.00
- 1.00
- 0.00
- ~
- ~~
- VERTEX: To Vertex Type: 12 , ID: 3
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 0.00
- 1.00
- 0.00
- ~
- ~~
- Next Edge: 3.
- ~~~
- EDGE: Type: 11, ID: 3
- MATRIX: Edge Direction Type: 13 , Dims 3, 1
- -4.00
- 1.00
- 0.00
- ~
- VERTEX: From Vertex Type: 12 , ID: 3
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 0.00
- 1.00
- 0.00
- ~
- ~~
- VERTEX: To Vertex Type: 12 , ID: 0
- MATRIX: Vertex Coords Type: 13 , Dims 3, 1
- 4.00
- 0.00
- 0.00
- ~
- ~~
- Next Edge: 0.
- ~~~
-
|