Skip to content

Commit 7fc21e0

Browse files
committed
Fixed Geometry Orientation Feature
1 parent 5c39e87 commit 7fc21e0

4 files changed

Lines changed: 1197 additions & 10 deletions

File tree

Geometry/ConvexHullGraham.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ function compare(a, b) {
1212
if (a.x === b.x && a.y < b.y) return -1
1313
return 1
1414
}
15+
1516
function orientation(a, b, c) {
16-
// Check orientation of Line(a, b) and Line(b, c)
17-
const alpha = (b.y - a.y) / (b.x - a.x)
18-
const beta = (c.y - b.y) / (c.x - b.x)
17+
// Calculate the cross product value
18+
// This helps determine the direction of the turn
19+
const val = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y)
1920

2021
// Clockwise
21-
if (alpha > beta) return 1
22-
// Anticlockwise
23-
else if (beta > alpha) return -1
24-
// Colinear
22+
if (val > 0) return 1
23+
// Counterclockwise
24+
if (val < 0) return -1
25+
// Collinear
2526
return 0
2627
}
2728

Maths/MobiusFunction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export const mobiusFunction = (number) => {
2828
return primeFactorsArray.length !== new Set(primeFactorsArray).size
2929
? 0
3030
: primeFactorsArray.length % 2 === 0
31-
? 1
32-
: -1
31+
? 1
32+
: -1
3333
}

String/GenerateGUID.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const Guid = () => {
88
const pattern = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
99
let currentDateMilliseconds = new Date().getTime()
1010
return pattern.replace(/[xy]/g, (currentChar) => {
11-
const randomChar = (currentDateMilliseconds + Math.random() * 16) % 16 | 0
11+
const randomChar = ((currentDateMilliseconds + Math.random() * 16) % 16) | 0
1212
currentDateMilliseconds = Math.floor(currentDateMilliseconds / 16)
1313
return (
1414
currentChar === 'x' ? randomChar : (randomChar & 0x7) | 0x8

0 commit comments

Comments
 (0)