Commit eb30339334a34b0838fd038914032391658db4f2
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,8 +69,9 @@ struct vec : public std::vector<T> | ||
69 | //copy constructor | 69 | //copy constructor |
70 | vec( const vec<T>& other){ | 70 | vec( const vec<T>& other){ |
71 | unsigned int N = other.size(); | 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 | //I'm not sure what these were doing here. | 77 | //I'm not sure what these were doing here. |
stim/visualization/obj.h
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <stim/parser/parser.h> | 8 | #include <stim/parser/parser.h> |
9 | #include <stim/math/vector.h> | 9 | #include <stim/math/vector.h> |
10 | +#include <algorithm> | ||
10 | 11 | ||
11 | namespace stim{ | 12 | namespace stim{ |
12 | 13 | ||
@@ -572,8 +573,6 @@ public: | @@ -572,8 +573,6 @@ public: | ||
572 | std::vector< stim::vec<T> > v; | 573 | std::vector< stim::vec<T> > v; |
573 | v.resize(vi.size()); //pre-allocate an array of vertices | 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 | for(unsigned i = 0; i < vi.size(); i++) | 576 | for(unsigned i = 0; i < vi.size(); i++) |
578 | v[i] = V[vi[i] - 1]; | 577 | v[i] = V[vi[i] - 1]; |
579 | 578 | ||
@@ -587,8 +586,6 @@ public: | @@ -587,8 +586,6 @@ public: | ||
587 | std::vector< stim::vec<T> > vt; | 586 | std::vector< stim::vec<T> > vt; |
588 | vt.resize(vti.size()); //pre-allocate an array of vertices | 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 | for(unsigned i = 0; i < vti.size(); i++) | 589 | for(unsigned i = 0; i < vti.size(); i++) |
593 | vt[i] = VT[vti[i] - 1]; | 590 | vt[i] = VT[vti[i] - 1]; |
594 | 591 | ||
@@ -602,8 +599,6 @@ public: | @@ -602,8 +599,6 @@ public: | ||
602 | std::vector< stim::vec<T> > vn; | 599 | std::vector< stim::vec<T> > vn; |
603 | vn.resize(vni.size()); //pre-allocate an array of vertices | 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 | for(unsigned i = 0; i < vni.size(); i++) | 602 | for(unsigned i = 0; i < vni.size(); i++) |
608 | vn[i] = VN[vni[i] - 1]; | 603 | vn[i] = VN[vni[i] - 1]; |
609 | 604 | ||
@@ -794,14 +789,14 @@ public: | @@ -794,14 +789,14 @@ public: | ||
794 | } | 789 | } |
795 | 790 | ||
796 | /// Returns a list of points corresponding to the vertices of a line | 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 | std::vector<unsigned> vi; //create a vector to store indices to vertices | 794 | std::vector<unsigned> vi; //create a vector to store indices to vertices |
800 | getLinei(l, vi); //get the indices for the line vertices | 795 | getLinei(l, vi); //get the indices for the line vertices |
801 | v = getV(vi); //get the vertices corresponding to the indices | 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 | std::vector<unsigned> vi, vti; | 801 | std::vector<unsigned> vi, vti; |
807 | getLinei(l, vi, vti); //get the indices for the line vertices | 802 | getLinei(l, vi, vti); //get the indices for the line vertices |
@@ -809,9 +804,9 @@ public: | @@ -809,9 +804,9 @@ public: | ||
809 | vt = getVT(vti); | 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 | std::vector<unsigned> vi, vti, vni; | 811 | std::vector<unsigned> vi, vti, vni; |
817 | getLinei(l, vi, vti, vni); //get the indices for the line vertices | 812 | getLinei(l, vi, vti, vni); //get the indices for the line vertices |