Week 5 — 24 January, 2022

This week was really well for me. Because I've reached some of my weekly goals!

  • Reach 80 followers on Twitter. ✅
  • Reach 500 subscriber on Youtube ✅
  • Reach 280 followers on Instagram. ✅

I know! I know, it's not big numbers. But it's a progress and I'm proud of myself 🥳

What I've learned previous week?

How to determine if a point lay on the line or not?

I was working on a project at Swiftmade. I had needed to determine if a point is on the line or not. I've realized that my math was not enough to do this quickly 😬😊😂. I've found a couple of solutions to implement but this one was working really good.

isOnLine(line, point) {
  // a: first point of line
  // b: end point of line
  // c: target point

  const ab = Math.sqrt(
    (line[0][0] - line[1][0]) ** 2 + (line[0][1] - line[1][1]) ** 2
  )

  const ac = Math.sqrt(
    (line[0][0] - point[0]) ** 2 + (line[0][1] - point[1]) ** 2
  )

  const bc = Math.sqrt(
    (line[1][0] - point[0]) ** 2 + (line[1][1] - point[1]) ** 2
  )

  // const result = Math.abs(ac + bc - ab) < Number.EPSILON
  const epsilon = 0.005
  const result = ac + bc - ab < epsilon

  return result
}

Number.EPSILON did not work well in my case. Using 0.005 was working well instead.

What did I do during previous week?

Remember user preference of dark mode on my website

When you choose dark mode or light mode on this website, it will remember that and will works according to your last choice. 🥳

A new youtube tutorial

I've published the third episode of twitter clone tutorial.

Links