Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Javascript, How do i check if two pseudo rectangles are colliding

Say I have two tables: rect1, and rect2. Each one follows the format of x,y,width,height.

For x, the bigger the number, the farther right it is. for y, the bigger the number, the farther down it is.

var rect1 = [20,40,80,60];
var rect2 = [10,30,67,10];

How would I check if these are colliding? I know it is math related, I am just having issues thinking at the moment.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It should be something along the lines of:

var rect1 = [20, 40, 80, 60];
var rect2 = [10, 30, 67, 10];
function checkCollision(rect1, rect2) {
  var x1 = rect1[0];
  var y1 = rect1[1];
  var w1 = rect1[2];
  var h1 = rect1[3];
  var x2 = rect2[0];
  var y2 = rect2[1];
  var w2 = rect2[2];
  var h2 = rect2[3];
  if (x1 < x2 + w2 && x1 + w1 > x2 && y1 < y2 + h2 && y1 + h1 > y2) {
    return true;
  } else {
    return false;
  }
}
console.log(checkCollision(rect1, rect2));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!