galaxy.inc.php 28.7 KB
Newer Older
Feu's avatar
Feu committed
1 2
<?php

Feu's avatar
test  
Feu committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/* Copyright 2007
 *
 * - Julien Etelain < julien at pmad dot net >
 *
 * "AE Recherche & Developpement" : Galaxy
 *
 * Ce fichier fait partie du site de l'Association des étudiants
 * de l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */
27

Feu's avatar
Feu committed
28 29
define("GALAXY_SCORE_1PTPHOTO",1);
define("GALAXY_SCORE_PARRAINAGE",15);
30 31
define("GALAXY_SCORE_2ANNEESACTIFASSO",15);
define("GALAXY_SCORE_2ANNEESASSO",5);
Feu's avatar
Feu committed
32
define("GALAXY_MINSCORE",10);
Feu's avatar
Feu committed
33

34 35 36 37 38 39 40 41 42 43 44
/**
 * @defgroup useless Les trucs inutiles
 */

/**
 * Gestionnaire de Galaxy
 *
 *
 * @ingroup useless
 * @author Julien Etelain
 */
Feu's avatar
Feu committed
45 46 47 48
class galaxy
{
  var $db;
  var $dbrw;
49

Feu's avatar
Feu committed
50 51
  var $width;
  var $height;
52

Feu's avatar
test  
Feu committed
53
  var $done_pre_cycle;
54

Feu's avatar
Feu committed
55 56 57 58
  function galaxy ( &$db, &$dbrw )
  {
    $this->db = $db;
    $this->dbrw = $dbrw;
Feu's avatar
test  
Feu committed
59
    $this->done_pre_cycle=false;
60 61
  }

Feu's avatar
test  
Feu committed
62 63 64 65
  /**
   * Vérifie que des données puevent être montrés aux utilisateurs.
   * Pour cela vérifie qu'il existe des éléments avec des coordonnées en pixels.
   */
Feu's avatar
Feu committed
66 67 68 69 70 71 72
  function is_ready_public()
  {
    $req = new requete($this->db,"SELECT * FROM galaxy_star WHERE rx_star IS NOT NULL AND ry_star IS NOT NULL LIMIT 1");
    if ( $req->lines != 1 )
      return false;
    return true;
  }
Feu's avatar
fix  
Feu committed
73

74

Feu's avatar
fix  
Feu committed
75
  function scores ()
Feu's avatar
Feu committed
76 77
  {
    $liens = array();
78

Feu's avatar
Feu committed
79
    // 1- Cacul du score
80

Feu's avatar
Feu committed
81
    // a- Les photos : 1pt / n photo ensemble
Feu's avatar
Feu committed
82 83 84 85
    $req = new requete($this->db, "SELECT COUNT( * ) as c, p1.id_utilisateur as u1, p2.id_utilisateur as u2 ".
    "FROM `sas_personnes_photos` AS `p1` ".
    "JOIN `sas_personnes_photos` AS `p2` ON ( p1.id_photo = p2.id_photo ".
    "AND p1.id_utilisateur != p2.id_utilisateur ) ".
86
    "LEFT JOIN utilisateurs usr1 ON (p1.id_utilisateur = usr1.id_utilisateur) ".
mbriand's avatar
mbriand committed
87
    "LEFT JOIN utilisateurs usr2 ON (p2.id_utilisateur = usr2.id_utilisateur) ".
88 89
    "WHERE usr1.publique_utl != '0' ".
    "AND usr2.publique_utl != '0' ".
Feu's avatar
Feu committed
90
    "GROUP BY p1.id_utilisateur, p2.id_utilisateur");
91

Feu's avatar
Feu committed
92 93 94 95
    while ( $row = $req->get_row() )
    {
      $a = min($row['u1'],$row['u2']);
      $b = max($row['u1'],$row['u2']);
96

Feu's avatar
Feu committed
97
      $liens[$a][$b] = round($row['c']/GALAXY_SCORE_1PTPHOTO);
98 99
    }

Feu's avatar
Feu committed
100
    // b- Parrainage : n pt / relation parrain-fillot
101
    $req = new requete($this->db, "SELECT parrains.id_utilisateur as u1, id_utilisateur_fillot as u2 ".
Feu's avatar
Feu committed
102
    "FROM `parrains` ".
103
    "LEFT JOIN utilisateurs usr1 ON (parrains.id_utilisateur = usr1.id_utilisateur) ".
mbriand's avatar
mbriand committed
104
    "LEFT JOIN utilisateurs usr2 ON (id_utilisateur_fillot = usr2.id_utilisateur) ".
105 106 107
    "WHERE usr1.publique_utl != '0' ".
    "AND usr2.publique_utl != '0' ".
    "GROUP BY parrains.id_utilisateur, id_utilisateur_fillot");
Feu's avatar
Feu committed
108 109 110
    while ( $row = $req->get_row() )
    {
      $a = min($row['u1'],$row['u2']);
111 112
      $b = max($row['u1'],$row['u2']);

Feu's avatar
Feu committed
113
      if ( isset($liens[$a][$b]) )
Feu's avatar
Feu committed
114
        $liens[$a][$b] += GALAXY_SCORE_PARRAINAGE;
Feu's avatar
Feu committed
115
      else
Feu's avatar
Feu committed
116
        $liens[$a][$b] = GALAXY_SCORE_PARRAINAGE;
117 118
    }

Feu's avatar
Feu committed
119
    // c- associations et clubs : 1pt / n jours ensemble / assos
Feu's avatar
Feu committed
120 121 122 123
    $req = new requete($this->db,"SELECT a.id_utilisateur as u1,b.id_utilisateur as u2,
  SUM(DATEDIFF(LEAST(COALESCE(a.date_fin,NOW()),COALESCE(b.date_fin,NOW())),GREATEST(a.date_debut,b.date_debut))) AS together
  FROM asso_membre AS a
  JOIN asso_membre AS b ON
124 125
  (
  a.id_utilisateur < b.id_utilisateur
Feu's avatar
Feu committed
126
  AND a.id_asso = b.id_asso
127
  AND GREATEST(a.date_debut,b.date_debut) < LEAST(COALESCE(a.date_fin,NOW()),COALESCE(b.date_fin,NOW()))
Feu's avatar
Feu committed
128
  )
129
  LEFT JOIN utilisateurs usr1 ON (a.id_utilisateur = usr1.id_utilisateur)
mbriand's avatar
mbriand committed
130
  LEFT JOIN utilisateurs usr2 ON (b.id_utilisateur = usr2.id_utilisateur)
131 132
  WHERE usr1.publique_utl != '0'
  AND usr2.publique_utl != '0'
133
  AND NOT (a.role > 0 AND b.role > 0)
Feu's avatar
Feu committed
134 135
  GROUP BY a.id_utilisateur,b.id_utilisateur
  ORDER BY a.id_utilisateur,b.id_utilisateur");
136

Feu's avatar
Feu committed
137 138 139
    while ( $row = $req->get_row() )
    {
      $a = min($row['u1'],$row['u2']);
140 141
      $b = max($row['u1'],$row['u2']);

Feu's avatar
Feu committed
142
      if ( isset($liens[$a][$b]) )
143
        $liens[$a][$b] += round((1-exp(-$row['together']/365))*GALAXY_SCORE_2ANNEESASSO);
Feu's avatar
Feu committed
144
      else
145 146 147 148 149 150 151 152 153 154
        $liens[$a][$b] = round((1-exp(-$row['together']/365))*GALAXY_SCORE_2ANNEESASSO);
    }

  $req = new requete($this->db,"SELECT a.id_utilisateur as u1,b.id_utilisateur as u2,
  SUM(DATEDIFF(LEAST(COALESCE(a.date_fin,NOW()),COALESCE(b.date_fin,NOW())),GREATEST(a.date_debut,b.date_debut))) AS together
  FROM asso_membre AS a
  JOIN asso_membre AS b ON
  (
  a.id_utilisateur < b.id_utilisateur
  AND a.id_asso = b.id_asso
155
  AND GREATEST(a.date_debut,b.date_debut) < LEAST(COALESCE(a.date_fin,NOW()),COALESCE(b.date_fin,NOW()))
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  )
  LEFT JOIN utilisateurs usr1 ON (a.id_utilisateur = usr1.id_utilisateur)
  LEFT JOIN utilisateurs usr2 ON (b.id_utilisateur = usr2.id_utilisateur)
  WHERE usr1.publique_utl != '0'
  AND usr2.publique_utl != '0'
  AND a.role > 0
  AND b.role > 0
  GROUP BY a.id_utilisateur,b.id_utilisateur
  ORDER BY a.id_utilisateur,b.id_utilisateur");

    while ( $row = $req->get_row() )
    {
      $a = min($row['u1'],$row['u2']);
      $b = max($row['u1'],$row['u2']);

      if ( isset($liens[$a][$b]) )
        $liens[$a][$b] += round((1-exp(-$row['together']/365))*GALAXY_SCORE_2ANNEESACTIFASSO);
      else
        $liens[$a][$b] = round((1-exp(-$row['together']/365))*GALAXY_SCORE_2ANNEESACTIFASSO);
175 176
    }

Feu's avatar
Feu committed
177 178 179 180
    // 2- On vire les liens pas significatifs
    foreach ( $liens as $a => $data )
    {
      foreach ( $data as $b => $score )
Feu's avatar
Feu committed
181
        if ( $score < GALAXY_MINSCORE )
Feu's avatar
Feu committed
182 183
          unset($liens[$a][$b]);
    }
Feu's avatar
fix  
Feu committed
184 185 186

    return $liens;
  }
187 188


Feu's avatar
fix  
Feu committed
189 190 191 192 193
  /**
   * Initialise une nouvelle galaxy, le "big bang" en quelque sorte
   */
  function init ( )
  {
194 195
    new requete($this->dbrw,"TRUNCATE `galaxy_link`");
    new requete($this->dbrw,"TRUNCATE `galaxy_star`");
196

Feu's avatar
fix  
Feu committed
197
    $liens = $this->scores();
198

Feu's avatar
Feu committed
199 200 201 202 203 204
    // 3- On crée les peronnes requises
    $stars = array();
    foreach ( $liens as $a => $data )
    {
      if ( !isset($stars[$a]) )
        $stars[$a] = $a;
205

Feu's avatar
Feu committed
206 207 208 209
      foreach ( $data as $b => $score )
        if ( !isset($stars[$b]) )
          $stars[$b] = $b;
    }
210

Feu's avatar
Feu committed
211 212
    $gx=0;
    $gy=0;
213

Feu's avatar
Feu committed
214
    $width = floor(sqrt(count($stars)));
215

Feu's avatar
Feu committed
216 217 218 219 220 221 222 223 224
    foreach ( $stars as $id )
    {
      new insert($this->dbrw,"galaxy_star",array( "id_star"=>$id, "x_star" => $gx, "y_star" => $gy ));
      $gx++;
      if ( $gx > $width )
      {
        $gx=0;
        $gy++;
      }
225 226
    }

Feu's avatar
Feu committed
227 228 229 230
    // 4- On crée les liens
    foreach ( $liens as $a => $data )
      foreach ( $data as $b => $score )
        new insert($this->dbrw,"galaxy_link",array( "id_star_a"=>$a, "id_star_b"=>$b, "tense_link" => $score ));
231

Feu's avatar
Feu committed
232 233 234 235
    //fixe_star
    new requete($this->dbrw, "UPDATE galaxy_star SET max_tense_star = ( SELECT MAX(tense_link) FROM galaxy_link WHERE id_star_a=id_star OR id_star_b=id_star )");
    new requete($this->dbrw, "UPDATE galaxy_star SET sum_tense_star = ( SELECT SUM(tense_link) FROM galaxy_link WHERE id_star_a=id_star OR id_star_b=id_star )");
    new requete($this->dbrw, "UPDATE galaxy_star SET nblinks_star = ( SELECT COUNT(*) FROM galaxy_link WHERE id_star_a=id_star OR id_star_b=id_star )");
Feu's avatar
test  
Feu committed
236
    new requete($this->dbrw, "UPDATE galaxy_link SET max_tense_stars_link=( SELECT AVG(max_tense_star) FROM galaxy_star WHERE id_star=id_star_a OR id_star=id_star_b )");
237

Feu's avatar
test  
Feu committed
238
    new requete($this->dbrw, "UPDATE galaxy_link SET ideal_length_link=0.25+((1-(tense_link/max_tense_stars_link))*30)");
Feu's avatar
Feu committed
239
    new requete($this->dbrw, "DELETE FROM galaxy_star WHERE nblinks_star = 0");
240

Feu's avatar
fix  
Feu committed
241
  }
242

Feu's avatar
fix  
Feu committed
243 244 245
  function update()
  {
    $liens = $this->scores();
246

Feu's avatar
fix  
Feu committed
247 248 249 250 251
    $stars = array();
    foreach ( $liens as $a => $data )
    {
      if ( !isset($stars[$a]) )
        $stars[$a] = $a;
252

Feu's avatar
fix  
Feu committed
253 254 255 256
      foreach ( $data as $b => $score )
        if ( !isset($stars[$b]) )
          $stars[$b] = $b;
    }
257

Feu's avatar
fix  
Feu committed
258
    $prev_stars = array();
Bate's avatar
Bate committed
259
    //$prev_liens = array();
260

Feu's avatar
fix  
Feu committed
261
    $req = new requete($this->dbrw, "SELECT id_star FROM galaxy_star");
262

Feu's avatar
fix  
Feu committed
263 264
    while ( list($id) = $req->get_row() )
      $prev_stars[$id] = $id;
265

Bate's avatar
Bate committed
266
    //$req = new requete($this->dbrw, "SELECT id_star_a, id_star_b, tense_link FROM galaxy_link");
267

Bate's avatar
Bate committed
268 269
    //while ( list($a,$b,$c) = $req->get_row() )
      //$prev_liens[$a][$b] = $c;
270

Feu's avatar
fix  
Feu committed
271 272 273 274
    // enlève les anciennes étoiles
    foreach ( $prev_stars as $id )
      if ( !isset($stars[$id]) )
        new delete($this->dbrw,"galaxy_star",array( "id_star"=>$id) );
275

Feu's avatar
fix  
Feu committed
276
    // enlève les anciens liens
Bate's avatar
Bate committed
277 278 279 280 281 282
    //foreach ( $prev_liens as $a => $data )
      //foreach ( $data as $b => $score )
        //if (!isset($liens[$a][$b]) )
          //new delete($this->dbrw,"galaxy_link",array( "id_star_a"=>$a, "id_star_b"=>$b));
    
    $req = new requete($this->dbrw, "DELETE FROM galaxy_link");
283

284 285 286 287 288 289 290 291 292 293 294
    if ( count($prev_stars) == 0 )
    {
      $x1=0;
      $y1=0;
      $cw=10;
    }
    else
    {
      list($x1,$y1,$x2,$y2) = $this->limits();
      $cw = max($x2-$x1,$y2-$y1);
    }
295

Feu's avatar
fix  
Feu committed
296 297 298 299 300 301
    // ajoute les nouvelles étoiles
    foreach ( $stars as $id )
      if ( !isset($prev_stars[$id]) )
      {
        list($nx,$ny) = $this->find_low_density_point($x1,$y1,$cw);
        new insert($this->dbrw,"galaxy_star",array( "id_star"=>$id, "x_star" => $nx, "y_star" => $ny ));
302 303 304
      }

    // ajoute les nouveaux liens
Feu's avatar
fix  
Feu committed
305 306
    foreach ( $liens as $a => $data )
      foreach ( $data as $b => $score )
Bate's avatar
Bate committed
307
        //if (!isset($prev_liens[$a][$b]) )
Feu's avatar
fix  
Feu committed
308
          new insert($this->dbrw,"galaxy_link",array( "id_star_a"=>$a, "id_star_b"=>$b, "tense_link" => $score ));
309

Feu's avatar
fix  
Feu committed
310
    // met à jour les anciens liens
Bate's avatar
Bate committed
311 312 313 314
    //foreach ( $liens as $a => $data )
    //  foreach ( $data as $b => $score )
    //    if ( isset($prev_liens[$a][$b]) && $prev_liens[$a][$b] != $score )
    //      new update($this->dbrw,"galaxy_link",array("tense_link"=>$score),array("id_star_a"=>$a,"id_star_b"=>$b));
315 316

    // met à jour les champs calculés
Feu's avatar
fix  
Feu committed
317 318 319 320
    new requete($this->dbrw, "UPDATE galaxy_star SET max_tense_star = ( SELECT MAX(tense_link) FROM galaxy_link WHERE id_star_a=id_star OR id_star_b=id_star )");
    new requete($this->dbrw, "UPDATE galaxy_star SET sum_tense_star = ( SELECT SUM(tense_link) FROM galaxy_link WHERE id_star_a=id_star OR id_star_b=id_star )");
    new requete($this->dbrw, "UPDATE galaxy_star SET nblinks_star = ( SELECT COUNT(*) FROM galaxy_link WHERE id_star_a=id_star OR id_star_b=id_star )");
    new requete($this->dbrw, "UPDATE galaxy_link SET max_tense_stars_link=( SELECT AVG(max_tense_star) FROM galaxy_star WHERE id_star=id_star_a OR id_star=id_star_b )");
321

Feu's avatar
fix  
Feu committed
322 323
    new requete($this->dbrw, "UPDATE galaxy_link SET ideal_length_link=0.25+((1-(tense_link/max_tense_stars_link))*30)");
    new requete($this->dbrw, "DELETE FROM galaxy_star WHERE nblinks_star = 0");
324

Feu's avatar
Feu committed
325
  }
326 327 328



Feu's avatar
test  
Feu committed
329 330 331 332 333 334 335 336
  /**
   * Préalable à une série de cycles.
   * Efface les coordonnées en pixels de tous les éléments.
   */
  function pre_cycle ()
  {
    // s'assure que is_ready_public() renverra false pendant les calculs
    // se débloquera après un appel à pre_render() (causé par render() ou mini_render())
Bate's avatar
Bate committed
337
    //new requete($this->dbrw,"UPDATE `galaxy_star` SET rx_star = NULL, ry_star = NULL");
Feu's avatar
test  
Feu committed
338 339
    $this->done_pre_cycle=true;
  }
340

Feu's avatar
test  
Feu committed
341 342 343 344 345 346
  /**
   * Cycle.
   * Produit les mouvements des objets par le calculs des contraintes aux quels ils sont soumis.
   * Attention: Il n'y a pas de notion d'accélération ou d'intertie.
   * Provoque un appel de pre_cycle() s'il n'a pas eu lieu.
   */
Feu's avatar
Feu committed
347 348
  function cycle ( $detectcollision=false )
  {
Feu's avatar
test  
Feu committed
349 350
    if ( !$this->done_pre_cycle )
      $this->pre_cycle();
351

Feu's avatar
test  
Feu committed
352 353 354 355
    new requete($this->dbrw,"UPDATE galaxy_link, galaxy_star AS a, galaxy_star AS b SET ".
    "vx_link = b.x_star-a.x_star, ".
    "vy_link = b.y_star-a.y_star  ".
    "WHERE a.id_star = galaxy_link.id_star_a AND b.id_star = galaxy_link.id_star_b");
Bate's avatar
Bate committed
356
    new requete($this->dbrw,"UPDATE galaxy_link SET length_link = IF(vx_link = 0 AND vy_link = 0, 1, SQRT(POW(vx_link,2)+POW(vy_link,2)))");
357 358


Bate's avatar
Bate committed
359
    new requete($this->dbrw,"UPDATE galaxy_star, (SELECT g.id_star AS id, SUM(tense_link*vx_link/POW(length_link,3)) AS ax, SUM(tense_link*vy_link/POW(length_link,3)) AS ay
Bate's avatar
Bate committed
360
							FROM galaxy_link 
Bate's avatar
Bate committed
361 362 363 364 365 366 367 368
							JOIN galaxy_star AS g
							WHERE galaxy_link.id_star_a = g.id_star 
							OR galaxy_link.id_star_b = g.id_star
							GROUP BY id) b
				SET 
				galaxy_star.dx_star = IFNULL(galaxy_star.dx_star + b.ax / galaxy_star.sum_tense_star,0), 
				galaxy_star.dy_star = IFNULL(galaxy_star.dy_star + b.ay / galaxy_star.sum_tense_star,0)
				WHERE galaxy_star.id_star = b.id");
Bate's avatar
Bate committed
369 370
    $req = new requete($this->db,"SELECT COUNT(*), AVG(x_star/sum_tense_star), AVG(y_star/sum_tense_star), SUM(sum_tense_star), MAX(x_star), MIN(x_star), MAX(y_star), MIN(y_star) FROM galaxy_star");
    list( $star_count, $center_x, $center_y, $sum_tense , $max_x, $min_x, $max_y, $min_y) = $req->get_row();
Bate's avatar
Bate committed
371 372
    $safe_area_x = ($max_x - $min_x)/ sqrt($star_count);
    $safe_area_y = ($max_y - $min_y)/ sqrt($star_count);
Bate's avatar
Bate committed
373 374
    new requete($this->dbrw,"UPDATE 	galaxy_star a, 
					(SELECT a.id_star AS id_a, b.id_star AS id_b, 
Bate's avatar
Bate committed
375 376
						SUM(b.sum_tense_star * (a.x_star - b.x_star)/POW(SQRT(POW(a.x_star - b.x_star,2) + POW(a.y_star - b.y_star, 2)),3)) AS ax, 
						SUM(b.sum_tense_star * (a.y_star - b.y_star)/POW(SQRT(POW(a.x_star - b.x_star,2) + POW(a.y_star - b.y_star, 2)),3)) AS ay 
Bate's avatar
Bate committed
377
					 FROM galaxy_star AS a, galaxy_star AS b 
Bate's avatar
Bate committed
378 379
					WHERE b.x_star < a.x_star + '$safe_area_x' AND b.x_star > a.x_star - '$safe_area_x'
					AND b.y_star < a.y_star + '$safe_area_y' AND b.y_star > a.y_star - '$safe_area_y'
Bate's avatar
Bate committed
380
					GROUP BY id_a) b 
Bate's avatar
Bate committed
381 382
				SET a.dx_star = a.dx_star + IFNULL(ax,0)/sum_tense_star, 
				dy_star = dy_star + IFNULL(ay,0)/sum_tense_star
Bate's avatar
Bate committed
383
				WHERE a.id_star = b.id_a");
Bate's avatar
Bate committed
384 385

    new requete($this->dbrw,"UPDATE galaxy_star SET
Bate's avatar
Bate committed
386 387
				dx_star = IFNULL(dx_star + $sum_tense*(x_star - '$center_x')/( (POW(x_star - '$center_x' , 2) + POW(y_star - '$center_y' , 2))*sum_tense_star) - LOG(sum_tense_star)*(x_star - '$center_x')/( SQRT(POW(x_star - '$center_x' , 2) + POW(y_star - '$center_y' , 2))*sum_tense_star),0), 
				dy_star = IFNULL(dy_star + $sum_tense*(y_star - '$center_y')/( (POW(x_star - '$center_x' , 2) + POW(y_star - '$center_y' , 2))*sum_tense_star) - LOG(sum_tense_star)*(y_star - '$center_y')/( SQRT(POW(x_star - '$center_x' , 2) + POW(y_star - '$center_y' , 2))*sum_tense_star),0)"); 
Bate's avatar
Bate committed
388

Bate's avatar
Bate committed
389 390 391 392
    //new requete($this->dbrw,"UPDATE galaxy_star SET dx_star = 200 WHERE dx_star > 200");
    //new requete($this->dbrw,"UPDATE galaxy_star SET dx_star = -200 WHERE dx_star < -200");
    //new requete($this->dbrw,"UPDATE galaxy_star SET dy_star = 200 WHERE dy_star > 200");
    //new requete($this->dbrw,"UPDATE galaxy_star SET dy_star = -200 WHERE dy_star < -200");
Bate's avatar
Bate committed
393
    new requete($this->dbrw,"UPDATE galaxy_star SET
Bate's avatar
Bate committed
394 395
				x_star = IFNULL(x_star,RAND()) + dx_star,
				y_star = IFNULL(y_star,RAND()) + dy_star");
396 397


Feu's avatar
test  
Feu committed
398
  }
399

Feu's avatar
test  
Feu committed
400 401 402
  /**
   * Provoque un deplacement aleatoir de tous les éléments (+/- 5 sur x et y)
   */
Feu's avatar
test  
Feu committed
403 404
  function rand()
  {
405
    new requete($this->dbrw, "UPDATE `galaxy_star` SET x_star = x_star+5-( RAND( ) *10 ), y_star = y_star+5-( RAND( ) *10) WHERE fixe_star != 1");
Feu's avatar
Feu committed
406
  }
407

Feu's avatar
test  
Feu committed
408 409 410 411 412
  /**
   * Optimise le placement de certains éléments en les renvoyant dans des zones peu denses
   */
  function optimize()
  {
413

Feu's avatar
test  
Feu committed
414
    $req = new requete($this->db,
415
    "SELECT a.id_star, b.x_star, b.y_star, l.ideal_length_link
Feu's avatar
test  
Feu committed
416 417 418 419 420 421 422 423 424 425
     FROM galaxy_star AS a
     INNER JOIN galaxy_link AS l ON ( l.id_star_a = a.id_star )
     INNER JOIN galaxy_star AS b ON ( l.id_star_b = b.id_star )
     WHERE a.nblinks_star=1 AND b.nblinks_star > 1
     UNION
     SELECT b.id_star, a.x_star, a.y_star, l.ideal_length_link
     FROM galaxy_star AS b
     INNER JOIN galaxy_link AS l ON ( l.id_star_b = b.id_star )
     INNER JOIN galaxy_star AS a ON ( l.id_star_a = a.id_star )
     WHERE b.nblinks_star=1 AND a.nblinks_star > 1");
426

Feu's avatar
test  
Feu committed
427 428
    while ( list($id,$cx,$cy,$l) = $req->get_row() )
    {
429
      list($nx,$ny) = $this->find_low_density_point($cx-$l,$cy-$l,$l*2,$id);
Feu's avatar
test  
Feu committed
430 431 432
      $nx = sprintf("%.f",$nx);
      $ny = sprintf("%.f",$ny);
      //echo "MOVE $id to ($nx, $ny)<br/>\n";
433
      new requete ( $this->dbrw, "UPDATE galaxy_star set x_star=$nx, y_star=$ny WHERE id_star=$id AND fixe_star != 1");
Feu's avatar
test  
Feu committed
434
    }
435

Feu's avatar
test  
Feu committed
436
    list($x1,$y1,$x2,$y2) = $this->limits();
Feu's avatar
fix  
Feu committed
437
    $cw = max($x2-$x1,$y2-$y1);
438

Feu's avatar
test  
Feu committed
439
    $req = new requete($this->db,
440
    "SELECT a.id_star, b.id_star, b.x_star, b.y_star
Feu's avatar
test  
Feu committed
441 442 443 444
     FROM galaxy_star AS a
     INNER JOIN galaxy_link AS l ON ( l.id_star_a = a.id_star )
     INNER JOIN galaxy_star AS b ON ( l.id_star_b = b.id_star )
     WHERE a.nblinks_star=1 AND b.nblinks_star=1");
445

Feu's avatar
test  
Feu committed
446 447 448 449 450
    while ( list($ida,$idb,$x,$y) = $req->get_row() )
    {
      $d = $this->get_density ( $x-1, $y-1, $x+1, $y+1, "$ida,$idb" );
      if ( $d > 5 )
      {
451
        list($nx,$ny) = $this->find_low_density_point($x1,$y1,$cw,"$ida,$idb");
Feu's avatar
test  
Feu committed
452
        //echo "MOVE $ida,$idb to ($nx, $ny)<br/>\n";
453
        new requete ( $this->dbrw, "UPDATE galaxy_star set x_star=$nx, y_star=$ny WHERE id_star=$ida OR id_star=$idb fixe_star != 1");
Feu's avatar
test  
Feu committed
454 455
      }
    }
456

Feu's avatar
test  
Feu committed
457
  }
458

Feu's avatar
Feu committed
459 460 461 462
  function star_color ( $img, $i )
  {
    if ( $i > 800 )
      return imagecolorallocate($img, 255, 255, 255);
463

Feu's avatar
Feu committed
464
    if ( $i > 700 )
465 466
      return imagecolorallocate($img, (($i-700)*255/100), (($i-700)*255/100), 255);

Feu's avatar
Feu committed
467 468
    if ( $i > 400 )
      return imagecolorallocate($img, 255 -(($i-400)*255/300), 255 -(($i-400)*255/300), ($i-400)*255/300);
469

Feu's avatar
Feu committed
470
    if ( $i > 35 )
471 472 473
      return imagecolorallocate($img, 255, ($i-35)*255/365, 0);

    return imagecolorallocate($img, $i*255/36, 0, 0);
Feu's avatar
Feu committed
474
  }
475

Feu's avatar
test  
Feu committed
476 477 478
  /**
   * Préalable au rendu: fixe les coordonnées en pixels de tous les éléments
   */
Bate's avatar
Bate committed
479
  function pre_render ($tx=10000)
Feu's avatar
Feu committed
480 481 482
  {
    $req = new requete($this->db, "SELECT MIN(x_star), MIN(y_star), MAX(x_star), MAX(y_star) FROM  galaxy_star");
    list($top_x,$top_y,$bottom_x,$bottom_y) = $req->get_row();
483

Feu's avatar
Feu committed
484 485 486 487
    $top_x = floor($top_x);
    $top_y = floor($top_y);
    $bottom_x = ceil($bottom_x);
    $bottom_y = ceil($bottom_y);
488

Bate's avatar
Bate committed
489 490 491 492 493
    $div_x = false;
    $div_y = false;
    $mult_x = 10000/($bottom_x-$top_x);
    if(abs($mult_x) < 1)
    {
Bate's avatar
Bate committed
494
	$mult_x = 1/$mult_x;
Bate's avatar
Bate committed
495
        $div_x = true;
Bate's avatar
Bate committed
496
    	$mult_x = ceil($mult_x);
Bate's avatar
Bate committed
497
    }
Bate's avatar
Bate committed
498 499
    else
    	$mult_x = floor($mult_x);
Bate's avatar
Bate committed
500 501 502 503 504
    $mult_y = 10000/($bottom_y-$top_y);
    if(abs($mult_y)  < 1)
    {
	$mult_y = 1/$mult_y;
        $div_y = true;
Bate's avatar
Bate committed
505
    	$mult_y = ceil($mult_y);
Bate's avatar
Bate committed
506
    }
Bate's avatar
Bate committed
507 508
    else
	$mult_y = floor($mult_y);
509

Bate's avatar
Bate committed
510 511 512
    $this->width = $tx;//($bottom_x-$top_x)*$tx;
    $this->height = $tx;//($bottom_y-$top_y)*$tx;

Bate's avatar
Bate committed
513
    $req=new requete($this->dbrw,"UPDATE galaxy_star SET rx_star = (x_star-'$top_x') ".($div_x?"/":"*")." '$mult_x', ry_star = (y_star-'$top_y') ".($div_y?"/":"*")." '$mult_y'");
Feu's avatar
Feu committed
514
  }
515

Feu's avatar
test  
Feu committed
516 517
  /**
   * Fait le rendu de la mignature de galaxy
Feu's avatar
Feu committed
518
   */
Feu's avatar
wip  
Feu committed
519 520 521 522
  function mini_render ( $mini_target="mini_galaxy_temp.png")
  {
    if ( empty($this->width) || empty($this->height) )
      $this->pre_render();
523

Feu's avatar
test  
Feu committed
524
    $img = imagecreatetruecolor($this->width/50,$this->height/50);
Feu's avatar
wip  
Feu committed
525 526
    $bg = imagecolorallocate($img, 0, 0, 0);
    imagefill($img, 0, 0, $bg);
Feu's avatar
test  
Feu committed
527
    $req = new requete($this->db, "SELECT FLOOR(rx_star/50),FLOOR(ry_star/50),SUM(sum_tense_star) FROM  galaxy_star GROUP BY FLOOR(rx_star/50),FLOOR(ry_star/50)");
528

Feu's avatar
wip  
Feu committed
529
    while ( list($x,$y,$d) = $req->get_row() )
Feu's avatar
wip  
Feu committed
530
      imagesetpixel($img,$x,$y,$this->star_color($img,$d));
531

Feu's avatar
test  
Feu committed
532 533
    $img2 = imagecreatetruecolor($this->width/100,$this->height/100);
    imagecopyresampled($img2,$img,0,0,0,0,$this->width/100,$this->height/100,$this->width/50,$this->height/50);
Antoine Tenart's avatar
kwain  
Antoine Tenart committed
534
    if(is_writable("/var/www/ae2/data/img/"))
BenC's avatar
BenC committed
535
      imagepng($img2,$mini_target);
536 537
    imagedestroy($img2);
    imagedestroy($img);
Feu's avatar
wip  
Feu committed
538
  }
539

Feu's avatar
test  
Feu committed
540 541 542
  /**
   * Fait le rendu de l'image globale de galaxy
   */
Bate's avatar
Bate committed
543
  function render ($target="galaxy_temp.png", $complete = true,$ratio = 1)
Feu's avatar
Feu committed
544 545 546
  {
    if ( empty($this->width) || empty($this->height) )
      $this->pre_render();
547

Bate's avatar
Bate committed
548
    $img = imagecreatetruecolor($this->width/$ratio,$this->height/$ratio);
549

Feu's avatar
Feu committed
550 551
    if ( $img === false )
    {
Bate's avatar
Bate committed
552
      echo "failed imagecreatetruecolor($width/$ratio,$height/$ratio);";
Feu's avatar
Feu committed
553 554
      exit();
    }
555

Feu's avatar
Feu committed
556 557
    $bg = imagecolorallocate($img, 0, 0, 0);
    $textcolor = imagecolorallocate($img, 255, 255, 255);
Feu's avatar
test  
Feu committed
558
    $wirecolor = imagecolorallocate($img, 32, 32, 32);
559

Feu's avatar
Feu committed
560
    imagefill($img, 0, 0, $bg);
561

Feu's avatar
Feu committed
562
    imagestring($img, 1, 0, 0, "AE R&D - GALAXY", $textcolor);
563

Feu's avatar
Feu committed
564 565 566
    for($i=0;$i<820;$i++)
    {
      imageline($img,$i,10,$i,20,$this->star_color($img,$i));
567

Feu's avatar
Feu committed
568 569 570
      if ( $i %100 == 0)
        imagestring($img, 1, $i, 22, $i, $textcolor);
    }
Bate's avatar
Bate committed
571
    if($complete)
Feu's avatar
Feu committed
572
    {
Bate's avatar
Bate committed
573 574 575 576 577 578 579 580
	    $req = new requete($this->db, "SELECT ABS(length_link-ideal_length_link) as ex, ".
	    "a.rx_star as x1, a.ry_star as y1, b.rx_star as x2, b.ry_star as y2 ".
	    "FROM  galaxy_link ".
	    "INNER JOIN galaxy_star AS a ON (a.id_star=galaxy_link.id_star_a) ".
	    "INNER JOIN galaxy_star AS b ON (b.id_star=galaxy_link.id_star_b)");

	    while ( $row = $req->get_row() )
	    {
Bate's avatar
Bate committed
581
	      imageline ($img, $row['x1']/$ratio, $row['y1']/$ratio, $row['x2']/$ratio, $row['y2']/$ratio, $wirecolor );
Bate's avatar
Bate committed
582
	    }
583 584
    }

Feu's avatar
Feu committed
585 586 587
    $req = new requete($this->db, "SELECT ".
    "rx_star, ry_star, sum_tense_star  ".
    "FROM  galaxy_star");
588

Feu's avatar
Feu committed
589 590
    while ( $row = $req->get_row() )
    {
Bate's avatar
Bate committed
591
      imagefilledellipse ($img, $row['rx_star']/$ratio, $row['ry_star']/$ratio, 5, 5, $this->star_color($img,$row['sum_tense_star']) );
Feu's avatar
Feu committed
592
    }
593

Bate's avatar
Bate committed
594
    if($complete)
Feu's avatar
Feu committed
595
    {
Bate's avatar
Bate committed
596 597 598 599 600 601 602 603
	    $req = new requete($this->db, "SELECT ".
	    "rx_star, ry_star, COALESCE(surnom_utbm, CONCAT(prenom_utl,' ',nom_utl), alias_utl) AS nom ".
	    "FROM  galaxy_star ".
	    "INNER JOIN utilisateurs ON (utilisateurs.id_utilisateur=galaxy_star.id_star)".
	    "INNER JOIN `utl_etu_utbm` ON (`utl_etu_utbm`.`id_utilisateur` = `utilisateurs`.`id_utilisateur`)");

	    while ( $row = $req->get_row() )
	    {
Bate's avatar
Bate committed
604
	      imagestring($img, 1, $row['rx_star']/$ratio+5, $row['ry_star']/$ratio-3,  utf8_decode($row['nom']), $textcolor);
Bate's avatar
Bate committed
605
	    }
Feu's avatar
Feu committed
606
    }
607

Feu's avatar
Feu committed
608 609 610 611
    if ( is_null($target) )
      imagepng($img);
    else
      imagepng($img,$target);
Feu's avatar
wip  
Feu committed
612

Feu's avatar
Feu committed
613
    imagedestroy($img);
614

Feu's avatar
Feu committed
615
  }
616

Feu's avatar
test  
Feu committed
617 618 619
  /**
   * Fait le rendu d'une zone de galaxy
   */
Feu's avatar
Feu committed
620
  function render_area ( $tx, $ty, $w, $h, $target=null, $highlight=null )
Feu's avatar
Feu committed
621
  {
Feu's avatar
Feu committed
622
    $x1 = $tx-100; // Pour les textes
Feu's avatar
Feu committed
623 624 625
    $y1 = $ty-3;
    $x2 = $tx+$w+3;
    $y2 = $ty+$h+3;
626

Feu's avatar
Feu committed
627
    $img = imagecreatetruecolor($w,$h);
628

Feu's avatar
Feu committed
629 630 631
    $bg = imagecolorallocate($img, 0, 0, 0);
    $textcolor = imagecolorallocate($img, 255, 255, 255);
    $wirecolor = imagecolorallocate($img, 32, 32, 32);
632 633 634

    imagefill($img, 0, 0, $bg);

Feu's avatar
Feu committed
635 636 637 638 639
    $req = new requete($this->db, "SELECT ABS(length_link-ideal_length_link) as ex, ".
    "a.rx_star as x1, a.ry_star as y1, b.rx_star as x2, b.ry_star as y2 ".
    "FROM  galaxy_link ".
    "INNER JOIN galaxy_star AS a ON (a.id_star=galaxy_link.id_star_a) ".
    "INNER JOIN galaxy_star AS b ON (b.id_star=galaxy_link.id_star_b)");
640

Feu's avatar
Feu committed
641 642
    while ( $row = $req->get_row() )
    {
643 644 645
      imageline ($img, $row['x1']-$tx, $row['y1']-$ty, $row['x2']-$tx, $row['y2']-$ty, $wirecolor );
    }

Feu's avatar
Feu committed
646
    if ( is_null($highlight ) ) // Normal render
Feu's avatar
Feu committed
647
    {
Feu's avatar
Feu committed
648 649 650 651
      $req = new requete($this->db, "SELECT ".
      "rx_star, ry_star, sum_tense_star  ".
      "FROM  galaxy_star ".
      "WHERE rx_star >= $x1 AND rx_star <= $x2 AND ry_star >= $y1 AND ry_star <= $y2");
652

Feu's avatar
Feu committed
653
      while ( $row = $req->get_row() )
654 655
        imagefilledellipse ($img, $row['rx_star']-$tx, $row['ry_star']-$ty, 5, 5, $this->star_color($img,$row['sum_tense_star']) );

Feu's avatar
Feu committed
656
      $req = new requete($this->db, "SELECT ".
mbriand's avatar
mbriand committed
657
      "rx_star, ry_star, COALESCE(surnom_utbm, CONCAT(prenom_utl,' ',nom_utl), alias_utl) AS nom ".
Feu's avatar
Feu committed
658 659
      "FROM  galaxy_star ".
      "INNER JOIN utilisateurs ON (utilisateurs.id_utilisateur=galaxy_star.id_star) ".
mbriand's avatar
mbriand committed
660
      "LEFT JOIN `utl_etu_utbm` ON (`utl_etu_utbm`.`id_utilisateur` = `utilisateurs`.`id_utilisateur`)".
661 662
      "WHERE rx_star >= $x1 AND rx_star <= $x2 AND ry_star >= $y1 AND ry_star <= $y2" );

Feu's avatar
Feu committed
663 664
      while ( $row = $req->get_row() )
        imagestring($img, 1, $row['rx_star']+5-$tx, $row['ry_star']-3-$ty,  utf8_decode($row['nom']), $textcolor);
665

Feu's avatar
Feu committed
666
    }
Feu's avatar
Feu committed
667
    else
Feu's avatar
Feu committed
668
    {
Feu's avatar
Feu committed
669
      $ids = implode(",",$highlight);
670

Feu's avatar
test  
Feu committed
671
      $wirecolor = imagecolorallocate($img, 64, 64, 64);
Feu's avatar
Feu committed
672 673 674 675 676 677

      $req = new requete($this->db, "SELECT ABS(length_link-ideal_length_link) as ex, ".
      "a.rx_star as x1, a.ry_star as y1, b.rx_star as x2, b.ry_star as y2 ".
      "FROM  galaxy_link ".
      "INNER JOIN galaxy_star AS a ON (a.id_star=galaxy_link.id_star_a) ".
      "INNER JOIN galaxy_star AS b ON (b.id_star=galaxy_link.id_star_b) ".
Feu's avatar
test  
Feu committed
678
      "WHERE a.id_star = ".$highlight[0]." OR b.id_star = ".$highlight[0]."");
679

Feu's avatar
Feu committed
680
      while ( $row = $req->get_row() )
681 682
        imageline ($img, $row['x1']-$tx, $row['y1']-$ty, $row['x2']-$tx, $row['y2']-$ty, $wirecolor );

Feu's avatar
Feu committed
683
      $textcolor = imagecolorallocate($img, 128, 128, 128);
684

Feu's avatar
Feu committed
685 686 687 688
       $req = new requete($this->db, "SELECT ".
      "rx_star, ry_star, sum_tense_star  ".
      "FROM  galaxy_star ".
      "WHERE id_star NOT IN ($ids) AND rx_star >= $x1 AND rx_star <= $x2 AND ry_star >= $y1 AND ry_star <= $y2");
689

Feu's avatar
Feu committed
690
      while ( $row = $req->get_row() )
691 692
        imagefilledellipse ($img, $row['rx_star']-$tx, $row['ry_star']-$ty, 5, 5, $this->star_color($img,$row['sum_tense_star']) );

Feu's avatar
Feu committed
693
      $req = new requete($this->db, "SELECT ".
mbriand's avatar
mbriand committed
694
      "rx_star, ry_star, COALESCE(surnom_utbm, CONCAT(prenom_utl,' ',nom_utl), alias_utl) AS nom ".
Feu's avatar
Feu committed
695 696
      "FROM  galaxy_star ".
      "INNER JOIN utilisateurs ON (utilisateurs.id_utilisateur=galaxy_star.id_star) ".
mbriand's avatar
mbriand committed
697
      "LEFT JOIN `utl_etu_utbm` ON (`utl_etu_utbm`.`id_utilisateur` = `utilisateurs`.`id_utilisateur`)".
698 699
      "WHERE id_star NOT IN ($ids) AND rx_star >= $x1 AND rx_star <= $x2 AND ry_star >= $y1 AND ry_star <= $y2" );

Feu's avatar
Feu committed
700 701
      while ( $row = $req->get_row() )
        imagestring($img, 1, $row['rx_star']+5-$tx, $row['ry_star']-3-$ty,  utf8_decode($row['nom']), $textcolor);
702

Feu's avatar
Feu committed
703
      $textcolor = imagecolorallocate($img, 255, 255, 255);
704

Feu's avatar
Feu committed
705 706 707 708
       $req = new requete($this->db, "SELECT ".
      "rx_star, ry_star, sum_tense_star  ".
      "FROM  galaxy_star ".
      "WHERE id_star IN ($ids) AND rx_star >= $x1 AND rx_star <= $x2 AND ry_star >= $y1 AND ry_star <= $y2");
709

Feu's avatar
Feu committed
710
      while ( $row = $req->get_row() )
711 712
        imagefilledellipse ($img, $row['rx_star']-$tx, $row['ry_star']-$ty, 5, 5, $this->star_color($img,$row['sum_tense_star']) );

Feu's avatar
Feu committed
713
      $req = new requete($this->db, "SELECT ".
mbriand's avatar
mbriand committed
714
      "rx_star, ry_star, COALESCE(surnom_utbm, CONCAT(prenom_utl,' ',nom_utl), alias_utl) AS nom ".
Feu's avatar
Feu committed
715 716
      "FROM  galaxy_star ".
      "INNER JOIN utilisateurs ON (utilisateurs.id_utilisateur=galaxy_star.id_star) ".
mbriand's avatar
mbriand committed
717
      "LEFT JOIN `utl_etu_utbm` ON (`utl_etu_utbm`.`id_utilisateur` = `utilisateurs`.`id_utilisateur`)".
718 719
      "WHERE id_star IN ($ids) AND rx_star >= $x1 AND rx_star <= $x2 AND ry_star >= $y1 AND ry_star <= $y2" );

Feu's avatar
Feu committed
720 721
      while ( $row = $req->get_row() )
        imagestring($img, 1, $row['rx_star']+5-$tx, $row['ry_star']-3-$ty,  utf8_decode($row['nom']), $textcolor);
722

Feu's avatar
Feu committed
723
    }
Feu's avatar
Feu committed
724

Feu's avatar
Feu committed
725 726 727 728
    if ( is_null($target) )
      imagepng($img);
    else
      imagepng($img,$target);
729 730 731

    imagedestroy($img);

Feu's avatar
Feu committed
732 733
  }

Feu's avatar
test  
Feu committed
734 735 736
  /**
   * Calcule le nombre d'objet dans la zone donnée.
   */
Feu's avatar
Feu committed
737 738
  function get_density ( $x1, $y1, $x2, $y2, $except=null )
  {
Feu's avatar
Feu committed
739 740 741 742
    $x1 = str_replace(",",".",sprintf("%.f",$x1));
    $y1 = str_replace(",",".",sprintf("%.f",$y1));
    $x2 = str_replace(",",".",sprintf("%.f",$x2));
    $y2 = str_replace(",",".",sprintf("%.f",$y2));
743

Feu's avatar
test  
Feu committed
744
    //echo "get_density($x1,$y1,$x2,$y2) = ";
745

Feu's avatar
Feu committed
746 747 748 749 750 751 752 753 754
    if (is_null($except) )
      $req = new requete($this->db, "SELECT ".
        "COUNT(*)  ".
        "FROM  galaxy_star ".
        "WHERE x_star >= $x1 AND x_star < $x2 AND y_star >= $y1 AND y_star < $y2");
    else
      $req = new requete($this->db, "SELECT ".
        "COUNT(*)  ".
        "FROM  galaxy_star ".
Feu's avatar
Feu committed
755
        "WHERE id_star NOT IN (".$except.") AND x_star >= $x1 AND x_star < $x2 AND y_star >= $y1 AND y_star < $y2");
756

Feu's avatar
Feu committed
757
    list($count) = $req->get_row();
758

Feu's avatar
test  
Feu committed
759
    //echo $count."<br/>\n";
760

Feu's avatar
Feu committed
761 762
    return $count;
  }
763

Feu's avatar
test  
Feu committed
764 765 766
  /**
   * Cherche un point où la densité est faible dans la zone donnée.
   */
Feu's avatar
Feu committed
767 768 769 770 771
  function find_low_density_point ( $x, $y, $s, $except=null )
  {
    $ld = null;
    $lx = null;
    $ly = null;
772

Feu's avatar
Feu committed
773 774
    $cx = $x;
    $cy = $y;
775

Feu's avatar
Feu committed
776 777 778 779
    for($cx=$x;$cx<$x+$s;$cx+=$s/3)
    {
      for($cy=$y;$cy<$y+$s;$cy+=$s/3)
      {
Feu's avatar
Feu committed
780
        $d = $this->get_density($cx,$cy,$cx+($s/3),$cy+($s/3), $except);
Feu's avatar
Feu committed
781
        if ( $d == 0 )
782 783
          return array($cx+($s/6),$cy+($s/6));

Feu's avatar
Feu committed
784 785
        if ( is_null($ld) || $ld > $d )
        {
786
          $lx = $cx;
Feu's avatar
Feu committed
787 788 789 790 791
          $ly = $cy;
          $ld = $d;
        }
      }
    }
792

Feu's avatar
Feu committed
793
    if ( $s < 0.001 )
794 795
      return array($lx+($s/6),$ly+($s/6));

Feu's avatar
Feu committed
796 797
    return $this->find_low_density_point($lx,$ly,$s/3, $except);
  }
798

Feu's avatar
Feu committed
799 800 801 802 803
  function limits()
  {
    $req = new requete($this->db, "SELECT MIN(x_star), MIN(y_star), MAX(x_star), MAX(y_star) FROM  galaxy_star");
    return $req->get_row();
  }
804

Bate's avatar
Bate committed
805 806 807 808 809 810
  function get_size()
  {
    list( $min_x, $min_y, $max_x, $max_y ) = $this->limits();
    return max($max_x-$min_x, $max_y - $min_y);
  }

Feu's avatar
Feu committed
811 812 813 814 815
}




BenC's avatar
BenC committed
816
?>