From: Mikko Rasa Date: Tue, 8 Mar 2011 11:31:05 +0000 (+0000) Subject: Rename Point to Vector X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f8a7788cee0261babfc4c804a58515aad6dfbc3d;p=r2c2.git Rename Point to Vector --- diff --git a/source/3d/axle.cpp b/source/3d/axle.cpp index 5123106..2da94b9 100644 --- a/source/3d/axle.cpp +++ b/source/3d/axle.cpp @@ -41,7 +41,7 @@ void Axle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const { GL::Matrix matrix; - const Point &pos = vehicle.get_position(); + const Vector &pos = vehicle.get_position(); matrix.translate(pos.x, pos.y, pos.z); matrix.rotate(vehicle.get_direction(), 0, 0, 1); diff --git a/source/3d/bogie.cpp b/source/3d/bogie.cpp index 234bd88..03f7dce 100644 --- a/source/3d/bogie.cpp +++ b/source/3d/bogie.cpp @@ -33,7 +33,7 @@ void Bogie3D::setup_render(Msp::GL::Renderer &renderer, const GL::Tag &) const { GL::Matrix matrix; - const Point &pos = vehicle.get_position(); + const Vector &pos = vehicle.get_position(); matrix.translate(pos.x, pos.y, pos.z); matrix.rotate(vehicle.get_direction(), 0, 0, 1); diff --git a/source/3d/catalogue.cpp b/source/3d/catalogue.cpp index 6cb7558..3f3aa6c 100644 --- a/source/3d/catalogue.cpp +++ b/source/3d/catalogue.cpp @@ -78,12 +78,12 @@ void Catalogue3D::vehicle_added(const VehicleType &veh) void Catalogue3D::build_endpoint_mesh() { const Profile &ballast_profile = catalogue.get_ballast_profile(); - const Point &ballast_min = ballast_profile.get_min_coords(); - const Point &ballast_max = ballast_profile.get_max_coords(); + const Vector &ballast_min = ballast_profile.get_min_coords(); + const Vector &ballast_max = ballast_profile.get_max_coords(); const Profile &rail_profile = catalogue.get_rail_profile(); - const Point &rail_min = rail_profile.get_min_coords(); - const Point &rail_max = rail_profile.get_max_coords(); + const Vector &rail_min = rail_profile.get_min_coords(); + const Vector &rail_max = rail_profile.get_max_coords(); float gauge = catalogue.get_gauge(); diff --git a/source/3d/endpoint.cpp b/source/3d/endpoint.cpp index 23bd20f..5b7f810 100644 --- a/source/3d/endpoint.cpp +++ b/source/3d/endpoint.cpp @@ -34,7 +34,7 @@ void Endpoint3D::render(GL::Renderer &renderer, const GL::Tag &tag) const { if(tag=="unlit") { - Point p = track.get_track().get_endpoint_position(index); + Vector p = track.get_track().get_endpoint_position(index); float a = track.get_track().get_endpoint_direction(index)+M_PI; GL::MatrixStack::Push push_mtx(renderer.matrix_stack()); diff --git a/source/3d/object.h b/source/3d/object.h index a9ac715..3da0cf3 100644 --- a/source/3d/object.h +++ b/source/3d/object.h @@ -19,7 +19,7 @@ protected: public: virtual ~Object3D() { } - virtual Point get_node() const = 0; + virtual Vector get_node() const = 0; virtual bool is_visible() const = 0; }; diff --git a/source/3d/overlay.cpp b/source/3d/overlay.cpp index 5b251b6..ed413cd 100644 --- a/source/3d/overlay.cpp +++ b/source/3d/overlay.cpp @@ -104,7 +104,7 @@ void Overlay3D::render(const GL::Tag &tag) const const Icon &icon = *i->second; - Point node = i->first->get_node(); + Vector node = i->first->get_node(); GL::Vector3 p = camera.project(GL::Vector3(node.x, node.y, node.z)); GL::PushMatrix push_mat; diff --git a/source/3d/rod.cpp b/source/3d/rod.cpp index 26d000d..86a6a9c 100644 --- a/source/3d/rod.cpp +++ b/source/3d/rod.cpp @@ -32,7 +32,7 @@ void Rod3D::render(GL::Renderer &renderer, const GL::Tag &tag) const void Rod3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const { GL::Matrix matrix; - const Point &pos = vehicle.get_position(); + const Vector &pos = vehicle.get_position(); matrix.translate(pos.x, pos.y, pos.z); matrix.rotate(vehicle.get_direction(), 0, 0, 1); diff --git a/source/3d/track.cpp b/source/3d/track.cpp index 5d31a4d..8b36b19 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -55,14 +55,14 @@ Track3D::~Track3D() delete *i; } -void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const +void Track3D::get_bounds(float angle, Vector &minp, Vector &maxp) const { type.get_bounds(angle-track.get_rotation(), minp, maxp); float c = cos(-angle); float s = sin(-angle); - const Point &pos = track.get_position(); + const Vector &pos = track.get_position(); minp.x += c*pos.x-s*pos.y; maxp.x += c*pos.x-s*pos.y; minp.y += s*pos.x+c*pos.y; @@ -77,23 +77,23 @@ void Track3D::get_bounds(float angle, Point &minp, Point &maxp) const minp.z += slope; } -Point Track3D::get_node() const +Vector Track3D::get_node() const { - const Point &pos = track.get_position(); - Point minp; - Point maxp; + const Vector &pos = track.get_position(); + Vector minp; + Vector maxp; type.get_bounds(0, minp, maxp); float rot = track.get_rotation(); float c = cos(rot); float s = sin(rot); - Point center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0); - return Point(pos.x+c*center.x-s*center.y, pos.y+s*center.x+c*center.y, pos.z+0.02); + Vector center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0); + return Vector(pos.x+c*center.x-s*center.y, pos.y+s*center.x+c*center.y, pos.z+0.02); } GL::Matrix Track3D::get_matrix() const { - const Point &pos = track.get_position(); + const Vector &pos = track.get_position(); float rot = track.get_rotation(); GL::Matrix matrix; diff --git a/source/3d/track.h b/source/3d/track.h index 9555bff..d0a90f4 100644 --- a/source/3d/track.h +++ b/source/3d/track.h @@ -39,10 +39,10 @@ public: Layout3D &get_layout() const { return layout; } Track &get_track() const { return track; } const TrackType3D &get_type() const { return type; } - void get_bounds(float, Point &, Point &) const; + void get_bounds(float, Vector &, Vector &) const; Path3D &get_path() { return *path; } - virtual Point get_node() const; + virtual Vector get_node() const; virtual bool is_visible() const { return true; } Msp::GL::Matrix get_matrix() const; diff --git a/source/3d/tracktype.cpp b/source/3d/tracktype.cpp index 8a62175..47c85ab 100644 --- a/source/3d/tracktype.cpp +++ b/source/3d/tracktype.cpp @@ -16,7 +16,7 @@ using namespace Msp; namespace { -bool compare_z(const R2C2::Point &p1, const R2C2::Point &p2) +bool compare_z(const R2C2::Vector &p1, const R2C2::Vector &p2) { return p1.zxx==lowest.x && i->y>lowest.y)) lowest = *i; @@ -80,13 +80,13 @@ TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt): const vector &parts = tt.get_parts(); const Profile &ballast_profile = cat.get_ballast_profile(); - const Point &ballast_min = ballast_profile.get_min_coords(); - const Point &ballast_max = ballast_profile.get_max_coords(); + const Vector &ballast_min = ballast_profile.get_min_coords(); + const Vector &ballast_max = ballast_profile.get_max_coords(); float ballast_h = ballast_max.y-ballast_min.y; const Profile &rail_profile = cat.get_rail_profile(); - const Point &rail_min = rail_profile.get_min_coords(); - const Point &rail_max = rail_profile.get_max_coords(); + const Vector &rail_min = rail_profile.get_min_coords(); + const Vector &rail_max = rail_profile.get_max_coords(); float rail_h = rail_max.y-rail_min.y; float gauge = cat.get_gauge(); @@ -106,14 +106,14 @@ TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt): unsigned index = 0; bld.texcoord(0.25, 0.5); for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) - build_part(*i, ballast_profile, Point(0, -ballast_min.y), false, bld, index); + build_part(*i, ballast_profile, Vector(0, -ballast_min.y), false, bld, index); bld.texcoord(0.75, 0.5); float y = ballast_h-rail_min.y; for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) - build_part(*i, rail_profile, Point(-gauge/2, y), true, bld, index); + build_part(*i, rail_profile, Vector(-gauge/2, y), true, bld, index); for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) - build_part(*i, rail_profile, Point(gauge/2, y), false, bld, index); + build_part(*i, rail_profile, Vector(gauge/2, y), false, bld, index); object = new GL::Object; object->set_mesh(mesh); @@ -131,13 +131,13 @@ TrackType3D::TrackType3D(Catalogue3D &cat3d, const TrackType &tt): unsigned index = 0; for(vector::const_iterator j=parts.begin(); j!=parts.end(); ++j) if(j->get_path()==i) - build_part(*j, cat.get_path_profile(), Point(0, ballast_h+1.5*rail_h), false, bld, index); + build_part(*j, cat.get_path_profile(), Vector(0, ballast_h+1.5*rail_h), false, bld, index); } path_meshes.push_back(m); } min_z = max_z = border.front().z; - for(vector::iterator i=border.begin(); i!=border.end(); ++i) + for(vector::iterator i=border.begin(); i!=border.end(); ++i) { min_z = min(min_z, i->z); max_z = max(max_z, i->z); @@ -151,16 +151,16 @@ TrackType3D::~TrackType3D() delete *i; } -void TrackType3D::get_bounds(float angle, Point &minp, Point &maxp) const +void TrackType3D::get_bounds(float angle, Vector &minp, Vector &maxp) const { float c = cos(-angle); float s = sin(-angle); - minp = maxp = Point(); + minp = maxp = Vector(); minp.z = min_z; maxp.z = max_z; - for(vector::const_iterator i=border.begin(); i!=border.end(); ++i) + for(vector::const_iterator i=border.begin(); i!=border.end(); ++i) { float x = c*i->x-s*i->y; float y = s*i->x+c*i->y; @@ -179,7 +179,7 @@ const GL::Mesh &TrackType3D::get_path_mesh(unsigned p) const return *path_meshes[p]; } -void TrackType3D::build_part(const TrackPart &part, const Profile &profile, const Point &offset, bool mirror, GL::MeshBuilder &bld, unsigned &base_index) +void TrackType3D::build_part(const TrackPart &part, const Profile &profile, const Vector &offset, bool mirror, GL::MeshBuilder &bld, unsigned &base_index) { float plen = part.get_length(); unsigned nsegs = (part.is_curved() ? static_cast(plen*32)+1 : 1); @@ -194,14 +194,14 @@ void TrackType3D::build_part(const TrackPart &part, const Profile &profile, cons for(unsigned j=0; j path_meshes; - std::vector border; + std::vector border; float min_z; float max_z; @@ -33,12 +33,12 @@ public: TrackType3D(Catalogue3D &, const TrackType &); ~TrackType3D(); - void get_bounds(float, Point &, Point &) const; + void get_bounds(float, Vector &, Vector &) const; const Msp::GL::Object &get_object() const { return *object; } const Msp::GL::Mesh &get_path_mesh(unsigned) const; private: - void build_part(const TrackPart &, const Profile &, const Point &, bool, Msp::GL::MeshBuilder &, unsigned &); + void build_part(const TrackPart &, const Profile &, const Vector &, bool, Msp::GL::MeshBuilder &, unsigned &); }; } // namespace R2C2 diff --git a/source/3d/vehicle.cpp b/source/3d/vehicle.cpp index 78899fd..42ac924 100644 --- a/source/3d/vehicle.cpp +++ b/source/3d/vehicle.cpp @@ -78,10 +78,10 @@ Vehicle3D::~Vehicle3D() delete *i; } -Point Vehicle3D::get_node() const +Vector Vehicle3D::get_node() const { - Point p = vehicle.get_position(); - return Point(p.x, p.y, p.z+0.01+vehicle.get_type().get_height()); + Vector p = vehicle.get_position(); + return Vector(p.x, p.y, p.z+0.01+vehicle.get_type().get_height()); } bool Vehicle3D::is_visible() const @@ -100,7 +100,7 @@ void Vehicle3D::render(GL::Renderer &renderer, const GL::Tag &tag) const void Vehicle3D::setup_render(GL::Renderer &renderer, const GL::Tag &) const { GL::Matrix matrix; - const Point &pos = vehicle.get_position(); + const Vector &pos = vehicle.get_position(); matrix.translate(pos.x, pos.y, pos.z); matrix.rotate(vehicle.get_direction(), 0, 0, 1); renderer.matrix_stack() *= matrix; diff --git a/source/3d/vehicle.h b/source/3d/vehicle.h index 84b10be..36853c9 100644 --- a/source/3d/vehicle.h +++ b/source/3d/vehicle.h @@ -37,7 +37,7 @@ public: Vehicle &get_vehicle() const { return vehicle; } const VehicleType3D &get_type() const { return type; } - virtual Point get_node() const; + virtual Vector get_node() const; virtual bool is_visible() const; virtual void render(Msp::GL::Renderer &, const Msp::GL::Tag &) const; diff --git a/source/designer/cameracontroller.cpp b/source/designer/cameracontroller.cpp index 6b98f3d..9770320 100644 --- a/source/designer/cameracontroller.cpp +++ b/source/designer/cameracontroller.cpp @@ -46,14 +46,14 @@ void CameraController::set_look_direction(const GL::Vector3 &look) void CameraController::view_all() { - Point minp; - Point maxp; + Vector minp; + Vector maxp; const Layout3D::TrackMap &tracks = designer.get_layout_3d().get_tracks(); for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { - Point tmin; - Point tmax; + Vector tmin; + Vector tmax; i->second->get_bounds(0, tmin, tmax); minp.x = min(minp.x, tmin.x); minp.y = min(minp.y, tmin.y); diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index 2002bd9..3b43efd 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -335,14 +335,14 @@ void Designer::add_selection_to_zone() show_zone(*cur_zone); } -Point Designer::map_pointer_to_ground(int x, int y) +Vector Designer::map_pointer_to_ground(int x, int y) { float xf = x*2.0/window.get_width()-1.0; float yf = y*2.0/window.get_height()-1.0; GL::Vector4 vec = camera.unproject(GL::Vector4(xf, yf, 0, 0)); const GL::Vector3 &pos = camera.get_position(); - return Point(pos.x-vec.x*pos.z/vec.z, pos.y-vec.y*pos.z/vec.z); + return Vector(pos.x-vec.x*pos.z/vec.z, pos.y-vec.y*pos.z/vec.z); } void Designer::tick() @@ -462,7 +462,7 @@ void Designer::button_press(int x, int y, unsigned btn, unsigned mod) y = window.get_height()-y-1; mod = Input::mod_from_sys(mod); - Point ground = map_pointer_to_ground(x, y); + Vector ground = map_pointer_to_ground(x, y); if(mode==CATALOGUE) { @@ -506,7 +506,7 @@ void Designer::pointer_motion(int x, int y) if(!root.get_child_at(x, y)) { - Point ground = map_pointer_to_ground(x, y); + Vector ground = map_pointer_to_ground(x, y); measure.pointer_motion(x, y, ground.x, ground.y); } } diff --git a/source/designer/designer.h b/source/designer/designer.h index 52904e4..da6cb0e 100644 --- a/source/designer/designer.h +++ b/source/designer/designer.h @@ -112,7 +112,7 @@ public: R2C2::Zone *get_current_zone() const { return cur_zone; } void add_selection_to_zone(); - R2C2::Point map_pointer_to_ground(int, int); + R2C2::Vector map_pointer_to_ground(int, int); private: void tick(); void key_press(unsigned, unsigned, wchar_t); diff --git a/source/designer/manipulator.cpp b/source/designer/manipulator.cpp index b41b29e..359fbbb 100644 --- a/source/designer/manipulator.cpp +++ b/source/designer/manipulator.cpp @@ -119,8 +119,8 @@ void Manipulator::flatten() for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - Point p = i->track->get_position(); - i->track->set_position(Point(p.x, p.y, z)); + Vector p = i->track->get_position(); + i->track->set_position(Vector(p.x, p.y, z)); i->track->set_slope(0); } @@ -228,7 +228,7 @@ void Manipulator::connect() float limit = designer.get_layout().get_catalogue().get_gauge()/10; Track *track1 = tracks.front().track; - Point pos1; + Vector pos1; float dir1; Track *track2 = tracks.back().track; bool ok = false; @@ -246,7 +246,7 @@ void Manipulator::connect() if(track2->get_link(j)) continue; - Point pos2 = track2->get_endpoint_position(j); + Vector pos2 = track2->get_endpoint_position(j); float dir2 = track2->get_endpoint_direction(j); float dz = pos2.z-pos1.z; @@ -307,7 +307,7 @@ void Manipulator::cancel() for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - i->track->set_position(Point(center.x+i->pos.x, center.y+i->pos.y, center.z+i->pos.z)); + i->track->set_position(Vector(center.x+i->pos.x, center.y+i->pos.y, center.z+i->pos.z)); i->track->set_rotation(i->rot); } @@ -377,11 +377,11 @@ void Manipulator::pointer_motion(int x, int y) if(mode==MOVE) { - Point delta(gpointer.x-move_origin.x, gpointer.y-move_origin.y, 0); - Point offset(center.x+delta.x, center.y+delta.y, center.z); + Vector delta(gpointer.x-move_origin.x, gpointer.y-move_origin.y, 0); + Vector offset(center.x+delta.x, center.y+delta.y, center.z); for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - i->track->set_position(Point(offset.x+i->pos.x, offset.y+i->pos.y, offset.z+i->pos.z)); + i->track->set_position(Vector(offset.x+i->pos.x, offset.y+i->pos.y, offset.z+i->pos.z)); i->track->set_rotation(i->rot); } @@ -406,14 +406,14 @@ void Manipulator::pointer_motion(int x, int y) float da = snapped->track->get_rotation()-snapped->rot; float c = cos(da); float s = sin(da); - const Point &sp = snapped->track->get_position(); + const Vector &sp = snapped->track->get_position(); for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { if(&*i==snapped) continue; - Point dp(i->pos.x-snapped->pos.x, i->pos.y-snapped->pos.y, 0); - i->track->set_position(Point(sp.x+c*dp.x-s*dp.y, sp.y+s*dp.x+c*dp.y, sp.z+i->pos.z-snapped->pos.z)); + Vector dp(i->pos.x-snapped->pos.x, i->pos.y-snapped->pos.y, 0); + i->track->set_position(Vector(sp.x+c*dp.x-s*dp.y, sp.y+s*dp.x+c*dp.y, sp.z+i->pos.z-snapped->pos.z)); i->track->set_rotation(i->rot+da); } } @@ -428,7 +428,7 @@ void Manipulator::pointer_motion(int x, int y) { float c = cos(angle); float s = sin(angle); - i->track->set_position(Point(center.x+c*i->pos.x-s*i->pos.y, center.y+s*i->pos.x+c*i->pos.y, center.z+i->pos.z)); + i->track->set_position(Vector(center.x+c*i->pos.x-s*i->pos.y, center.y+s*i->pos.x+c*i->pos.y, center.z+i->pos.z)); i->track->set_rotation(angle+i->rot); } } @@ -439,14 +439,14 @@ void Manipulator::pointer_motion(int x, int y) signal_status.emit(format("Elevation: %+.0fmm (%.0fmm)", dz*1000, (center.z+dz)*1000)); for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) - i->track->set_position(Point(center.x+i->pos.x, center.y+i->pos.y, center.z+i->pos.z+dz)); + i->track->set_position(Vector(center.x+i->pos.x, center.y+i->pos.y, center.z+i->pos.z+dz)); for(set::iterator i=neighbors.begin(); i!=neighbors.end(); ++i) (*i)->check_slope(); } else if(mode==EXTEND) { - Point pos; + Vector pos; float dir = 0; float length = 0; for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) @@ -457,7 +457,7 @@ void Manipulator::pointer_motion(int x, int y) if(i->track->get_link(j)) continue; - Point ep_pos = i->track->get_endpoint_position(j); + Vector ep_pos = i->track->get_endpoint_position(j); float ep_dir = i->track->get_endpoint_direction(j); float c = cos(ep_dir); float s = sin(ep_dir); @@ -509,13 +509,13 @@ void Manipulator::selection_changed() void Manipulator::update_tracks() { - Point minp, maxp; + Vector minp, maxp; for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { unsigned n_endpoints = i->track->get_type().get_endpoints().size(); for(unsigned j=0; jtrack->get_endpoint_position(j); + Vector p = i->track->get_endpoint_position(j); if(i==tracks.begin() && j==0) minp = maxp = p; else @@ -529,11 +529,11 @@ void Manipulator::update_tracks() } } - center = Point((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, minp.z); + center = Vector((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, minp.z); for(vector::iterator i=tracks.begin(); i!=tracks.end(); ++i) { - const Point &tp = i->track->get_position(); - i->pos = Point(tp.x-center.x, tp.y-center.y, tp.z-center.z); + const Vector &tp = i->track->get_position(); + i->pos = Vector(tp.x-center.x, tp.y-center.y, tp.z-center.z); i->rot = i->track->get_rotation(); } } @@ -563,20 +563,20 @@ void Manipulator::update_neighbors() void Manipulator::set_slope(TrackOrder &track, float z, float dz) { - const Point &p = track.track->get_position(); + const Vector &p = track.track->get_position(); if(track.rev) { - track.track->set_position(Point(p.x, p.y, z+dz)); + track.track->set_position(Vector(p.x, p.y, z+dz)); track.track->set_slope(-dz); } else { - track.track->set_position(Point(p.x, p.y, z)); + track.track->set_position(Vector(p.x, p.y, z)); track.track->set_slope(dz); } } -vector Manipulator::create_straight(const R2C2::Point &start, float dir, float length, float limit) +vector Manipulator::create_straight(const R2C2::Vector &start, float dir, float length, float limit) { const Catalogue::TrackMap &track_types = designer.get_catalogue().get_tracks(); std::map types_by_length; @@ -636,7 +636,7 @@ vector Manipulator::create_straight(const R2C2::Point &start, float dir if(!lengths.empty()) { - Point pos = start; + Vector pos = start; float c = cos(dir); float s = sin(dir); for(vector::iterator i=lengths.begin(); i!=lengths.end(); ++i) diff --git a/source/designer/manipulator.h b/source/designer/manipulator.h index 75fafe5..d8c3986 100644 --- a/source/designer/manipulator.h +++ b/source/designer/manipulator.h @@ -28,7 +28,7 @@ private: struct MTrack { R2C2::Track *track; - R2C2::Point pos; + R2C2::Vector pos; float rot; MTrack(R2C2::Track *); @@ -51,12 +51,12 @@ private: Msp::Graphics::EventSource &event_source; Selection &selection; std::vector tracks; - R2C2::Point center; + R2C2::Vector center; - R2C2::Point gpointer; + R2C2::Vector gpointer; int pointer_y; Mode mode; - R2C2::Point move_origin; + R2C2::Vector move_origin; float angle; float rot_origin; int elev_origin; @@ -82,7 +82,7 @@ private: void update_tracks(); void update_neighbors(); void set_slope(TrackOrder &, float, float); - std::vector create_straight(const R2C2::Point &, float, float, float); + std::vector create_straight(const R2C2::Vector &, float, float, float); }; #endif diff --git a/source/designer/measure.cpp b/source/designer/measure.cpp index 56efc1b..e5e5abb 100644 --- a/source/designer/measure.cpp +++ b/source/designer/measure.cpp @@ -25,7 +25,7 @@ void Measure::start() state = STARTING; } -void Measure::snap_to_tracks(Point &pt, float &dir) +void Measure::snap_to_tracks(Vector &pt, float &dir) { const set <racks = designer.get_layout().get_tracks(); for(set::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i) @@ -40,7 +40,7 @@ void Measure::button_press(int, int, float gx, float gy, unsigned btn) if(btn==1) { - spoint = Point(gx, gy, 0); + spoint = Vector(gx, gy, 0); sdir = 0; snap_to_tracks(spoint, sdir); @@ -63,13 +63,13 @@ void Measure::pointer_motion(int, int, float gx, float gy) if(!state) return; - pointer = Point(gx, gy, 0); + pointer = Vector(gx, gy, 0); float dir = sdir; snap_to_tracks(pointer, dir); if(state!=STARTING) { - Point delta(pointer.x-spoint.x, pointer.y-spoint.y, 0); + Vector delta(pointer.x-spoint.x, pointer.y-spoint.y, 0); float c = cos(sdir); float s = sin(sdir); diff --git a/source/designer/measure.h b/source/designer/measure.h index 6800ecc..fc675a6 100644 --- a/source/designer/measure.h +++ b/source/designer/measure.h @@ -28,8 +28,8 @@ public: private: Designer &designer; - R2C2::Point pointer; - R2C2::Point spoint; + R2C2::Vector pointer; + R2C2::Vector spoint; float sdir; float par_dist; float perp_dist; @@ -46,7 +46,7 @@ public: void pointer_motion(int, int, float, float); void render(); private: - void snap_to_tracks(R2C2::Point &, float &); + void snap_to_tracks(R2C2::Vector &, float &); }; #endif diff --git a/source/designer/svgexporter.cpp b/source/designer/svgexporter.cpp index a9e13f8..a9ba131 100644 --- a/source/designer/svgexporter.cpp +++ b/source/designer/svgexporter.cpp @@ -27,8 +27,8 @@ void SvgExporter::save(const string &fn) gauge = layout.get_catalogue().get_gauge()*1000; const Profile &rail_profile = layout.get_catalogue().get_rail_profile(); - const Point &rail_min = rail_profile.get_min_coords(); - const Point &rail_max = rail_profile.get_max_coords(); + const Vector &rail_min = rail_profile.get_min_coords(); + const Vector &rail_max = rail_profile.get_max_coords(); rail_width = (rail_max.x-rail_min.x)*1000; xmlpp::Document *doc = new xmlpp::Document; @@ -41,8 +41,8 @@ void SvgExporter::save(const string &fn) ".artnr { text-anchor: middle; font-size: %.3f; }\n", rail_width, rail_width, gauge*0.75)); - Point minp; - Point maxp; + Vector minp; + Vector maxp; const set &tracks = layout.get_tracks(); for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { @@ -52,7 +52,7 @@ void SvgExporter::save(const string &fn) unsigned n_endpoints = (*i)->get_type().get_endpoints().size(); for(unsigned j=0; jget_endpoint_position(j); + Vector pos = (*i)->get_endpoint_position(j); if(i==tracks.begin() && j==0) minp = maxp = pos; else @@ -73,7 +73,7 @@ void SvgExporter::save(const string &fn) void SvgExporter::save_track(const Track &track, xmlpp::Element &group) { - const Point &pos = track.get_position(); + const Vector &pos = track.get_position(); float rot = track.get_rotation(); string transform = format("translate(%.3f %.3f) rotate(%.3f)", pos.x*1000, -pos.y*1000, -rot*180/M_PI); group.set_attribute("transform", transform); diff --git a/source/designer/trackwrap.cpp b/source/designer/trackwrap.cpp index 5e21ddc..45ec19c 100644 --- a/source/designer/trackwrap.cpp +++ b/source/designer/trackwrap.cpp @@ -34,7 +34,7 @@ void TrackWrap::render(const GL::Tag &) const for(list::const_iterator i=wraps.begin(); i!=wraps.end(); ++i) { GL::PushMatrix _pushm; - const Point &pos = i->track->get_position(); + const Vector &pos = i->track->get_position(); GL::translate(pos.x, pos.y, pos.z); GL::rotate(i->track->get_rotation()*180/M_PI, 0, 0, 1); i->mesh->draw(); @@ -64,12 +64,12 @@ GL::Mesh &TrackWrap::get_mesh(const TrackType &type) float min_area = -1; float angle = 0; - Point center; + Vector center; float width = 0; float height = 0; for(float a=0; aget_endpoint_direction(picking_entry); - Point pos = picking_track->get_endpoint_position(picking_entry); + Vector pos = picking_track->get_endpoint_position(picking_entry); GL::translate(pos.x, pos.y, pos.z+0.03); GL::rotate(rot*180/M_PI+180, 0, 0, 1); @@ -338,7 +338,7 @@ void Engineer::view_all() float max_y = 0; for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { - Point minp, maxp; + Vector minp, maxp; i->second->get_bounds(angle, minp, maxp); min_x = min(min_x, minp.x); max_x = max(max_x, maxp.x); diff --git a/source/engineer/trainview.cpp b/source/engineer/trainview.cpp index 805fec5..a2dedf9 100644 --- a/source/engineer/trainview.cpp +++ b/source/engineer/trainview.cpp @@ -92,7 +92,7 @@ void TrainView::set_forward(bool f) void TrainView::prepare() { const Vehicle &veh = train.get_vehicle(0); - const Point &pos = veh.get_position(); + const Vector &pos = veh.get_position(); float angle = veh.get_direction(); if(!forward) angle += M_PI; diff --git a/source/libr2c2/catalogue.cpp b/source/libr2c2/catalogue.cpp index 51cad9a..70a3985 100644 --- a/source/libr2c2/catalogue.cpp +++ b/source/libr2c2/catalogue.cpp @@ -96,8 +96,8 @@ void Catalogue::Loader::gauge(float g) { obj.gauge = g/1000; obj.path_profile = Profile(); - obj.path_profile.append_vertex(Point(0.1*obj.gauge, 0), false); - obj.path_profile.append_vertex(Point(-0.1*obj.gauge, 0), false); + obj.path_profile.append_vertex(Vector(0.1*obj.gauge, 0), false); + obj.path_profile.append_vertex(Vector(-0.1*obj.gauge, 0), false); } void Catalogue::Loader::layout() diff --git a/source/libr2c2/geometry.h b/source/libr2c2/geometry.h index 48bbd49..8519499 100644 --- a/source/libr2c2/geometry.h +++ b/source/libr2c2/geometry.h @@ -13,21 +13,21 @@ Distributed under the GPL namespace R2C2 { -struct Point +struct Vector { float x, y, z; - Point(): x(0), y(0), z(0) { } - Point(float x_, float y_): x(x_), y(y_), z(0) { } - Point(float x_, float y_, float z_): x(x_), y(y_), z(z_) { } + Vector(): x(0), y(0), z(0) { } + Vector(float x_, float y_): x(x_), y(y_), z(0) { } + Vector(float x_, float y_, float z_): x(x_), y(y_), z(z_) { } }; -inline float distance(const Point &p, const Point &q) +inline float distance(const Vector &p, const Vector &q) { return sqrt((p.x-q.x)*(p.x-q.x) + (p.y-q.y)*(p.y-q.y) + (p.z-q.z)*(p.z-q.z)); } struct TrackPoint { - Point pos; + Vector pos; float dir; float grade; diff --git a/source/libr2c2/profile.cpp b/source/libr2c2/profile.cpp index 1b1aeee..96b06a2 100644 --- a/source/libr2c2/profile.cpp +++ b/source/libr2c2/profile.cpp @@ -13,7 +13,7 @@ using namespace Msp; namespace R2C2 { -void Profile::append_vertex(const Point &p, bool smooth) +void Profile::append_vertex(const Vector &p, bool smooth) { if(vertices.size()>1 && !vertices.back().smooth) vertices.push_back(vertices.back()); @@ -32,7 +32,7 @@ void Profile::append_vertex(const Point &p, bool smooth) if(vertices.back().smooth) { - Point &n = vertices.back().normal; + Vector &n = vertices.back().normal; n.x += v.normal.x; n.y += v.normal.y; len = sqrt(n.x*n.x+n.y*n.y); @@ -76,12 +76,12 @@ Profile::Loader::Loader(Profile &p): void Profile::Loader::point(float x, float y) { - obj.append_vertex(Point(x/1000, y/1000), false); + obj.append_vertex(Vector(x/1000, y/1000), false); } void Profile::Loader::smooth_point(float x, float y) { - obj.append_vertex(Point(x/1000, y/1000), true); + obj.append_vertex(Vector(x/1000, y/1000), true); } } // namespace R2C2 diff --git a/source/libr2c2/profile.h b/source/libr2c2/profile.h index 4354a13..9f56b2d 100644 --- a/source/libr2c2/profile.h +++ b/source/libr2c2/profile.h @@ -28,22 +28,22 @@ public: struct Vertex { - Point pos; - Point normal; + Vector pos; + Vector normal; bool smooth; }; private: std::vector vertices; - Point min_coords; - Point max_coords; + Vector min_coords; + Vector max_coords; public: - void append_vertex(const Point &, bool); + void append_vertex(const Vector &, bool); unsigned get_n_vertices() const { return vertices.size(); } const Vertex &get_vertex(unsigned) const; - const Point &get_min_coords() const { return min_coords; } - const Point &get_max_coords() const { return max_coords; } + const Vector &get_min_coords() const { return min_coords; } + const Vector &get_max_coords() const { return max_coords; } float get_width() const { return max_coords.x-min_coords.x; } float get_height() const { return max_coords.y-min_coords.y; } }; diff --git a/source/libr2c2/track.cpp b/source/libr2c2/track.cpp index c6c1751..0d4052e 100644 --- a/source/libr2c2/track.cpp +++ b/source/libr2c2/track.cpp @@ -65,7 +65,7 @@ Block &Track::get_block() const return *block; } -void Track::set_position(const Point &p) +void Track::set_position(const Vector &p) { pos = p; } @@ -99,8 +99,8 @@ void Track::check_slope() if(links[0] && links[1]) { - Point epp0 = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); - Point epp1 = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); + Vector epp0 = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); + Vector epp1 = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); pos.z = epp0.z; slope = epp1.z-pos.z; } @@ -109,12 +109,12 @@ void Track::check_slope() slope = 0; if(links[0]) { - Point epp = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); + Vector epp = links[0]->get_endpoint_position(links[0]->get_endpoint_by_link(*this)); pos.z = epp.z; } else if(links[1]) { - Point epp = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); + Vector epp = links[1]->get_endpoint_position(links[1]->get_endpoint_by_link(*this)); pos.z = epp.z; } } @@ -162,7 +162,7 @@ int Track::get_endpoint_by_link(Track &other) const return -1; } -Point Track::get_endpoint_position(unsigned epi) const +Vector Track::get_endpoint_position(unsigned epi) const { const vector &eps = type.get_endpoints(); if(epi>=eps.size()) @@ -173,7 +173,7 @@ Point Track::get_endpoint_position(unsigned epi) const float c = cos(rot); float s = sin(rot); - Point p(pos.x+c*ep.pos.x-s*ep.pos.y, pos.y+s*ep.pos.x+c*ep.pos.y, pos.z); + Vector p(pos.x+c*ep.pos.x-s*ep.pos.y, pos.y+s*ep.pos.x+c*ep.pos.y, pos.z); if(eps.size()==2 && epi==1) p.z += slope; return p; @@ -205,14 +205,14 @@ bool Track::snap_to(Track &other, bool link, float limit) for(unsigned i=0; i &eps = type.get_endpoints(); for(unsigned i=0; i &get_links() const { return links; } diff --git a/source/libr2c2/trackpart.cpp b/source/libr2c2/trackpart.cpp index af2cf37..f677c70 100644 --- a/source/libr2c2/trackpart.cpp +++ b/source/libr2c2/trackpart.cpp @@ -43,12 +43,12 @@ TrackPoint TrackPart::get_point(float d) const float s = sin(a); float rx = radius*sin(dir); float ry = -radius*cos(dir); - result.pos = Point(pos.x+c*rx-s*ry-rx, pos.y+c*ry+s*rx-ry); + result.pos = Vector(pos.x+c*rx-s*ry-rx, pos.y+c*ry+s*rx-ry); result.dir = dir+a; } else { - result.pos = Point(pos.x+cos(dir)*d, pos.y+sin(dir)*d); + result.pos = Vector(pos.x+cos(dir)*d, pos.y+sin(dir)*d); result.dir = dir; } @@ -120,7 +120,7 @@ void TrackPart::Loader::finish() void TrackPart::Loader::start(float x, float y, float d) { - obj.pos = Point(x, y); + obj.pos = Vector(x, y); obj.dir = d; } diff --git a/source/libr2c2/trackpart.h b/source/libr2c2/trackpart.h index 0a07b4d..4294584 100644 --- a/source/libr2c2/trackpart.h +++ b/source/libr2c2/trackpart.h @@ -26,7 +26,7 @@ public: }; private: - Point pos; + Vector pos; float dir; float length; float radius; diff --git a/source/libr2c2/tracktype.h b/source/libr2c2/tracktype.h index 9c4865f..f285036 100644 --- a/source/libr2c2/tracktype.h +++ b/source/libr2c2/tracktype.h @@ -20,7 +20,7 @@ class TrackType public: struct Endpoint { - Point pos; + Vector pos; float dir; // Direction outwards from the endpoint unsigned paths; diff --git a/source/libr2c2/vehicle.cpp b/source/libr2c2/vehicle.cpp index 3fdc7a4..2c31ba1 100644 --- a/source/libr2c2/vehicle.cpp +++ b/source/libr2c2/vehicle.cpp @@ -293,17 +293,17 @@ void Vehicle::update_rods() const Axle &axle = get_axle(i->type->pivot_index); float c = cos(axle.angle); float s = sin(axle.angle); - const Point &pp = i->type->pivot_point; - i->position = Point(axle.type->position+pp.x*c+pp.z*s, pp.y, axle.type->wheel_dia/2+pp.z*c-pp.x*s); + const Vector &pp = i->type->pivot_point; + i->position = Vector(axle.type->position+pp.x*c+pp.z*s, pp.y, axle.type->wheel_dia/2+pp.z*c-pp.x*s); } else if(i->type->pivot==VehicleType::Rod::ROD) { const Rod &prod = get_rod(i->type->pivot_index); float c = cos(prod.angle); float s = sin(prod.angle); - const Point &pos = prod.position; - const Point &off = i->type->pivot_point; - i->position = Point(pos.x+off.x*c-off.z*s, pos.y+off.y, pos.z+off.z*c+off.x*s); + const Vector &pos = prod.position; + const Vector &off = i->type->pivot_point; + i->position = Vector(pos.x+off.x*c-off.z*s, pos.y+off.y, pos.z+off.z*c+off.x*s); } if(i->type->connect_index>=0) @@ -346,8 +346,8 @@ void Vehicle::adjust_for_distance(TrackPosition &front, TrackPosition &back, flo int adjust_dir = 0; while(1) { - Point front_point = front.get_point().pos; - Point back_point = back.get_point().pos; + Vector front_point = front.get_point().pos; + Vector back_point = back.get_point().pos; float dx = front_point.x-back_point.x; float dy = front_point.y-back_point.y; @@ -373,14 +373,14 @@ void Vehicle::adjust_for_distance(TrackPosition &front, TrackPosition &back, flo } } -TrackPoint Vehicle::get_point(const Point &front, const Point &back, float ratio) const +TrackPoint Vehicle::get_point(const Vector &front, const Vector &back, float ratio) const { float dx = front.x-back.x; float dy = front.y-back.y; float dz = front.z-back.z; TrackPoint tp; - tp.pos = Point(back.x+dx*ratio, back.y+dy*ratio, back.z+dz*ratio); + tp.pos = Vector(back.x+dx*ratio, back.y+dy*ratio, back.z+dz*ratio); tp.dir = atan2(dy, dx); return tp; diff --git a/source/libr2c2/vehicle.h b/source/libr2c2/vehicle.h index 1f118cc..b9c36d9 100644 --- a/source/libr2c2/vehicle.h +++ b/source/libr2c2/vehicle.h @@ -48,7 +48,7 @@ public: struct Rod { const VehicleType::Rod *type; - Point position; + Vector position; float angle; Rod(const VehicleType::Rod &); @@ -72,7 +72,7 @@ private: Vehicle *next; Vehicle *prev; TrackPosition track_pos; - Point position; + Vector position; float direction; std::vector axles; std::vector bogies; @@ -99,7 +99,7 @@ public: Track *get_track() const { return track_pos.track; } unsigned get_entry() const { return track_pos.ep; } float get_offset() const { return track_pos.offs; } - const Point &get_position() const { return position; } + const Vector &get_position() const { return position; } float get_direction() const { return direction; } const Axle &get_axle(unsigned) const; const Bogie &get_bogie(unsigned) const; @@ -116,7 +116,7 @@ private: void update_rods(); void adjust_for_distance(TrackPosition &, TrackPosition &, float, float = 0.5) const; - TrackPoint get_point(const Point &, const Point &, float = 0.5) const; + TrackPoint get_point(const Vector &, const Vector &, float = 0.5) const; TrackPoint get_point(const TrackPosition &, float, float = 0.5) const; }; diff --git a/source/libr2c2/vehicletype.cpp b/source/libr2c2/vehicletype.cpp index 4f64019..7b355ac 100644 --- a/source/libr2c2/vehicletype.cpp +++ b/source/libr2c2/vehicletype.cpp @@ -232,8 +232,8 @@ void VehicleType::Rod::Loader::connect(const string &t, float px, float pz, floa if(i==tags.end()) throw KeyError("Unknown rod tag", t); obj.connect_index = i->second; - obj.connect_point = Point(px/1000, 0, pz/1000); - obj.connect_offset = Point(ox/1000, 0, oz/1000); + obj.connect_point = Vector(px/1000, 0, pz/1000); + obj.connect_offset = Vector(ox/1000, 0, oz/1000); } void VehicleType::Rod::Loader::pivot_body() @@ -265,7 +265,7 @@ void VehicleType::Rod::Loader::pivot_rod(const string &t) void VehicleType::Rod::Loader::position(float x, float y, float z) { - obj.pivot_point = Point(x/1000, y/1000, z/1000); + obj.pivot_point = Vector(x/1000, y/1000, z/1000); } void VehicleType::Rod::Loader::set_tag(const string &t) diff --git a/source/libr2c2/vehicletype.h b/source/libr2c2/vehicletype.h index a12d3f4..97942af 100644 --- a/source/libr2c2/vehicletype.h +++ b/source/libr2c2/vehicletype.h @@ -116,11 +116,11 @@ public: Anchor pivot; unsigned pivot_index; unsigned pivot_index2; - Point pivot_point; + Vector pivot_point; Limit limit; int connect_index; - Point connect_point; - Point connect_offset; + Vector connect_point; + Vector connect_offset; std::string object; bool mirror_object;