Distance between point and rectangular box without case logic

Assuming you have a point (x,y) and a rectangle parallel to x and y axis defined by its upper left and lower right corner. How can we calculate its distance without using case logic?

P = (x,y)
A = { (x1,y1), (x2,y2) }

The answer is:

dx = max(A.x1 - p.x, 0, p.x - A.x2)
dy = max(A.y1 - p.y, 0, p.y - A.y2)
distance = sqrt(dx*dx + dy*dy)

Its very tricky.

Here is a great analysis here by MultiRRomero:


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) }




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:


And an awesome interactive visualization by Matthew Crumley here:


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:


Cat nutrition table from animalmedicalcenter:


Best daily calorie calculator site for cats and dogs:


Advices for cat nutrition:



Another calculator