Skip to content

Commit a003cef

Browse files
committed
Added algorithm to work out if cattle is infected
1 parent fd064ad commit a003cef

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/models/Cattle.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ export class Cattle {
66
#location;
77
#status;
88
#imageUrl;
9+
#fieldX;
10+
#fieldY;
911

10-
constructor(id, sex, tag, breed, location, status = 'Healthy', imageUrl = null) {
12+
constructor(id, sex, tag, breed, location, status = 'Healthy', imageUrl = null, fieldX = 0.0, fieldY = 0.0) {
1113
this.#id = id;
1214
this.#sex = sex;
1315
this.#tag = tag;
1416
this.#breed = breed;
1517
this.#location = location;
1618
this.#status = status;
1719
this.#imageUrl = imageUrl;
20+
this.fieldX = fieldX;
21+
this.fieldY = fieldY;
1822
}
1923

2024
// Getters
@@ -53,6 +57,23 @@ export class Cattle {
5357
return this.#status.toLowerCase().replace(/\s+/g, '-');
5458
}
5559

60+
getPossiblyInfected(cattle){
61+
for (let i = 0; i < cattle.length; i++){
62+
let cattleDistance = Math.sqrt(((cattle[i].fieldX - this.fieldX) * (cattle[i].fieldX - this.fieldX)) + ((cattle[i].fieldY - this.fieldY) * (cattle[i].fieldY - this.fieldY)));
63+
if (cattleDistance < 10){
64+
if (cattle[i].#status === 'Infected'){
65+
return true;
66+
}
67+
}
68+
}
69+
70+
if (this.#status === 'Infected'){
71+
return true;
72+
} else {
73+
return false;
74+
}
75+
}
76+
5677
toJSON() {
5778
return {
5879
id: this.#id,

0 commit comments

Comments
 (0)