Determine if two rectangles intersect without case logic

Assuming you have two rectangles A and B that exist parallel to the x and y axis and are defined by their upper left (x1,x2) and lower right corners (x2,y2). How can you calculate if A and B intersect without using case logic?

A = { (x1,y1), (x2,y2) }
B = { (x1,y1), (x2,y2) }

 

intersect

 

The answer is:

if (A.x1 < B.x2 && 
    A.x2 > B.x1 &&  
    A.y1 < B.y2 && 
    A.y2 > B.y1) {
  then A and B intersect
}

There is a great analysis here:

http://stackoverflow.com/questions/306316/determine-if-two-rectangles-overlap-each-other

And an awesome interactive visualization by Matthew Crumley here:

https://silentmatt.com/rectangle-intersection/

Advertisements

Git Setup instructions

Setup your account and your project:

  1. Create a google account
  2. Use that account to login to gitlab.com
  3. Create a new project
  4. Note the URL of the project displayed by gitlab.
  5. Optionally add members (other users) to that project as developers

Install git client to a linux (debian) machine:

  1. sudo apt-get install xclip
  2. sudo apt-get install git
  3. ssh-keygen -t rsa -C “blabla@hohomail.com”
  4. xclip -sel clip < ~/.ssh/id_rsa.pub

Step 3 has created a public and a private key to the computer to be used from SSH. The paths are:

  • private key file: ~/.ssh/id_rsa
  • public key file: ~/.ssh/id_rsa.pub

Step 4 has copied the public key to clipboard buffer. You have to login to gitlab and paste that key to your profile’s SSH keys.

Configure GIT global variables:

  1. git config –global user.name “John Doe”
  2. git config –global user.email “blabla@hohomail.com”

Now you are ready to either create a new repository or clone an existing one:

To create a new repository:

  1. git init
  2. git remote add origin git@gitlab.com:blabla/projectsth.git
  3. git add .
  4. git commit -m “blabla comment”
  5. git push -u origin master

To clone an existing one:

  1. git clone git@gitlab.com:blabla/projectsth.git
  2. touch newfile
  3. git add newfile
  4. git commit -m “blabla comment”
  5. git push -u origin master

Pet nutrition

From catster you have a handy estimation:

For wet food:

  • 3 ounce = 85gr = 125 calories
  • 6 ounce = 170gr = 250 calories

For dry food:

  • 1 cup = 300 calories

Here are some sites with important information on pet diet:

Calculator for calories per 100g of dry food:

http://fnae.org/carbcalorie.html

Cat nutrition table from animalmedicalcenter:

http://www.animalmedicalcenterofchicago.com/pdf/CalorieRequirementsForCats.pdf

Best daily calorie calculator site for cats and dogs:

http://petnutritionalliance.org/calculator/cat.php

http://www.petplace.com/article/cats/keeping-your-cat-healthy/feeding-nutrition/how-to-calculate-your-cats-daily-calorie-intake

Advices for cat nutrition:

http://www.2ndchance.info/catfood.htm

http://www.catster.com/cat-food/how-much-should-i-feed-my-cat

Another calculator

http://petsci.co.uk/feline-calorie-calculator/

 

Bash history expansion

The general syntax is:

!command:parameter

Command segment defines which command to look for in history. It can be a modifier like !! (last command), !-1, !-2, !-3 … (last, previous to last etc) or a specific keyword like !cat (search for most recent cat).

Parameter segment defines which part of the command to use. ^ is first parameter, $ is last parameter, * are all the parameters, 0 the command and 1,2,3… are the parameters. You can define a range eg 2-4 (parameters 2 to 4)

Besides that, you can also use ^x^y^ to replace x with y. There are some more advanced ways to search. Take a look at the references at the end of this page.

You can also use history n to review the last n commands with their ids. If you know an id, you can use it at command segment,

All results are shown as if the command was executed immediately after touch a b c d e (not one after another)

Assume that you have typed in this order:

  1. ls -a -r
  2. date
  3. touch a b c d e
!! last command (all words) touch a b c d e
!* all but first keyword a b c d e
!^ second keyword a
!$ last keyword e
!:0 first word touch
!:1 second word a
!:2-4 range of words b c d
 ^touch^ls find touch and replace it with ls  ls a b c e d
!-1 last command touch a b c d e
!-2 previous to last command date
!-2:0 first keyword of previous to last command date
!ls:* search for command ls
all but first keyword of ls
-a -r
!ls:$ search for command ls
last keyword of ls
-r

References:

http://www.thegeekstuff.com/2011/08/bash-history-expansion

https://www.gnu.org/software/bash/manual/html_node/Event-Designators.html#Event-Designators

Book recommendation:

UNIX Shells by Example, Ellie Quigley

Doom links

The Doom series Wiki

It includes complete walkthroughs for every map of every doom game. It includes story background, history, speedrun paths and instructions for all secrets on all maps. The only drawback is that secrets are explained with text.

classicdoom.com

This is a great site for Doom 1 and Doom 2 resources. It includes the maps of all episodes with options to display keys, teleports and secrets. Secrets and teleports are displayed visually on the maps.

onemandoom

Useful site with many reviews of the common WADs

ian-albert.com

You can find pseudo 3d projections of the maps.

Engines

gzdoom

prboom

Mods:

I do not include links since they might change in the future, but if you google them you will easily find sites to download them.

  • Smooth Doom – It includes only visual improvements. No gameplay changes
  • Beautiful doom – It includes visual improvements. It also includes new weapons and some minor game play changes but they are mostly optional
  • Knee deep in zdoom – Imho a totally different game, but you can check it out

Wads:

  • Winter’s fury

There are numerous other mods and WADs. I only include those I like.

Netbeans – “not all requested modules can be enabled”

If you have installed Oracle Java 8 via default installers and you get the awkward message “not all requested modules can be enabled” in your Linux box when trying to create a new java project in Netbeans you should:

  1. open netbeans.conf
    1. set netbeans_jdkhome to point to the proper location, eg:

netbeans_jdkhome=”/usr/lib/jvm/java-8-oracle”

This file should be found in install dir of netbeans

The easiest way to find netbeans.conf is to run the following command:

  • find / -name netbeans.conf 2> /dev/null

In default installation it should be something like:

  • /home//netbeans-X.Y/etc/netbeans.conf

C++ Data models

A usual headache to C++ beginners: What is the value of sizeof(int) in C/C++?

The answer is: there is no specific answer.

In theory, the C++ standard does not define explicitly the size of primitive data types but it does define their minimum size. You can read more about it at official C++ reference page

In practice though, there are 4 data models that are mostly used : LP32, ILP32, LLP64 and LP64. Both Windows and Linux 32 architectures use ILP32. Windows 64bit use LP64 and Linux 64bit use LLP 64.

If you compare the values, you will see that sizes of all floating point data types are the same regardless of architecture (float 4, double 8, long double 16) and all integer data types are the same apart from long (char 1, short 2, int 4, long long 8). Of course pointers depend on the architecture (32bit in x86 and 64 bit in AMD64)

Here is a handy table for you.

datamodels

 

 

Doom 3 in modern computers

In this post I explained in summary what you have to do to run Doom 1 & 2 in your modern PC. Doom 3 is a totally different story.

The reason is that ID released two games named Doom 3 which are considered totaly different by hardcore gamers:

  1. Doom3 (vanilla version). This version was released on 2004 and it is considered an old game. Doom3 vanilla version was designed as a thriller.
  2. Doom3 BFG, released on 2012. Doom 3 BFG was designed as a shoot em up.

I think the most important difference between these is the flashlight. In original Doom 3 you cannot hold a flashlight and a weapon at the same time (doh). Although this is an awkward choice it adds up to the atmosphere of the game (less light = more scary). In Doom 3 BFG on the otherhand, this was “fixed”. Additionally some shadows were removed and wide screen support was added, making the game more brightful and less scary. Whether this is good or bad is up to you to decide.

Another important difference is that Doom3 supports more mods. So you have many options:

  1. Run Doom3 as it was released. Graphics will be old style and you will have to switch between flashlight and other weapons frequently.
  2. Run Doom3 BFG as it was released.Graphics will be slightly better
  3. Run Doom3 with mods:
    1. If you want light then add ducttape. This will add light to some of your weapons. This will not change graphics, but it will make the game easier to play, especially if your room is bright.
    2. If you want better graphics then add AbsoluteHD
    3. If you want a different experience you may try Perfect Doom 3

You can combine mods so the possibilities are endless provided you have the necessary time to spend. The easiest way to configure Doom3 though is to read this thread and download a premade configuration file from that thread. Also read this thread. Alternatively you can watch this video, but from the two threads mentioned you will learn more.

In summary, these are some of the most used mods:

  1. Sikkmod
  2. Wulfen’s high-res texture pack v2.0 (texture improvement)
  3. Monoxead Texture pack (texture improvement)
  4. Trent Reznor’s sound pack (sound improvement, i disagree)
  5. Parallax Occlusion mapping mod
  6. Venom Menu Enhancement Pack

 

Personal portal to the Internet