Skip to content

Commit ed910ae

Browse files
authored
Merge pull request #1 from adam-rumpf/dev
Minor edits, and adding a couple of utility functions.
2 parents 703f335 + 910aa72 commit ed910ae

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Adam Rumpf
3+
Copyright (c) 2021 Adam Rumpf
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ A variety of scripts dealing with sequences, functions, and sets, which may have
2222
Common array functions (such as searching and counting).
2323

2424
* [`_array_count`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_array_count/_array_count.gml): Counts the number of occurrences of a specified value in an array.
25+
* [`_array_function`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_array_function/_array_function.gml): Applies a given function to every element of a given array, and returns an array of results.
2526
* [`_array_index`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_array_index/_array_index.gml): Finds the first index at which a specified value occurs in an array (or -1 if not found). An optional argument allows the search to begin from a specified index.
2627
* [`_array_max`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_array_max/_array_max.gml): Returns the maximum value (or the index of the maximum value) in an array.
2728
* [`_array_min`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_array_min/_array_min.gml): Returns the minimum value (or the index of the minimum value) in an array.
@@ -43,6 +44,7 @@ Numerical algorithms for computational mathematics.
4344

4445
Common linear algebra algorithms for dealing with matrices and vectors. In all functions, _vectors_ are considered to be 1D arrays while _matrices_ are 2D arrays (i.e. arrays of arrays).
4546

47+
* [`_coordinate_remap`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_coordinate_remap/_coordinate_remap.gml): Remaps a coordinate from one rectangular region to another.
4648
* [`_linear_solve`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_linear_solve/_linear_solve.gml): Solves a linear system of the form _Ax = b_ (using [Gaussian elimination with partial pivoting](https://en.wikipedia.org/wiki/Pivot_element)).
4749
* [`_matrix_multiply`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_matrix_multiply/_matrix_multiply.gml): Performs matrix-matrix, matrix-vector, and vector-vector multiplication.
4850
* [`_matrix_transpose`](https://github.com/adam-rumpf/game-maker-scripts/blob/master/scripts/_matrix_transpose/_matrix_transpose.gml): Transposes a 2D matrix.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// @func _coordinate_remap(xi1, yi1, xi2, yi2, xf1, yf1, xf1, yf2, x, y)
2+
/// @desc Remaps a coordinate from one rectangular region to another.
3+
/// @param {real} xi1 Initial rectangular region's minimum x-value.
4+
/// @param {real} yi1 Initial rectangular region's minimum y-value.
5+
/// @param {real} xi2 Initial rectangular region's maximum x-value.
6+
/// @param {real} yi2 Initial rectangular region's maximum y-value.
7+
/// @param {real} xf1 Final rectangular region's minimum x-value.
8+
/// @param {real} yf1 Final rectangular region's minimum y-value.
9+
/// @param {real} xf2 Final rectangular region's maximum x-value.
10+
/// @param {real} yf2 Final rectangular region's maximum y-value.
11+
/// @param {real} x x-coordinate to be remapped.
12+
/// @param {real} y y-coordinate to be remapped.
13+
/// @return {real[]} Remapped coordinates of input point, as an ordered pair [x, y].
14+
15+
function _coordinate_remap(xi1, yi1, xi2, yi2, xf1, yf1, xf2, yf2, xx, yy)
16+
{
17+
// Calculate remapped coordinates
18+
var xf, yf;
19+
xf = ((xx - xi1)*(xf2 - xf1))/(xi2 - xi1) + xf1;
20+
yf = ((yy - yi1)*(yf2 - yf1))/(yi2 - yi1) + yf1;
21+
22+
return [xf, yf];
23+
}

scripts/_random_weighted_index/_random_weighted_index.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function _random_weighted_index(wt)
2323

2424
// Find which interval this number belongs to
2525
var i = 0;
26-
while (r > 0 && i < n)
26+
while ((r > 0) && (i < n))
2727
{
2828
r -= wt[i];
2929
i++;

scripts/_range/_range.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// @func _range(start, stop[, step]])
1+
/// @func _range(start, stop[, step])
22
/// @desc Generates an array of equally-spaced values over a specified range with a specified step size.
33
/// @param {real} start First value of array.
44
/// @param {real} stop Final value of array (if the step size evenly divides the array; otherwise gives an upper bound to the final value).

0 commit comments

Comments
 (0)