26 lines
524 B
C++
26 lines
524 B
C++
#include "all_includes.hh"
|
|
|
|
Segment::Segment(Vertex _u, Vertex _v): u(_u), v(_v) {}
|
|
|
|
float Segment::length() {
|
|
return (u-v).norm();
|
|
}
|
|
|
|
Segment Segment::reduce(float value) {
|
|
float reduc = (float)length()/(float)value;
|
|
return Segment(u,u+((v - u) / reduc));
|
|
}
|
|
|
|
float Segment::width() {
|
|
return std::abs(u.x - v.x);
|
|
}
|
|
|
|
float Segment::height() {
|
|
return std::abs(u.y - v.y);
|
|
}
|
|
|
|
Vertex Segment::randomPos(int seed, int n, float a, float b) {
|
|
float pos = floatInRange(seed, n, a, b);
|
|
return (u * pos + v * (1-pos));
|
|
}
|