Posts

Featured post

c++ - Collision Detection and Time Complexity: How do I make checking for collisions easier? -

i'm trying write program handles detection of various objects. objects have origin, width, height, , velocity. there way set data structure/algorithm every object isn't checking every other object? some sample code of problem i'm trying avoid: for (int = 0; < ballcount; i++) { (int j = + 1; j < ballcount; j++) { if (balls[i].colliding(balls[j])) { balls[i].resolvecollision(balls[j]); } } } as mentioned other answer(s), can use quadtree structure make collision detection faster. i recommend geos open-source c++ library, has quadtree implementation. here docs quadtree class . so pseudo code this: quadtree quadtree; // create , populate quadtree. // change whenever balls move. // here's intersection loop: (int i=0; i<ballcount; ++i) { envelope envelope = ...; // bounds (envelope) of ball std::vector<void*> possiblyintersectingballs; quadtree.query(envelope, possiblyintersectingballs); // loop on members of possiblyintersectingballs check // if int...

r - Learning to understand plyr, ddply -

i've been attempting understand , how plyr works through trying different variables , functions , seeing results. i'm more looking explanation of how plyr works specific fix answers. i've read documentation newbie brain still not getting it. some data , names: mydf<- data.frame(c("a","a","b","b","c","c"),c("e","e","e","e","e","e") ,c(1,2,3,10,20,30), c(5,10,20,20,15,10)) colnames(mydf)<-c("model", "class","length", "speed") mydf question 1: summarise versus transform syntax so if enter: ddply(mydf, .(model), summarise, sum = length+length) i get: `model ..1 1 2 2 4 3 b 6 4 b 20 5 c 40 6 c 60 and if enter: ddply(mydf, .(model), summarise, length+length) same result. now if use transform: ddply(mydf, .(model), transform, sum = (length+length)) i get: model class length speed sum 1 e 1 5 2 2 e 2 10 4...

python - How to escape a ' within a string? -

i have little script creates insert sql statement me. for postgresql need wrap values inserted within 2 single quotes. unfortunately of value strings inserted contain single quote, , need escape them automatically. for line in f: out.write('(\'' + line[:2] + '\', \'' + line[3:-1] + '\'),\n') how can make sure single quote (e.g. ' ) inside line[3:-1] automatically escaped? thanks, update: e.g. line ci|cote d'ivoire fails due ' update 2: i can't use double quotes in values, e.g. insert "app_country" (country_code, country_name) values ("af", "afghanistan") i error message: error: column "af" not exist this works fine: insert "app_country" (country_code, country_name) values ('af', 'afghanistan') as described in pep-249 , dbpi generic interface various databases. different implementations exist different databases. postgres there psycopg . docs: c...

c# - Inheritance vs varying instances? -

if modelling various brands of cars use inheritance hierarchy, or varying constructor parameters? what general rule whether relate objects using inheritance, or re-using same class? for cars new car("porsche","991","3.8") or have overall abstract car superclass, abstract subclass manufacturers "porsche" , possibly class each model of porsche? if have few properties shared cars (or methods act on object), , unique properties (or methods) each make/model, you'd want use inheritance. otherwise, varying instances fine. let's want these properties cars: make model year of doors in case, wouldn't want create class hierarchy, because doesn't buy anything. instead, if had 2 "types" of cars: regular , race-car, , race-car enable nitrous oxide (presumably method this), you'd want car class, regularcar , racecar inheriting it. if you're afraid of having pass same parameters constructor time, can create stat...

PHP Preg_replace() function -

how use preg_replace function replace /c83403.403/ example: https://startimage.ca/c83403.403/ahmedmynewpix.jpg another example: https://startimage.ca/c2.3403.403/ahmedmynewpix2.jpg it start /c..../ want replace "" i trying following not working $str = '/c..../'; $str = preg_replace('/+[0-9]', '', $str); do mean this? $str = 'https://startimage.ca/c83403.403/ahmedmynewpix.jpg'; $str = preg_replace('|/c[0-9.]+|', '', $str); echo $str; # https://startimage.ca/ahmedmynewpix.jpg' ... or $str = preg_replace('|/c[0-9.]+|', '/c', $str); echo $str; # https://startimage.ca/c/ahmedmynewpix.jpg' the point replace starting /c , containing either digits or dot symbol ( . ) - either empty space or /c string, depending on need. )

android - Reading ActivityManager-logs on a Jelly Bean device? -

jelly bean has removed ability read logs of other apps (according this i/o talk), sensible security improvement. however, need read activitymanager -logs app work (to see app starting). this, using private static final string clearlogcat = "logcat -c"; private static final string logcatcommand = "logcat activitymanager:i *:s"; //... which no longer works, can read own application's logs in jelly bean. there alternative solution finding out when app starting (apart root)? understand why shouldn't able read other applications' logs (kind of - should other developers' resposibility make sure no personal information logged, not mine being prevented reading log), don't understand why activitymanager , framework class, included in policy... thanks, nick there extensive discussion of issue going on here . unfortunately, it's "expected behavior" , such won't fixed. current solution (for reading logs within application on jb , ...

python - Tuple of objects that, if referenced directly, returns first object -

i want modify 1 of api methods returns object. think should return tuple of objects. don't want change way people call api method. there way return tuple of objects can referenced directly first object? if change function returned object instead return tuple, callers of function have changed. there no way around that. either change callers extract first object, or unchanged code have tuple used have object.