summaryrefslogtreecommitdiffstats
path: root/src/interfaces
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2007-05-10 09:52:09 +0000
committerKore Nordmann <github@kore-nordmann.de>2007-05-10 09:52:09 +0000
commit9fe5c1ce375e75ce093ace1f251fc54bf391b5c8 (patch)
tree31e193c19dd67fd638c965d18cac99a91826dcf1 /src/interfaces
parentf01b8b1bdfb55dd7e77c8b9eec8def3989a6560c (diff)
downloadzetacomponents-graph-9fe5c1ce375e75ce093ace1f251fc54bf391b5c8.zip
zetacomponents-graph-9fe5c1ce375e75ce093ace1f251fc54bf391b5c8.tar.gz
- Fixed issue #10746: Border size reducement algorithm fails for polygones
with edge lengths < reducement # Modifications in comparision files because some invisible small shapes # were not rendered any more
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/driver.php55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/interfaces/driver.php b/src/interfaces/driver.php
index 04025ac..a477eea 100644
--- a/src/interfaces/driver.php
+++ b/src/interfaces/driver.php
@@ -95,6 +95,7 @@ abstract class ezcGraphDriver
*
* @param array( ezcGraphCoordinate ) $points
* @param float $size
+ * @throws ezcGraphReducementFailedException
* @return array( ezcGraphCoordinate )
*/
protected function reducePolygonSize( array $points, $size )
@@ -107,8 +108,14 @@ abstract class ezcGraphDriver
{
$nextPoint = ( $i + 1 ) % $pointCount;
$vectors[$i] = ezcGraphVector::fromCoordinate( $points[$nextPoint] )
- ->sub( $points[$i] )
- ->unify();
+ ->sub( $points[$i] );
+
+ // Throw exception if polygon is too small to reduce
+ if ( $vectors[$i]->length() < $size )
+ {
+ throw new ezcGraphReducementFailedException();
+ }
+ $vectors[$i]->unify();
if ( ( $vectors[$i]->x == $vectors[$i]->y ) && ( $vectors[$i]->x == 0 ) )
{
@@ -218,6 +225,7 @@ abstract class ezcGraphDriver
* @param mixed $startAngle
* @param mixed $endAngle
* @param mixed $size
+ * @throws ezcGraphReducementFailedException
* @return array
*/
protected function reduceEllipseSize( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, $size )
@@ -254,6 +262,49 @@ abstract class ezcGraphDriver
$centerMovement = clone $unifiedStartVector;
$newCenter = $v->add( $centerMovement->scalar( $size / tan( ( $endAngle - $startAngle ) / 2 ) ) )->add( $center );
+ // Test if center is still inside the ellipse, otherwise the sector
+ // was to small to be reduced
+ $innerBoundingBoxSize = 0.7 * min( $width, $height );
+ if ( ( $newCenter->x < ( $center->x + $innerBoundingBoxSize ) ) &&
+ ( $newCenter->x > ( $center->x - $innerBoundingBoxSize ) ) &&
+ ( $newCenter->y < ( $center->y + $innerBoundingBoxSize ) ) &&
+ ( $newCenter->y > ( $center->y - $innerBoundingBoxSize ) ) )
+ {
+ // Point is in inner bounding box -> everything is OK
+ }
+ elseif ( ( $newCenter->x < ( $center->x - $width ) ) ||
+ ( $newCenter->x > ( $center->x + $width ) ) ||
+ ( $newCenter->y < ( $center->y - $height ) ) ||
+ ( $newCenter->y > ( $center->y + $height ) ) )
+ {
+ // Quick bounding box check
+ throw new ezcGraphReducementFailedException();
+ }
+ else
+ {
+ // Perform exact check
+ $distance = new ezcGraphVector(
+ $newCenter->x - $center->x,
+ $newCenter->y - $center->y
+ );
+
+ // Convert elipse to circle for correct angle calculation
+ $direction = clone $distance;
+ $direction->y *= ( $width / $height );
+ $angle = $direction->angle( new ezcGraphVector( 0, 1 ) );
+
+ $outerPoint = new ezcGraphVector(
+ sin( $angle ) * $width,
+ cos( $angle ) * $height
+ );
+
+ // Point is not in ellipse any more
+ if ( $distance->x > $outerPoint->x )
+ {
+ throw new ezcGraphReducementFailedException();
+ }
+ }
+
// Use start spanning vector and its orthogonal vector to calculate
// new start point
$newStartPoint = clone $oldStartPoint;
OpenPOWER on IntegriCloud