segment.cpp (780B)
1 #include "all_includes.hh" 2 3 Segment::Segment(Vertex _u, Vertex _v): u(_u), v(_v) {} 4 5 float Segment::length() { 6 return (u-v).norm(); 7 } 8 9 Segment Segment::reduce(float value) { 10 float reduc = (float)length()/(float)value; 11 return Segment(u,u+((v - u) / reduc)); 12 } 13 14 Vertex Segment::at(float proportiannalDist) { 15 return Segment(u,u+((v-u)*proportiannalDist)).v; 16 } 17 18 Vertex Segment::center() { 19 return at(1./2.); 20 } 21 22 float Segment::width() { 23 return std::abs(u.x - v.x); 24 } 25 26 float Segment::height() { 27 return std::abs(u.y - v.y); 28 } 29 30 Vertex Segment::randomPos(int seed, int n, float a, float b) { 31 float pos = floatInRange(seed, n, a, b); 32 return (u * pos + v * (1-pos)); 33 } 34 35 Segment operator+(const Segment& s, const Vertex& voff) { 36 return Segment(s.u + voff, s.v + voff); 37 }