limit points to the limits of the monitor

pull/1857/head
Isaac Connor 2017-04-19 16:12:12 -04:00
parent c4ec01c0d2
commit 3db38eb474
3 changed files with 53 additions and 40 deletions

View File

@ -1755,6 +1755,25 @@ function coordsToPoints( $coords ) {
return( $points ); return( $points );
} }
function limitPoints( &$points, $min_x, $min_y, $max_x, $max_y ) {
foreach ( $points as &$point ) {
if ( $point['x'] < $min_x ) {
Debug('Limiting point x'.$point['x'].' to min_x ' . $min_x );
$point['x'] = $min_x;
} else if ( $point['x'] > $max_x ) {
Debug('Limiting point x'.$point['x'].' to max_x ' . $max_x );
$point['x'] = $max_x;
}
if ( $point['y'] < $min_y ) {
Debug('Limiting point y'.$point['y'].' to min_y ' . $min_y );
$point['y'] = $min_y;
} else if ( $point['y'] > $max_y ) {
Debug('Limiting point y'.$point['y'].' to max_y ' . $max_y );
$point['y'] = $max_y;
}
} // end foreach point
} // end function limitPoints( $points, $min_x, $min_y, $max_x, $max_y )
function getLanguages() { function getLanguages() {
$langs = array(); $langs = array();
foreach ( glob("lang/*_*.php") as $file ) { foreach ( glob("lang/*_*.php") as $file ) {

View File

@ -18,9 +18,8 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// //
if ( !canView( 'Monitors' ) ) if ( !canView( 'Monitors' ) ) {
{ $view = 'error';
$view = "error";
return; return;
} }
@ -34,29 +33,25 @@ $hicolor = '0x00ff00'; // Green
$presets = array(); $presets = array();
$presetNames = array(); $presetNames = array();
$presetNames[0] = translate('ChoosePreset'); $presetNames[0] = translate('ChoosePreset');
$sql = "select *, Units-1 as UnitsIndex, CheckMethod-1 as CheckMethodIndex from ZonePresets order by Id asc"; $sql = 'SELECT *, Units-1 AS UnitsIndex, CheckMethod-1 AS CheckMethodIndex FROM ZonePresets ORDER BY Id ASC';
foreach( dbFetchAll( $sql ) as $preset ) foreach( dbFetchAll( $sql ) as $preset ) {
{ $presetNames[$preset['Id']] = $preset['Name'];
$presetNames[$preset['Id']] = $preset['Name']; $presets[] = $preset;
$presets[] = $preset;
} }
$optTypes = array(); $optTypes = array();
foreach ( getEnumValues( 'Zones', 'Type' ) as $optType ) foreach ( getEnumValues( 'Zones', 'Type' ) as $optType ) {
{ $optTypes[$optType] = $optType;
$optTypes[$optType] = $optType;
} }
$optUnits = array(); $optUnits = array();
foreach ( getEnumValues( 'Zones', 'Units' ) as $optUnit ) foreach ( getEnumValues( 'Zones', 'Units' ) as $optUnit ) {
{ $optUnits[$optUnit] = $optUnit;
$optUnits[$optUnit] = $optUnit;
} }
$optCheckMethods = array(); $optCheckMethods = array();
foreach ( getEnumValues( 'Zones', 'CheckMethod' ) as $optCheckMethod ) foreach ( getEnumValues( 'Zones', 'CheckMethod' ) as $optCheckMethod ) {
{ $optCheckMethods[$optCheckMethod] = $optCheckMethod;
$optCheckMethods[$optCheckMethod] = $optCheckMethod;
} }
$monitor = new Monitor( $mid ); $monitor = new Monitor( $mid );
@ -66,14 +61,10 @@ $maxX = $monitor->Width()-1;
$minY = 0; $minY = 0;
$maxY = $monitor->Height()-1; $maxY = $monitor->Height()-1;
if ( !isset($newZone) ) if ( !isset($newZone) ) {
{ if ( $zid > 0 ) {
if ( $zid > 0 )
{
$zone = dbFetchOne( 'SELECT * FROM Zones WHERE MonitorId = ? AND Id=?', NULL, array( $monitor->Id(), $zid ) ); $zone = dbFetchOne( 'SELECT * FROM Zones WHERE MonitorId = ? AND Id=?', NULL, array( $monitor->Id(), $zid ) );
} } else {
else
{
$zone = array( $zone = array(
'Id' => 0, 'Id' => 0,
'Name' => translate('New'), 'Name' => translate('New'),
@ -104,17 +95,16 @@ if ( !isset($newZone) )
$zone['AreaCoords'] = preg_replace( '/\s+/', ',', $zone['Coords'] ); $zone['AreaCoords'] = preg_replace( '/\s+/', ',', $zone['Coords'] );
$newZone = $zone; $newZone = $zone;
} } # end if new Zone
//if ( !$points ) # Ensure Zone fits within the limits of the Monitor
//{ limitPoints( $newZone['Points'], $minX, $minY, $maxX, $maxY );
//$points = $zone['Points'];
//}
ksort( $newZone['Points'], SORT_NUMERIC ); ksort( $newZone['Points'], SORT_NUMERIC );
$newZone['Coords'] = pointsToCoords( $newZone['Points'] ); $newZone['Coords'] = pointsToCoords( $newZone['Points'] );
$newZone['Area'] = getPolyArea( $newZone['Points'] ); $newZone['Area'] = getPolyArea( $newZone['Points'] );
$newZone['AreaCoords'] = preg_replace( '/\s+/', ',', $newZone['Coords'] );
$selfIntersecting = isSelfIntersecting( $newZone['Points'] ); $selfIntersecting = isSelfIntersecting( $newZone['Points'] );
$focusWindow = true; $focusWindow = true;

View File

@ -18,23 +18,27 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// //
if ( !canView( 'Monitors' ) ) if ( !canView( 'Monitors' ) ) {
{ $view = 'error';
$view = "error"; return;
return;
} }
$mid = validInt($_REQUEST['mid']); $mid = validInt($_REQUEST['mid']);
$monitor = new Monitor( $mid ); $monitor = new Monitor( $mid );
# Width() and Height() are already rotated
$minX = 0;
$maxX = $monitor->Width()-1;
$minY = 0;
$maxY = $monitor->Height()-1;
$zones = array(); $zones = array();
foreach( dbFetchAll( 'select * from Zones where MonitorId = ? order by Area desc', NULL, array($mid) ) as $row ) foreach( dbFetchAll( 'SELECT * FROM Zones WHERE MonitorId=? ORDER BY Area DESC', NULL, array($mid) ) as $row ) {
{ $row['Points'] = coordsToPoints( $row['Coords'] );
if ( $row['Points'] = coordsToPoints( $row['Coords'] ) )
{ limitPoints( $row['Points'], $minX, $minY, $maxX, $maxY );
$row['AreaCoords'] = preg_replace( '/\s+/', ',', $row['Coords'] ); $row['Coords'] = pointsToCoords( $row['Points'] );
$zones[] = $row; $row['AreaCoords'] = preg_replace( '/\s+/', ',', $row['Coords'] );
} $zones[] = $row;
} }
$connkey = generateConnKey(); $connkey = generateConnKey();