| OLD | NEW |
| 1 // The functions in this file are intended to be used to test non-complex polygo
ns | 1 // The functions in this file are intended to be used to test non-complex polygo
ns |
| 2 // where horizontal lines that overlap the polygon only cross the polygon twice. | 2 // where horizontal lines that overlap the polygon only cross the polygon twice. |
| 3 function createPolygon(vertices) { | 3 function createPolygon(vertices) { |
| 4 var xCoordinates = vertices.map( function(p) { return p.x; } ); | 4 var xCoordinates = vertices.map( function(p) { return p.x; } ); |
| 5 var yCoordinates = vertices.map( function(p) { return p.y; } ); | 5 var yCoordinates = vertices.map( function(p) { return p.y; } ); |
| 6 return { | 6 return { |
| 7 vertices: vertices, | 7 vertices: vertices, |
| 8 minX: Math.min.apply(null, xCoordinates), | 8 minX: Math.min.apply(null, xCoordinates), |
| 9 maxX: Math.max.apply(null, xCoordinates), | 9 maxX: Math.max.apply(null, xCoordinates), |
| 10 minY: Math.min.apply(null, yCoordinates), | 10 minY: Math.min.apply(null, yCoordinates), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 return i1; | 99 return i1; |
| 100 | 100 |
| 101 return [Math.max(i1[0], i2[0]), Math.min(i1[1], i2[1])]; | 101 return [Math.max(i1[0], i2[0]), Math.min(i1[1], i2[1])]; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Generate an "X X ..." string that contains enough characters to fill the poly
gon. Each | 104 // Generate an "X X ..." string that contains enough characters to fill the poly
gon. Each |
| 105 // character occupies a lineHeight size square cell, the top of first line of ch
aracters is aligned | 105 // character occupies a lineHeight size square cell, the top of first line of ch
aracters is aligned |
| 106 // with the the polygon's bounds minimum Y value, and each line of characters fi
lls the interior | 106 // with the the polygon's bounds minimum Y value, and each line of characters fi
lls the interior |
| 107 // of the polygon. | 107 // of the polygon. |
| 108 | 108 |
| 109 function generatePolygonContentString(polygon, lineheight) { | 109 function generatePolygonContentString(polygon, lineHeight) { |
| 110 var result = ""; | 110 var result = ""; |
| 111 | 111 |
| 112 for (var y = polygon.minY; y < polygon.maxY; y += lineHeight) { | 112 for (var y = polygon.minY; y < polygon.maxY; y += lineHeight) { |
| 113 var xIntercepts = polygonLineIntercepts(polygon, y, lineHeight); | 113 var xIntercepts = polygonLineIntercepts(polygon, y, lineHeight); |
| 114 var lengthInCells = Math.floor(xIntercepts[1] / lineHeight) - Math.ceil(
xIntercepts[0] / lineHeight); | 114 var lengthInCells = Math.floor(xIntercepts[1] / lineHeight) - Math.ceil(
xIntercepts[0] / lineHeight); |
| 115 for (var i = 0; i < lengthInCells / 2; i++) | 115 for (var i = 0; i < lengthInCells / 2; i++) |
| 116 result += "X "; // all lines end in a space, to enable line breakin
g | 116 result += "X "; // all lines end in a space, to enable line breakin
g |
| 117 } | 117 } |
| 118 | 118 |
| 119 return result; | 119 return result; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 positionInformativeText("informative-text", stylesheet, polygon, lineHeight) | 238 positionInformativeText("informative-text", stylesheet, polygon, lineHeight) |
| 239 } | 239 } |
| 240 | 240 |
| 241 function createPolygonShapeInsideTestCaseExpected() { | 241 function createPolygonShapeInsideTestCaseExpected() { |
| 242 var stylesheet = document.getElementById("stylesheet").sheet; | 242 var stylesheet = document.getElementById("stylesheet").sheet; |
| 243 var polygon = createPolygon(vertices); | 243 var polygon = createPolygon(vertices); |
| 244 generateSimulatedPolygonShapeInsideElement("polygon-shape-inside", styleshee
t, polygon, lineHeight); | 244 generateSimulatedPolygonShapeInsideElement("polygon-shape-inside", styleshee
t, polygon, lineHeight); |
| 245 generatePolygonSVGElements("polygon-svg-shape", stylesheet, polygon, lineHei
ght); | 245 generatePolygonSVGElements("polygon-svg-shape", stylesheet, polygon, lineHei
ght); |
| 246 positionInformativeText("informative-text", stylesheet, polygon, lineHeight) | 246 positionInformativeText("informative-text", stylesheet, polygon, lineHeight) |
| 247 } | 247 } |
| OLD | NEW |