From 1e7dec0db4b95ccd021b49334fd01b15128584f9 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Thu, 27 Oct 2016 16:35:50 -0400 Subject: [PATCH] Add and improve comments. --- src/quadFeature.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/quadFeature.js b/src/quadFeature.js index 59023840f0..16cb9585ef 100644 --- a/src/quadFeature.js +++ b/src/quadFeature.js @@ -163,15 +163,24 @@ var quadFeature = function (arg) { util.pointInPolygon(coordinate, poly2)) { indices.push(quad.idx); found.push(data[quad.idx]); + /* If a point is in the quad (based on pointInPolygon, above), check + * where in the quad it is located. We want to output coordinates + * where the upper-left is (0, 0) and the lower-right is (1, 1). */ coordbasis = util.pointTo2DTriangleBasis( coordinate, poly1[0], poly1[1], poly1[2]); if (!coordbasis || coordbasis.x + coordbasis.y > 1) { coordbasis = util.pointTo2DTriangleBasis( coordinate, poly2[2], poly2[1], poly2[0]); if (coordbasis) { + /* In the second triangle, (0, 0) is upper-right, (1, 0) is + * upper-left, and (0, 1) is lower-right. Invert x to get to + * the desired output coordinates. */ coordbasis.x = 1 - coordbasis.x; } } else { + /* In the first triangle, (0, 0) is lower-left, (1, 0) is lower- + * right, and (0, 1) is upper-left. Invert y to get to the + * desired output coordinates. */ coordbasis.y = 1 - coordbasis.y; } if (coordbasis) { @@ -258,7 +267,7 @@ var quadFeature = function (arg) { /** * Convert the current data set to a pair of arrays, one of quads that are - * solid color and one of qudas that have an image. All quads are objects + * solid color and one of quads that have an image. All quads are objects * with pos (a 12 value array containing 4 three-dimensional position * coordinates), and opacity. Color quads also have a color. Image quads * may have an image element, if the image is loaded. If it isn't, this @@ -292,7 +301,7 @@ var quadFeature = function (arg) { clrQuads = [], imgQuads = [], origin = [0, 0, 0], origindiag2, diag2; /* Keep track of images that we are using. This prevents creating - * additional Image elemnts for repeated urls. */ + * additional Image elements for repeated urls. */ m_this._objectListStart(m_images); $.each(data, function (i, d) { if (d._cachedQuad) {