/home/martin/workspace/OpenStreetNav/src/displayer/DisplayLine.cpp
Go to the documentation of this file.
00001 /*
00002  * DisplayLine.cpp
00003  *
00004  *  Created on: Dec 29, 2011
00005  *      Author: martin
00006  */
00007 
00008 #include "DisplayLine.h"
00009 
00010 namespace display
00011 {
00012 
00013 DisplayLine::DisplayLine(geo::Point p1, geo::Point p2, bool arrow, std::unique_ptr<DisplayStyle> && style):
00014     DisplayElement(std::move(style)),
00015     p1(p1),
00016     p2(p2),
00017     arrow(arrow)
00018 {
00019 }
00020 
00021 DisplayLine::~DisplayLine()
00022 {
00023 }
00024 
00025 DisplayElementType DisplayLine::get_type() const
00026 {
00027     return DisplayElementType::Line;
00028 }
00029 
00030 bool DisplayLine::operator <(const DisplayElement& other) const
00031 {
00032     if (other.get_type() != DisplayElementType::Line)
00033         return DisplayElementType::Line < other.get_type();
00034     DisplayLine const& ln = static_cast<DisplayLine const&>(other);
00035     return std::pair<geo::Point, geo::Point>(p1, p2) < std::pair<geo::Point, geo::Point>(ln.p1, ln.p2);
00036 }
00037 
00038 bool DisplayLine::operator >(const DisplayElement& other) const
00039 {
00040     return !(*this == other) && !(*this < other);
00041 }
00042 
00043 bool DisplayLine::operator <=(const DisplayElement& other) const
00044 {
00045     return *this == other || *this < other;
00046 }
00047 
00048 bool DisplayLine::operator >=(const DisplayElement& other) const
00049 {
00050     return !(*this < other);
00051 }
00052 
00053 bool DisplayLine::operator ==(const DisplayElement& other) const
00054 {
00055     if (other.get_type() != DisplayElementType::Line)
00056         return false;
00057     DisplayLine const& ln = static_cast<DisplayLine const&>(other);
00058     return std::pair<geo::Point, geo::Point>(p1, p2) == std::pair<geo::Point, geo::Point>(ln.p1, ln.p2);
00059 }
00060 
00061 bool DisplayLine::operator !=(const DisplayElement& other) const
00062 {
00063     return !(*this == other);
00064 }
00065 
00066 void DisplayLine::draw_internal(Cairo::RefPtr<Cairo::Context> cr, proj::MapProjection& pr) const
00067 {
00068     auto pp1 = pr.project(p1);
00069     auto pp2 = pr.project(p2);
00070     if (arrow)
00071     {
00072         double l = sqrt((pp2.x - pp1.x) * (pp2.x - pp1.x) + (pp2.y - pp1.y) * (pp2.y - pp1.y));
00073         double norm_x = (pp2.x - pp1.x) / (l * 100);
00074         double norm_y = (pp2.y - pp1.y) / (l * 100);
00075         proj::FlatPoint ppc((pp1.x + pp2.x) / 2.0, (pp1.y + pp2.y) / 2.0);
00076         cr->move_to(pp1.x, pp1.y);
00077         cr->line_to(ppc.x, ppc.y);
00078         cr->line_to(ppc.x - norm_x - norm_y, ppc.y - norm_y + norm_x);
00079         cr->move_to(ppc.x - norm_x + norm_y, ppc.y - norm_y - norm_x);
00080         cr->line_to(ppc.x, ppc.y);
00081         cr->line_to(pp2.x, pp2.y);
00082     }
00083     else
00084     {
00085         cr->move_to(pp1.x, pp1.y);
00086         cr->line_to(pp2.x, pp2.y);
00087     }
00088 }
00089 
00090 /* namespace display */
00091 }
00092 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines