From 3c6f8765ea525ce1d8c04b92ebd2c83f39a7bbab Mon Sep 17 00:00:00 2001 From: Johann Rudloff Date: Sun, 13 Apr 2008 13:32:51 +0000 Subject: [PATCH] Fix profiling switch in SConstruct. Speed up simulation by avoiding double calculation. --- SConstruct | 6 +++--- src/Simulation.cpp | 22 +++++++++++----------- src/Simulation.h | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/SConstruct b/SConstruct index ef3c7c1..8ad5f4e 100644 --- a/SConstruct +++ b/SConstruct @@ -40,12 +40,12 @@ if not conf.PkgConfig('gtkmm-2.4', '2.8'): env.AppendUnique(CCFLAGS=['-Wall']) if env['profiling']: - env.AppendUnique(CPPDEFINES='PROFILING') + env.AppendUnique(CPPDEFINES=['PROFILING']) if env['debug']: - env.AppendUnique(CCFLAGS=['-g', '-O0'], CPPDEFINES='DEBUG') + env.AppendUnique(CCFLAGS=['-g', '-O0'], CPPDEFINES=['DEBUG']) else: - env.AppendUnique(CCFLAGS=['-O3'], CPPDEFINES='NDEBUG') + env.AppendUnique(CCFLAGS=['-O3'], CPPDEFINES=['NDEBUG']) paths = {"bindir": env['prefix'] + '/bin', "datadir": env['prefix'] + '/share/elfelli', diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 64d6e20..6d18c03 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -143,21 +143,21 @@ Vec2 Simulation::force_at(const Vec2& pos, float charge) { PlateBody& plate = plates[i]; - float ax, ay, bx, by; + float xa, ya, xb, yb; Vec2 v; - ax = plate.pos_a.get_x() - pos.get_x(); - ay = plate.pos_a.get_y() - pos.get_y(); - bx = plate.pos_b.get_x() - plate.pos_a.get_x(); - by = plate.pos_b.get_y() - plate.pos_a.get_y(); + xa = plate.pos_a.get_x() - pos.get_x(); + ya = plate.pos_a.get_y() - pos.get_y(); + xb = plate.pos_b.get_x() - plate.pos_a.get_x(); + yb = plate.pos_b.get_y() - plate.pos_a.get_y(); - v.set_x((2*by*atan((by*by+ay*by+bx*bx+ax*bx)/(ax*by-ay*bx))+bx*log(by*by+2*ay*by+bx*bx+2*ax*bx+ay*ay+ax*ax)-2*by* - atan((ay*by+ax*bx)/(ax*by-ay*bx))-log(ay*ay+ax*ax)*bx)/((2*by*by+2*bx*bx)*(atan((by*by+ay*by+bx*bx+ax*bx)/(ax*by-ay*bx))/(ax*by-ay*bx)-atan((ay*by+ax*bx)/(ax*by-ay*bx))/(ax*by-ay*bx)))); - - v.set_y((-2*bx*atan((by*by+ay*by+bx*bx+ax*bx)/(ax*by-ay*bx))+by*log(by*by+2*ay*by+bx*bx+2*ax*bx+ay*ay+ax*ax)+2*bx* - atan((ay*by+ax*bx)/(ax*by-ay*bx))-log(ay*ay+ax*ax)*by)/((2*by*by+2*bx*bx)*(atan((by*by+ay*by+bx*bx+ax*bx)/(ax*by-ay*bx))/(ax*by-ay*bx)-atan((ay*by+ax*bx)/(ax*by-ay*bx))/(ax*by-ay*bx)))); + float u = (-(2*ya*yb+2*xa*xb)*atan((yb*yb+ya*yb+xb*xb+xa*xb)/(xa*yb-xb*ya))-(xb*ya-xa*yb)* + log(yb*yb+2*ya*yb+ya*ya+xb*xb+2*xa*xb+xa*xa)-(-2*ya*yb-2*xa*xb)*atan((ya*yb+xa*xb)/(xa*yb-xb*ya))-xa*log(ya*ya+xa*xa)* + yb+xb*ya*log(ya*ya+xa*xa))/((2*yb*yb+2*xb*xb)*atan((yb*yb+ya*yb+xb*xb+xa*xb)/(xa*yb-xb*ya))+(-2*yb*yb-2*xb*xb)*atan((ya*yb+xa*xb)/(xa*yb-xb*ya))); + v.set_x(xa+u*xb); + v.set_y(ya+u*yb); float dist = v.length(); - float length = sqrt(bx*bx+by*by)/30; + float length = sqrt(xb*xb+yb*yb)/30; Vec2 t = (v.normalize())/(dist*dist); f -= t * (charge * plate.charge/length); diff --git a/src/Simulation.h b/src/Simulation.h index 28f9031..4d8a280 100644 --- a/src/Simulation.h +++ b/src/Simulation.h @@ -105,8 +105,8 @@ public: void add_body(const Vec2& v, float charge); void add_plate(const Vec2& a, const Vec2& b, float charge); - const std::vector get_bodies() const{return bodies;}; - const std::vector get_plates() const{return plates;}; + const std::vector& get_bodies() const{return bodies;}; + const std::vector& get_plates() const{return plates;}; Body& operator[](int n){return bodies[n];}; int n_bodies(){return bodies.size();}; -- 2.38.5