From 8aba7e1123962037cd79e0ed0cb80d1303b3bb4f Mon Sep 17 00:00:00 2001 From: elexis Date: Fri, 10 Nov 2017 17:17:59 +0000 Subject: [PATCH] Further clarify geometric meaning of the river painting in rP11137 and r20429. Refer to the normalized river vector instead of the river vector divided by the length of the river. Rename mag to magnitude. git-svn-id: https://svn.wildfiregames.com/public/ps/trunk@20435 3db68df2-c116-0410-a063-a993310a9797 --- binaries/data/mods/public/globalscripts/vector.js | 12 ++++++------ binaries/data/mods/public/maps/random/rmgen/gaia_terrain.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/binaries/data/mods/public/globalscripts/vector.js b/binaries/data/mods/public/globalscripts/vector.js index 9bac1ed091..0f0f85926f 100644 --- a/binaries/data/mods/public/globalscripts/vector.js +++ b/binaries/data/mods/public/globalscripts/vector.js @@ -63,11 +63,11 @@ Vector2D.prototype.div = function(f) Vector2D.prototype.normalize = function() { - var mag = this.length(); - if (!mag) + let magnitude = this.length(); + if (!magnitude) return this; - return this.div(mag); + return this.div(magnitude); }; /** @@ -260,11 +260,11 @@ Vector3D.prototype.div = function(f) Vector3D.prototype.normalize = function() { - var mag = this.length(); - if (!mag) + let magnitude = this.length(); + if (!magnitude) return this; - return this.div(mag); + return this.div(magnitude); }; // Numeric 3D info functions (non-mutating) diff --git a/binaries/data/mods/public/maps/random/rmgen/gaia_terrain.js b/binaries/data/mods/public/maps/random/rmgen/gaia_terrain.js index 8a8f9fe0a4..94c2c51789 100644 --- a/binaries/data/mods/public/maps/random/rmgen/gaia_terrain.js +++ b/binaries/data/mods/public/maps/random/rmgen/gaia_terrain.js @@ -363,8 +363,8 @@ function paintRiver(args) let mapSize = getMapSize(); let vecStart = new Vector2D(args.startX, args.startZ).mult(mapSize); let vecEnd = new Vector2D(args.endX, args.endZ).mult(mapSize); - let vecRiver = Vector2D.sub(vecStart, vecEnd); - let riverLength = vecRiver.length(); + let riverLength = vecStart.distanceTo(vecEnd); + let unitVecRiver = Vector2D.sub(vecStart, vecEnd).normalize(); // Describe river boundaries. let riverMinX = Math.min(vecStart.x, vecEnd.x); @@ -381,10 +381,10 @@ function paintRiver(args) let vecPoint = new Vector2D(ix, iz); // Compute the shortest distance to the river. - let distanceToRiver = vecRiver.cross(Vector2D.sub(vecPoint, vecEnd)) / riverLength; + let distanceToRiver = unitVecRiver.cross(Vector2D.sub(vecPoint, vecEnd)); // Closest point on the river (i.e the foot of the perpendicular). - let river = Vector2D.sub(vecPoint, vecRiver.perpendicular().mult(distanceToRiver / riverLength)); + let river = Vector2D.sub(vecPoint, unitVecRiver.perpendicular().mult(distanceToRiver)); // Only process points that actually are perpendicular with the river. if (river.x < riverMinX || river.x > riverMaxX || -- 2.11.4.GIT