Posts

coordinate systems - How can I calculate the distance between two points in Cartesian space while respecting Asteroids style wrap around? -

i have 2 points (x 1 , y 1 ) , (x 2 ,y 2 ) represent location of 2 entities in space. calculate euclidian distance between them using pythagoras' theorem , wonderful. however, if space becomes finite, want define new shortest distance between points "wraps around" seams of map. example, if have point (10, 10) , point b (90,10) , , map 100 units wide, i'd calculate distance between , b 20 (out right edge of map , left edge), instead of 80, normal euclidian distance. i think issue i'm using coordinate system isn't quite right i'm trying do, , flat square map more of seamless doughnut shape. suggestions how implement system of nature , convert , forth cartesian coordinates appreciated too! toroidal plane? okay, i'll bite. var raw_dx = math.abs(x2 - x1); var raw_dy = math.abs(y2 - y1); var dx = (raw_dx < (xmax / 2)) ? raw_dx : xmax - raw_dx; var dy = (raw_dy < (ymax / 2)) ? raw_dy : ymax - raw_dy; var l2dist = math.sqrt((dx * dx)...

sql server - FIltering on the join? -

is there argument, performance wise, filtering in join, opposed clause? for example, select blah tablea inner join tableb b on b.id = a.id , b.deleted = 0 a.field = 5 as opposed to select blah tablea inner join tableb b on b.id = a.id a.field = 5 , b.deleted = 0 i prefer latter, because feel filtering should done in filtering section (where), there performance or other reasons either method? if query optimizer job, there no difference @ (except clarity others) in 2 forms inner joins. that said, left joins condition in join means filter rows out of second table before joining. condition in means filter rows out of final result after joining. mean different things.

ruby - Spit out a list of the last 10 days in Rails 3 -

i feel should qualify of questions saying brand new rails 3, forgive me newbiness. i've been reading actionview date helpers, cannot figure out how complete simple function. in rails 3, want spit out html list last 10 days. so, instance, today: <li>tuesday, february 8</li> <li>monday, february 7</li> <li>sunday, february 6</li> <li>saturday, february 5</li> <li>friday, february 4</li> <li>thursday, february 3</li> <li>wednesday, february 2</li> <li>tuesday, february 1</li> <li>monday, january 31</li> <li>sunday, january 30</li> it seems simple, cannot figure out. care give shot? <%- date.today.downto(date.today - 9.days) |date| %> <li><%= date %></li> <%- end %>

java - Will other instances of a class be able to access a static variable in another? -

i have class know loaded urlclassloader each instance of it, if have static variable in one, other instances able access it? for example, class myclass loaded classloader , classloader b, , want know if myclass loaded have same static fields myclass loaded b. so basically, following statement true: a.loadclass("myclass").getfield("myfield").get(null).equals(b.loadclass("myclass").getfield("myfield").get(null)); unfortunately @dinesh/@daj's answer incorrect. (@romain's maybe too, wording hard parse.) suppose have class a.b.c , arrange same class gets loaded 2 different classloaders. according specifications, end 2 distinct class objects qualified name a.b.c , , type system perspective 2 distinct types. each of types have different set of static variables. the primary reference jls 4.3.4 - paragraphs 2 , 3. you can infer each reference type distinct (at runtime) have distinct set of statics jls 4.12.3 , jls 8.3...

ruby on rails - dynamic nested form always creates an extra blank entry - using formtastic_coocoon -

i'm using formtastic & formtastic_cocoon created nested form. all seems working dynamically adding nested form existing form, 1 exception. i have users , users have entries. when create user, , add entry, end -user - entry (empty) - entry test 1 i should have -user - entry test 1 i'm not sure why blank entry showing up. my models are class user < activerecord::base validates :name, :presence => true has_attached_file :photo has_many :tasks, :dependent => :destroy accepts_nested_attributes_for :tasks, :allow_destroy => true end class task < activerecord::base attr_accessible :entry belongs_to :user end my create controller (i think right controller) def create @user = user.new(params[:user]) if @user.save flash[:notice] = "successfully created user." redirect_to @user else render :action => 'new' end end def create @task = task.new(p...

haskell - Override -Werror when installing from Cabal -

i'm trying install nano-hmac-0.2.0 package (a dependency of package want) hackage using cabal , ghc 6.12.1, fails following error: data/digest/openssl/hmac.hsc:1:0: warning: module `prelude' deprecated: using old package `base' version 3.x. future ghc versions not support base version 3.x. should update code use new base version 4.x. <no location info>: failing due -werror. sure enough, package's .cabal file has following line in it: ghc-options: -wall -werror -o2 -fvia-c i'd able override -werror option can install package without manually modifying .cabal file, can't find way work. in particular, tried passing --ghc-options cabal stick -wwarn in ghc's argument list, this: $ cabal install nano-hmac-0.2.0 -v2 --ghc-options='-wwarn' this doesn't want, though; verbose output verifies -wwarn getting added beginning of ghc's argument list, -werror .cabal fil...

how to put dynamic button in android useing its position -

how put dynamic button using xml. want fetch position of button xml , place them in screen. what mean dynamic? create xml file called filename.xml, put in. change drawables necessary. bt_return , bt_returnpress <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/bt_return" android:state_pressed="false" /> <item android:drawable="@drawable/bt_returnpress" android:state_pressed="true" /> <item android:drawable="@drawable/bt_return" android:state_focused="false" /> <item android:drawable="@drawable/bt_returnpress" android:state_focused="true" /> </selector> then assign filename.xml background of dynamic button u want.