isaacscript-common 30.0.0 → 30.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.rollup.d.ts
CHANGED
|
@@ -4618,6 +4618,15 @@ export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity:
|
|
|
4618
4618
|
|
|
4619
4619
|
export declare function getClosestPlayer(position: Vector): EntityPlayer;
|
|
4620
4620
|
|
|
4621
|
+
/**
|
|
4622
|
+
* Given an array of vectors, this helper function returns the closest one to a provided reference
|
|
4623
|
+
* vector.
|
|
4624
|
+
*
|
|
4625
|
+
* @param referenceVector The vector to compare against.
|
|
4626
|
+
* @param vectors The array of vectors to look through.
|
|
4627
|
+
*/
|
|
4628
|
+
export declare function getClosestVectorTo(referenceVector: Vector, vectors: Vector[]): Vector | undefined;
|
|
4629
|
+
|
|
4621
4630
|
/**
|
|
4622
4631
|
* Helper function to get all of the coin pickup entities in the room.
|
|
4623
4632
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
--[[
|
|
2
2
|
|
|
3
|
-
isaacscript-common 30.
|
|
3
|
+
isaacscript-common 30.1.0
|
|
4
4
|
|
|
5
5
|
This is the "isaacscript-common" library, which was created with the IsaacScript tool.
|
|
6
6
|
|
|
@@ -17838,6 +17838,18 @@ function ____exports.doesVectorHaveLength(self, vector, threshold)
|
|
|
17838
17838
|
end
|
|
17839
17839
|
return vector:Length() >= threshold
|
|
17840
17840
|
end
|
|
17841
|
+
function ____exports.getClosestVectorTo(self, referenceVector, vectors)
|
|
17842
|
+
local closestVector
|
|
17843
|
+
local closestDistance = math.huge
|
|
17844
|
+
for ____, vector in ipairs(vectors) do
|
|
17845
|
+
local distance = referenceVector:Distance(vector)
|
|
17846
|
+
if distance < closestDistance then
|
|
17847
|
+
closestVector = vector
|
|
17848
|
+
closestDistance = distance
|
|
17849
|
+
end
|
|
17850
|
+
end
|
|
17851
|
+
return closestVector
|
|
17852
|
+
end
|
|
17841
17853
|
function ____exports.getRandomVector(self, seedOrRNG)
|
|
17842
17854
|
if seedOrRNG == nil then
|
|
17843
17855
|
seedOrRNG = getRandomSeed(nil)
|
|
@@ -23,6 +23,14 @@ export declare function deserializeVector(vector: SerializedVector): Vector;
|
|
|
23
23
|
* 0.01.
|
|
24
24
|
*/
|
|
25
25
|
export declare function doesVectorHaveLength(vector: Vector, threshold?: number): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Given an array of vectors, this helper function returns the closest one to a provided reference
|
|
28
|
+
* vector.
|
|
29
|
+
*
|
|
30
|
+
* @param referenceVector The vector to compare against.
|
|
31
|
+
* @param vectors The array of vectors to look through.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getClosestVectorTo(referenceVector: Vector, vectors: Vector[]): Vector | undefined;
|
|
26
34
|
/**
|
|
27
35
|
* Helper function to get a random vector between (-1, -1) and (1, 1).
|
|
28
36
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vector.d.ts","sourceRoot":"","sources":["../../../src/functions/vector.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,yBAAyB,EACzB,SAAS,EACV,MAAM,8BAA8B,CAAC;AAatC,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACvD,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC;CACnD,CAAC;AAKF,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQjD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAqBlE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,SAAS,SAAO,GACf,OAAO,CAET;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,SAAS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kBAAkB,CAChC,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,MAAM,EAAE,GAChB,MAAM,GAAG,SAAS,CAapB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,SAAS,GAAE,IAAI,GAAG,GAAqB,GACtC,QAAQ,CAAC,MAAM,CAAC,CAOlB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,gBAAgB,CAM5B;AAED,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,MAAM,CAE1D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAWhE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAEtE;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAG3D;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,MAAM,CAIpE"}
|
|
@@ -67,6 +67,23 @@ function ____exports.doesVectorHaveLength(self, vector, threshold)
|
|
|
67
67
|
end
|
|
68
68
|
return vector:Length() >= threshold
|
|
69
69
|
end
|
|
70
|
+
--- Given an array of vectors, this helper function returns the closest one to a provided reference
|
|
71
|
+
-- vector.
|
|
72
|
+
--
|
|
73
|
+
-- @param referenceVector The vector to compare against.
|
|
74
|
+
-- @param vectors The array of vectors to look through.
|
|
75
|
+
function ____exports.getClosestVectorTo(self, referenceVector, vectors)
|
|
76
|
+
local closestVector
|
|
77
|
+
local closestDistance = math.huge
|
|
78
|
+
for ____, vector in ipairs(vectors) do
|
|
79
|
+
local distance = referenceVector:Distance(vector)
|
|
80
|
+
if distance < closestDistance then
|
|
81
|
+
closestVector = vector
|
|
82
|
+
closestDistance = distance
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
return closestVector
|
|
86
|
+
end
|
|
70
87
|
--- Helper function to get a random vector between (-1, -1) and (1, 1).
|
|
71
88
|
--
|
|
72
89
|
-- To get random vectors with a bigger length, multiply this with a number.
|
package/package.json
CHANGED
package/src/functions/vector.ts
CHANGED
|
@@ -78,6 +78,31 @@ export function doesVectorHaveLength(
|
|
|
78
78
|
return vector.Length() >= threshold;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Given an array of vectors, this helper function returns the closest one to a provided reference
|
|
83
|
+
* vector.
|
|
84
|
+
*
|
|
85
|
+
* @param referenceVector The vector to compare against.
|
|
86
|
+
* @param vectors The array of vectors to look through.
|
|
87
|
+
*/
|
|
88
|
+
export function getClosestVectorTo(
|
|
89
|
+
referenceVector: Vector,
|
|
90
|
+
vectors: Vector[],
|
|
91
|
+
): Vector | undefined {
|
|
92
|
+
let closestVector: Vector | undefined;
|
|
93
|
+
let closestDistance = math.huge;
|
|
94
|
+
for (const vector of vectors) {
|
|
95
|
+
const distance = referenceVector.Distance(vector);
|
|
96
|
+
|
|
97
|
+
if (distance < closestDistance) {
|
|
98
|
+
closestVector = vector;
|
|
99
|
+
closestDistance = distance;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return closestVector;
|
|
104
|
+
}
|
|
105
|
+
|
|
81
106
|
/**
|
|
82
107
|
* Helper function to get a random vector between (-1, -1) and (1, 1).
|
|
83
108
|
*
|