Commit eb30339334a34b0838fd038914032391658db4f2

Authored by David Mayerich
1 parent 2dec3dbb

updates to the stim::vec class

Showing 2 changed files with 9 additions and 13 deletions   Show diff stats
stim/math/vector.h
... ... @@ -69,8 +69,9 @@ struct vec : public std::vector<T>
69 69 //copy constructor
70 70 vec( const vec<T>& other){
71 71 unsigned int N = other.size();
72   - for(unsigned int i=0; i<N; i++)
73   - push_back(other[i]);
  72 + resize(N); //resize the current vector to match the copy
  73 + for(unsigned int i=0; i<N; i++) //copy each element
  74 + at(i) = other[i];
74 75 }
75 76  
76 77 //I'm not sure what these were doing here.
... ...
stim/visualization/obj.h
... ... @@ -7,6 +7,7 @@
7 7 #include <stdlib.h>
8 8 #include <stim/parser/parser.h>
9 9 #include <stim/math/vector.h>
  10 +#include <algorithm>
10 11  
11 12 namespace stim{
12 13  
... ... @@ -572,8 +573,6 @@ public:
572 573 std::vector< stim::vec<T> > v;
573 574 v.resize(vi.size()); //pre-allocate an array of vertices
574 575  
575   - std::cout<<"stim::obj::getV: "<<v.size()<<std::endl;
576   -
577 576 for(unsigned i = 0; i < vi.size(); i++)
578 577 v[i] = V[vi[i] - 1];
579 578  
... ... @@ -587,8 +586,6 @@ public:
587 586 std::vector< stim::vec<T> > vt;
588 587 vt.resize(vti.size()); //pre-allocate an array of vertices
589 588  
590   - std::cout<<"stim::obj::getV: "<<vt.size()<<std::endl;
591   -
592 589 for(unsigned i = 0; i < vti.size(); i++)
593 590 vt[i] = VT[vti[i] - 1];
594 591  
... ... @@ -602,8 +599,6 @@ public:
602 599 std::vector< stim::vec<T> > vn;
603 600 vn.resize(vni.size()); //pre-allocate an array of vertices
604 601  
605   - std::cout<<"stim::obj::getV: "<<vn.size()<<std::endl;
606   -
607 602 for(unsigned i = 0; i < vni.size(); i++)
608 603 vn[i] = VN[vni[i] - 1];
609 604  
... ... @@ -794,14 +789,14 @@ public:
794 789 }
795 790  
796 791 /// Returns a list of points corresponding to the vertices of a line
797   - void getLine(unsigned l, std::vector< stim::vec<T> > v){
  792 + void getLine(unsigned l, std::vector< stim::vec<T> >& v){
798 793  
799 794 std::vector<unsigned> vi; //create a vector to store indices to vertices
800 795 getLinei(l, vi); //get the indices for the line vertices
801 796 v = getV(vi); //get the vertices corresponding to the indices
802 797 }
803 798  
804   - void getLine(unsigned l, std::vector< stim::vec<T> > v, std::vector< stim::vec<T> > vt){
  799 + void getLine(unsigned l, std::vector< stim::vec<T> >& v, std::vector< stim::vec<T> >& vt){
805 800  
806 801 std::vector<unsigned> vi, vti;
807 802 getLinei(l, vi, vti); //get the indices for the line vertices
... ... @@ -809,9 +804,9 @@ public:
809 804 vt = getVT(vti);
810 805 }
811 806  
812   - void getLine(unsigned l, std::vector< stim::vec<T> > v,
813   - std::vector< stim::vec<T> > vt,
814   - std::vector< stim::vec<T> > vn){
  807 + void getLine(unsigned l, std::vector< stim::vec<T> >& v,
  808 + std::vector< stim::vec<T> >& vt,
  809 + std::vector< stim::vec<T> >& vn){
815 810  
816 811 std::vector<unsigned> vi, vti, vni;
817 812 getLinei(l, vi, vti, vni); //get the indices for the line vertices
... ...