12 #ifndef AW_POSITION_HXX
13 #define AW_POSITION_HXX
24 #ifndef _GLIBCXX_CMATH
29 #define aw_assert(bed) arb_assert(bed)
37 #define ISVALID(a) aw_assert((a).valid())
39 inline const double&
NONAN(
const double& d) {
77 inline double centroid(
const double& val1,
const double& val2) {
return (val1+val2)*0.5; }
99 inline bool is_between(
const double& coord1,
const double& between,
const double& coord2) {
100 return ((coord1-between)*(between-coord2)) >= 0.0;
118 const double&
xpos()
const {
return x; }
119 const double&
ypos()
const {
return y; }
135 extern const Position
Origin;
154 Vector(
const double& X,
const double& Y) : end(X, Y), len(-1) {
ISVALID(*
this); }
155 Vector(
const double& X,
const double& Y,
const double& Length) : end(X, Y), len(Length) {
ISVALID(*
this); }
160 const double&
x()
const {
return end.
xpos(); }
161 const double&
y()
const {
return end.
ypos(); }
164 Vector&
set(
const double& X,
const double& Y,
double Length = -1) { end =
Position(X, Y); len = Length;
return *
this; }
169 if (len<0.0) len = hypot(
x(),
y());
189 double factor = new_length/
length();
190 return (*
this *= factor);
255 double tlen = target.
length();
256 return target * (
scalarProduct(projectee, target) / (tlen*tlen));
287 LineVector(
double X1,
double Y1,
double X2,
double Y2) : Start(X1, Y1), ToEnd(X2-X1, Y2-Y1) {
ISVALID(*
this); }
312 const double&
xpos()
const {
return Start.
xpos(); }
313 const double&
ypos()
const {
return Start.
ypos(); }
321 Position
crosspoint(
const LineVector& l1,
const LineVector& l2,
double& factor_l1,
double& factor_l2);
454 mutable double Radian;
457 void recalcRadian()
const;
458 void recalcNormal()
const;
466 explicit Angle(
double Radian_) : Radian(Radian_) { recalcNormal();
ISVALID(*
this); }
479 while (Radian<0.0) Radian += 2*
M_PI;
480 while (Radian >= 2*
M_PI) Radian -= 2*
M_PI;
487 const double&
sin()
const {
return Normal.
y(); }
488 const double&
cos()
const {
return Normal.
x(); }
549 inline double hypotenuse(
double cath1,
double cath2) {
return hypot(cath1, cath2); }
552 return sqrt(hypotenuse*hypotenuse - cathetus*cathetus);
559 inline bool are_equal(
const double& d1,
const double& d2) {
561 return diff < 0.000001;
564 inline bool are_orthographic(
const Vector& v1,
const Vector& v2) {
571 return p.
xpos() == 0 && p.
ypos() == 0;
575 inline void aw_dump(
const double& p,
const char *varname) {
576 fprintf(stderr,
"%s=%f", varname, p);
578 inline void aw_dump(
const Position& p,
const char *varname) {
579 fprintf(stderr,
"Position %s={ ", varname);
580 aw_dump(p.xpos(),
"x");
fputs(
", ", stderr);
581 aw_dump(p.ypos(),
"y");
fputs(
" }", stderr);
583 inline void aw_dump(
const Vector& v,
const char *varname) {
584 fprintf(stderr,
"Vector %s={ ", varname);
585 aw_dump(v.x(),
"x");
fputs(
", ", stderr);
586 aw_dump(v.y(),
"y");
fputs(
" }", stderr);
588 inline void aw_dump(
const Angle& a,
const char *varname) {
589 fprintf(stderr,
"Angle %s={ ", varname);
590 aw_dump(a.degrees(),
"degrees()");
fputs(
" }", stderr);
592 inline void aw_dump(
const LineVector& v,
const char *varname) {
593 fprintf(stderr,
"LineVector %s={ ", varname);
594 aw_dump(v.start(),
"start");
fputs(
", ", stderr);
595 aw_dump(v.line_vector(),
"line_vector");
fputs(
" }", stderr);
598 inline void aw_dump(
const Rectangle& r,
const char *varname) {
599 fprintf(stderr,
"Rectangle %s={ ", varname);
600 aw_dump(r.upper_left_corner(),
"upper_left_corner");
fputs(
", ", stderr);
601 aw_dump(r.lower_right_corner(),
"lower_right_corner");
fputs(
" }", stderr);
604 #define AW_DUMP(x) do { aw_dump(x, #x); fputc('\n', stderr); } while(0)
609 return x_pos - x_size*alignment;
614 #error aw_position.hxx included twice
615 #endif // AW_POSITION_HXX
Position nearest_corner(const Position &topos) const
Position get_corner(int i) const
bool are_antiparallel(const Vector &v1, const Vector &v2)
returns true, if two vectors have opposite orientations
Vector & operator/=(const double &divisor)
LineVector(double X1, double Y1, double X2, double Y2)
double centroid(const double &val1, const double &val2)
LineVector smaller_extent() const
void move(const Vector &movement)
Position centroid() const
LineVector lower_edge() const
bool nearlyEqual(const double &val1, const double &val2)
const double & radian() const
Vector & set(const double &X, const double &Y, double Length=-1)
Vector & operator-=(const Vector &other)
LineVector bigger_extent() const
Rectangle bounding_box(const Position &pos) const
Rectangle bounding_box(const Rectangle &r1, const Rectangle &r2)
Vector operator*(const Vector &v, const double &f)
Angle(const Position &p1, const Position &p2)
Position nearest_linepoint(const Position &pos, const LineVector &line, double &factor)
LineVector horizontal_extent() const
bool contains(const LineVector &lvec) const
bool distinct_from(const Rectangle &rect) const
Angle & operator*=(const double &fact)
Vector(const double &X, const double &Y, const double &Length)
Rectangle(const Position &corner, const Position &opposite_corner)
Rectangle(double X1, double Y1, double X2, double Y2)
bool nearlyZero(const double &val)
Vector & sety(const double &Y)
const double & cos() const
const Vector & normal() const
Vector & operator*=(const double &factor)
LineVector left_edge() const
Vector & set_length(double new_length)
Rectangle(const AW_screen_area &r, AW_screen_area_conversion_mode mode)
void sety(const double &Y)
void moveTo(const Position &pos)
bool isOrigin(const Position &p)
const Position & start() const
static int diff(int v1, int v2, int v3, int v4, int st, int en)
Vector & setx(const double &X)
static const double deg2rad
bool are_parallel(const Vector &v1, const Vector &v2)
const double & sin() const
Angle & operator-=(const Angle &o)
Angle & operator+=(const Angle &o)
const double & ypos() const
Angle & operator=(const Angle &other)
Rectangle intersect_with(const Rectangle &rect) const
Vector(const double &X, const double &Y)
LineVector reverse() const
double hypotenuse(double cath1, double cath2)
LineVector vertical_extent() const
Position lower_left_corner() const
bool are_distinct(const Position &p1, const Position &p2)
LineVector(const Position &startpos, const Vector &to_end)
Angle(double x, double y)
Position crosspoint(const LineVector &l1, const LineVector &l2, double &factor_l1, double &factor_l2)
const Position & endpoint() const
Vector operator-(const Position &to, const Position &from)
const Position & upper_left_corner() const
Position & operator+=(const Vector &v)
void movey(const double &Y)
Position(double X, double Y)
void moveTo(const Position &pos)
Vector normalized(const Vector &v)
bool is_vertical(const Vector &v)
double cathetus(double hypotenuse, double cathetus)
void setx(const double &X)
Position operator+(const Position &p, const Vector &v)
LineVector(const AW_screen_area &r, AW_screen_area_conversion_mode mode)
Rectangle(const Position &corner, const Vector &to_opposite_corner)
LineVector(const AW_world &r)
const double & ypos() const
bool is_between(const double &coord1, const double &between, const double &coord2)
void movex(const double &X)
Vector orthogonal_projection(const Vector &projectee, const Vector &target)
Vector & operator+=(const Vector &other)
double scalarProduct(const Vector &v1, const Vector &v2)
const Vector & diagonal() const
Rectangle bounding_box(const Rectangle &rect) const
Vector operator/(const Vector &v, const double &d)
Vector(const Position &from, const Position &to)
const Vector & line_vector() const
static const double rad2deg
fputs(TRACE_PREFIX, stderr)
Rectangle(const AW_world &r)
const double & length() const
bool contains(const Position &pos) const
LineVector upper_edge() const
bool is_between(const Position &p1, const Position &p2) const
bool overlaps_with(const Rectangle &rect) const
Position upper_right_corner() const
bool is_normalized() const
Angle(const Vector &n, double r)
double Distance(const Position &from, const Position &to)
AW_screen_area_conversion_mode
const double & xpos() const
Rectangle(const LineVector &Diagonal)
CONSTEXPR_INLINE bool definesQuadrant(const RoughDirection rd)
Angle(const LineVector &lv)
Position lower_right_corner() const
Position & operator-=(const Vector &v)
LineVector(const Position &startpos, const Position &end)
LineVector right_edge() const
Vector(const Position &to)
bool is_horizontal(const Vector &v)
AW_pos x_alignment(AW_pos x_pos, AW_pos x_size, AW_pos alignment)
void move(const Vector &movement)
const double & xpos() const