summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-10-23 09:53:02 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-10-23 09:53:02 +0000
commit9d8a0e23a879caa50032bbafd5fd345732c4423b (patch)
treeeee1ab0d0ee0e4d00e4173f47d08b07f8813946a
parentc7cb2aa85e0f7b4584119cc96bb908799bdf1923 (diff)
downloadzetacomponents-graph-9d8a0e23a879caa50032bbafd5fd345732c4423b.zip
zetacomponents-graph-9d8a0e23a879caa50032bbafd5fd345732c4423b.tar.gz
- Fixed issue #11640: Polygon size reducement failes for very thin four edged
polygones
-rw-r--r--ChangeLog2
-rw-r--r--src/interfaces/driver.php41
-rw-r--r--tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonFourPointsNotFilledBorderSizeReducement.svg2
-rw-r--r--tests/driver_svg_test.php33
4 files changed, 66 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 6b8e820..98b10a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
1.2 - [RELEASEDATE]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- Fixed issue #11640: Polygon size reducement failes for very thin four edged
+ polygones
- Fixed issue #11511: Line thickness wan't used for rendering
- Fixed issue #11509: Typo in line chart option
- Implemented feature #10978: Add support for stacked bar charts
diff --git a/src/interfaces/driver.php b/src/interfaces/driver.php
index dfd8e1a..5eb6f03 100644
--- a/src/interfaces/driver.php
+++ b/src/interfaces/driver.php
@@ -105,6 +105,7 @@ abstract class ezcGraphDriver
// Build normalized vectors between polygon edge points
$vectors = array();
+ $vectorLength = array();
for ( $i = 0; $i < $pointCount; ++$i )
{
$nextPoint = ( $i + 1 ) % $pointCount;
@@ -112,7 +113,8 @@ abstract class ezcGraphDriver
->sub( $points[$i] );
// Throw exception if polygon is too small to reduce
- if ( $vectors[$i]->length() < $size )
+ $vectorLength[$i] = $vectors[$i]->length();
+ if ( $vectorLength[$i] < $size )
{
throw new ezcGraphReducementFailedException();
}
@@ -215,17 +217,32 @@ abstract class ezcGraphDriver
// point and the size as distance to move.
// point + v + size / tan( angle / 2 ) * startVector
$newPoint = clone $vectors[$next];
- $newPoints[$next] =
- $v ->add(
- $newPoint
- ->scalar(
- $size /
- tan(
- $lastVector->angle( $vectors[$next] ) / 2
- )
- )
- )
- ->add( $points[$next] );
+ $v ->add(
+ $newPoint
+ ->scalar(
+ $size /
+ tan(
+ $lastVector->angle( $vectors[$next] ) / 2
+ )
+ )
+ );
+
+ // A fast guess: If the movement of the point exceeds the length of
+ // the surrounding edge vectors the angle was to small to perform a
+ // valid size reducement. In this case we just fall back to the
+ // original point array.
+ //
+ // The correct way to check would be a test, if the calculated
+ // point is still in the original polygon, but a test for a point
+ // in a polygon is too expensive.
+ $movement = $v->length();
+ if ( ( $movement > $vectorLength[$last] ) &&
+ ( $movement > $vectorLength[$next] ) )
+ {
+ $v->unify()->scalar( min( $vectorLength[$last], $vectorLength[$next] ) );
+ }
+
+ $newPoints[$next] = $v->add( $points[$next] );
}
return $newPoints;
diff --git a/tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonFourPointsNotFilledBorderSizeReducement.svg b/tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonFourPointsNotFilledBorderSizeReducement.svg
new file mode 100644
index 0000000..c3c5d82
--- /dev/null
+++ b/tests/data/compare/ezcGraphSvgDriverTest_testDrawPolygonFourPointsNotFilledBorderSizeReducement.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 24.4367,27.7272 L 24.6906,27.9766 L 30.5106,22.4890 L 30.2567,22.2397 L 24.4367,27.7272 z " style="fill: none; stroke: #3465a4; stroke-width: 1; stroke-opacity: 0.50; stroke-linecap: round; stroke-linejoin: round;" id="ezcGraphPolygon_1"/><path d=" M 43.6544,8.6381 L 24.7929,28.0781 L 11.2929,41.5781 L 30.1544,22.1381 L 43.6544,8.6381 z " style="fill: #3465a4; fill-opacity: 0.50; stroke: none;" id="ezcGraphPolygon_2"/></g></svg>
diff --git a/tests/driver_svg_test.php b/tests/driver_svg_test.php
index 75233e4..16dedff 100644
--- a/tests/driver_svg_test.php
+++ b/tests/driver_svg_test.php
@@ -151,6 +151,39 @@ class ezcGraphSvgDriverTest extends ezcGraphTestCase
);
}
+ public function testDrawPolygonFourPointsNotFilledBorderSizeReducement()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.svg';
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 24.79289, 28.078128 ),
+ new ezcGraphCoordinate( 11.29289, 41.578128 ),
+ new ezcGraphCoordinate( 30.15439, 22.13813 ),
+ new ezcGraphCoordinate( 43.65439, 8.63813 ),
+ ),
+ ezcGraphColor::fromHex( '#3465A480' ),
+ false
+ );
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( 24.79289, 28.078128 ),
+ new ezcGraphCoordinate( 11.29289, 41.578128 ),
+ new ezcGraphCoordinate( 30.15439, 22.13813 ),
+ new ezcGraphCoordinate( 43.65439, 8.63813 ),
+ ),
+ ezcGraphColor::fromHex( '#3465A480' )
+ );
+
+ $this->driver->render( $filename );
+
+ $this->compare(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
+ );
+ }
+
public function testDrawPolygonThreePointsNotFilledReverse()
{
$filename = $this->tempDir . __FUNCTION__ . '.svg';
OpenPOWER on IntegriCloud