summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-05-25 09:29:33 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-05-25 09:29:33 +0000
commit40967187c4276d08ade3efc26ded4a46d5085199 (patch)
treeaa37712cc321868d5bfdf6fb58762eef5b15da64
parent9d608ebc1f95c411add7ebdb3f4157d56ca9a7f9 (diff)
downloadzetacomponents-graph-40967187c4276d08ade3efc26ded4a46d5085199.zip
zetacomponents-graph-40967187c4276d08ade3efc26ded4a46d5085199.tar.gz
- Fixed issue #10846: Division by zero in polygon size reducement algorithm
for edges with an angle equals 0 degree.
-rw-r--r--ChangeLog2
-rw-r--r--src/interfaces/driver.php25
-rw-r--r--tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonBorderReducementWithRedundantPoints.svg2
-rw-r--r--tests/driver_svg_test.php23
4 files changed, 51 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 84a0d85..6818198 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,8 @@
- Fixed issue #10842: Pie charts fatal error with datasets with value sum <= 0
- Fixed issue #10848: Missing pie segment labels in pie charts with 3d
renderer
+- Fixed issue #10846: Division by zero in polygon size reducement algorithm
+ for edges with an angle equals 0 degree.
1.1beta1 - Monday 07 May 2007
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/interfaces/driver.php b/src/interfaces/driver.php
index a477eea..cb8857a 100644
--- a/src/interfaces/driver.php
+++ b/src/interfaces/driver.php
@@ -117,9 +117,9 @@ abstract class ezcGraphDriver
}
$vectors[$i]->unify();
+ // Remove point from list if it the same as the next point
if ( ( $vectors[$i]->x == $vectors[$i]->y ) && ( $vectors[$i]->x == 0 ) )
{
- // Remove point from list if it the same as the next point
$pointCount--;
if ( $i === 0 )
{
@@ -136,6 +136,29 @@ abstract class ezcGraphDriver
}
}
+ // Remove vectors and appendant point, if local angle equals zero
+ // dergrees.
+ for ( $i = 0; $i < $pointCount; ++$i )
+ {
+ $nextPoint = ( $i + 1 ) % $pointCount;
+
+ if ( ( abs( $vectors[$i]->x - $vectors[$nextPoint]->x ) < .0001 ) &&
+ ( abs( $vectors[$i]->y - $vectors[$nextPoint]->y ) < .0001 ) )
+ {
+ $pointCount--;
+
+ $points = array_merge(
+ array_slice( $points, 0, $i + 1 ),
+ array_slice( $points, $i + 2 )
+ );
+ $vectors = array_merge(
+ array_slice( $vectors, 0, $i + 1 ),
+ array_slice( $vectors, $i + 2 )
+ );
+ $i--;
+ }
+ }
+
// No reducements for lines
if ( $pointCount <= 2 )
{
diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonBorderReducementWithRedundantPoints.svg b/tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonBorderReducementWithRedundantPoints.svg
new file mode 100644
index 0000000..44b39bf
--- /dev/null
+++ b/tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonBorderReducementWithRedundantPoints.svg
@@ -0,0 +1,2 @@
+<?xml version="1.0"?>
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.0" id="ezcGraph"><defs/><g id="ezcGraphChart" color-rendering="optimizeQuality" shape-rendering="geometricPrecision" text-rendering="optimizeLegibility"><path d=" M 10.0000,55.0000 L 10.0000,10.0000 L 10.0000,55.0000 z " style="fill: none; stroke: #3465a4; stroke-width: 1; stroke-opacity: 1.00; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_1"/></g></svg>
diff --git a/tests/driver_svg_test.php b/tests/driver_svg_test.php
index 03e7734..67e0096 100644
--- a/tests/driver_svg_test.php
+++ b/tests/driver_svg_test.php
@@ -327,6 +327,29 @@ class ezcGraphSvgDriverTest extends ezcGraphTestCase
);
}
+ public function testDrawPolygonBorderReducementWithRedundantPoints()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 10, 10 ),
+ new ezcGraphCoordinate( 10, 15 ),
+ new ezcGraphCoordinate( 10, 50 ),
+ new ezcGraphCoordinate( 10, 55 ),
+ ),
+ ezcGraphColor::fromHex( '#3465A4' ),
+ false
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
public function testDrawCircleSectorAcuteNonFilled()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
OpenPOWER on IntegriCloud