Page MenuHomeCode

No OneTemporary

This document is not UTF8. It was detected as ISO-8859-1 (Latin 1) and converted to UTF8 for display.
diff --git a/dev/quux.php b/dev/quux.php
--- a/dev/quux.php
+++ b/dev/quux.php
@@ -1,130 +1,138 @@
<?php
require_once('includes/objects/ship.php');
require_once('includes/objects/port.php');
require_once('includes/objects/application.php');
require_once('includes/objects/content.php');
require_once('includes/objects/message.php');
require_once('includes/objects/invite.php');
require_once('includes/cache/cache.php');
-
+
include('controllers/header.php');
-
- $case = 'index_scenes';
-
+
+ $case = 'GeoPointPolarZ';
+
switch ($case) {
+ case 'GeoPointPolarZ':
+ require_once('includes/geo/pointPolarZ.php');
+ echo "<H2>GeoPointPolarZ</H2>";
+ $point = GeoPointPolarZ::fromString("(48, 30°, 3)");
+ printf("Secteur T%dC%d, zone %d-%d");
+ dprint_r($point);
+ break;
+
case 'index_scenes':
$time[] = microtime();
require_once('includes/geo/scene.php');
require_once('includes/geo/sceneindex.php');
$cache = Cache::load();
if ($index = $cache->get('GeoSceneIndex')) {
$index = unserialize($index);
} else {
$index = GeoSceneIndex::Load(SCENE_DIR);
$cache->set('GeoSceneIndex', serialize($index));
}
$time[] = microtime();
echo '<H2>GeoSceneIndex</H2>';
dprint_r($index);
echo '<H2>Time (ms)</H2>';
dprint_r(1000 * ($time[1] - $time[0]));
- dieprint_r($time);
+ dprint_r($time);
break;
-
+
case 'travel':
require_once('includes/travel/travel.php');
$travel = Travel::load();
dieprint_r($travel);
break;
-
+
case 'spherical':
require_once('includes/geo/galaxy.php');
echo '<H2>Spherical coordinates test</H2>';
echo '<table cellpadding=8>';
echo "<tr><th>Name</th><th>Type</th><th>Cartesian coords</th><th>Spherical I</th><th>Spherical II</th><th>Pencil coordinates</th></tr>";
$objects = GeoGalaxy::get_coordinates();
foreach ($objects as $row) {
echo "<tr><th style='text-align: left'>$row[0]</th><td>$row[1]</td><td>$row[2]</td>";
$pt = $row[2];
echo '<td>(', implode(', ', $pt->to_spherical()), ')</td>';
echo '<td>(', implode(', ', $pt->to_spherical2()), ')</td>';
$pt->translate(500, 300, 200, 2);
echo '<td>', $pt, '</td>';
echo '</tr>';
}
echo '</table>';
break;
case 'travel':
require_once('includes/travel/travel.php');
require_once('includes/travel/place.php');
$cache = Cache::load();
$travel = $cache->get('zed_travel');
if ($travel == '') {
$travel_nocached = new Travel();
$travel_nocached->load_xml("content/travel.xml");
$cache->set('zed_travel', serialize($travel_nocached));
} else {
$travel = unserialize($travel);
}
dieprint_r($travel);
break;
case 'perso.create.notify':
$testperso = Perso::get(4733);
$message = new Message();
$message->from = 0;
$message->to = invite::who_invited(4733);
$url = get_server_url() . get_url('who', $testperso->nickname);
$message->text = sprintf(lang_get('InvitePersoCreated'), $testperso->name, $url);
$message->send();
dieprint_r($message);
break;
case 'pushdata';
echo '
<h2>/api.php/app/pushdata</h2>
<form method="post" action="/api.php/app/pushdata?mode=file&key=37d839ba-f9fc-42ca-a3e8-28053e979b90" enctype="multipart/form-data">
<input type="file" name="datafile" /><br />
<input type="submit" value="Send file" />
</form>
';
break;
case 'thumbnail':
$content = new Content(1);
dprint_r($content);
$content->generate_thumbnail();
break;
case 'port':
echo '<h2>Port::from_location test</h2>';
$locations = array("B00002", "B00002123", "B00001001", "xyz: [800, 42, 220]");
foreach ($locations as $location) {
dprint_r(Port::from_location($location));
}
break;
case 'ext':
$file = 'dev/foo.tar';
echo "<h2>$file</h2>";
echo "<h3>.tar.bz2</h3>";
echo ereg('\.tar\.bz2$', $file);
echo "<h3>.tar</h3>";
echo ereg('\.tar$', $file);
break;
case 'app':
echo Application::from_api_key("37d839ba-f9fc-42ca-a3e8-28053e979b90")->generate_userkey();
break;
case '':
dieprint_r("No case currently selected.");
break;
}
include('controllers/footer.php');
-?>
\ No newline at end of file
+?>
diff --git a/includes/geo/octocube.php b/includes/geo/octocube.php
--- a/includes/geo/octocube.php
+++ b/includes/geo/octocube.php
@@ -1,77 +1,143 @@
<?php
/**
* Geo octocube class.
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* @package Zed
* @subpackage Geo
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
/**
* Geo octocube class
*
* An octocube is a cube divided in 8 parts (sliced in two in x, y and z)
*
* Its coordinate (0, 0, 0) is the octocube centrum.
*/
class GeoOctocube {
/**
* Gets the sector from the (x, y, z) specified coordinates
*
* Sector will be:
* <code>
* // _____ _____
* // / 5 / 6 /|
* // /- - -/- - -/ |
* // /_____/____ /| |
* // | | | |/|
* // | 7 | 8 | / | 2
* // |_____|_____|/| |
* // | | | |/
* // | 3 | 4 | /
* // |_____|_____|/
* </code>
*
* @param int $x the x coordinate
* @param int $y the y coordinate
* @param int $z the z coordinate
* @return int the number of the sector (0 if x = y = z 0 ; otherwise, 1 to 8)
*/
static function get_sector ($x, $y, $z) {
//Cube centrum
if ($x == 0 && $y == 0 && $z == 0) return 0;
//One of the 8 cubes
$sector = 1;
if ($x >= 0) $sector++; //we're at right
if ($y < 0) $sector += 2; //we're at bottom
if ($z >= 0) $sector += 4; //we're on the top layer
return $sector;
}
/**
* Gets the sector from the (x, y, z) specified coordinates
* @see get_sector
- *
- * @param GeoPoint3D $pt the x, y, z coordinates
+ *
+ * @param mixed $pt a GeoPoint3D object for the x, y, z coordinates or a parsable string
* @return int the number of the sector (0 if x = y = z 0 ; otherwise, 1 to 8)
*/
static function get_sector_from_point3D ($pt) {
- return get_sector($pt->x, $pt->y, $pt->z);
+ if (is_string($pt)) {
+ $pt = GeoPoint3D::fromString($pt);
+ }
+ return self::get_sector($pt->x, $pt->y, $pt->z);
+ }
+
+ /**
+ * Gets the base vector for the specified sector
+ *
+ * @param int $sector the sector number (0-8)
+ * @return array if the sector is 0, (0, 0, 0) ; otherwise, an array with three signed 1 values.
+ *
+ * Example code:
+ *
+ * $vector = GeoOctocube::get_base_vector(4);
+ * //$vector is a (1, -1, -1) array
+ */
+ static function get_base_vector ($sector) {
+ switch ($sector) {
+ case 0: return array(0, 0, 0);
+ case 1: return array(-1, 1, -1);
+ case 2: return array(1, 1, -1);
+ case 3: return array(-1, -1, -1);
+ case 4: return array(1, -1, -1);
+ case 5: return array(-1, 1, 1);
+ case 6: return array(1, 1, 1);
+ case 7: return array(-1, -1, 1);
+ case 8: return array(1, -1, 1);
+ default: message_die(GENERAL_ERROR, "Invalid sector: $sector", "GeoOctocube::get_base_vector");
+ }
+ }
+
+
+ /**
+ * Gets SQL RLIKE pattern for the specified sector
+ *
+ * @param int $sector the sector number (0-8)
+ * @param int $z if not null, limits the query to the specified z coordinate [optional]
+ * @return string the LIKE q[0-9]+uery
+ */
+ static function get_rlike_pattern_from_sector ($sector, $z = null) {
+ if ($sector == 0) return "(0, 0, 0)";
+
+ $vector = self::get_base_vector($sector);
+
+ //x
+ if ($vector[0] == 1)
+ $query = "([0-9]+, ";
+ else
+ $query = "(-[0-9]+, ";
+
+ //y
+ if ($vector[1] == 1)
+ $query .= "[0-9]+, ";
+ else
+ $query .= "-[0-9]+, ";
+
+ //z
+ if ($z !== null) {
+ $query .= "$z)";
+ } elseif ($vector[2] == "1") {
+ $query .= "[0-9]+)";
+ } else {
+ $query .= "-[0-9]+)";
+ }
+
+ return $query;
}
}
?>
diff --git a/includes/geo/pointPolarZ.php b/includes/geo/pointPolarZ.php
new file mode 100644
--- /dev/null
+++ b/includes/geo/pointPolarZ.php
@@ -0,0 +1,376 @@
+<?php
+
+/**
+ * Geo point polar+z class.
+ *
+ * Zed. The immensity of stars. The HyperShip. The people.
+ *
+ * (c) 2010, Dereckson, some rights reserved.
+ * Released under BSD license.
+ *
+ * @package Zed
+ * @subpackage Geo
+ * @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
+ * @copyright 2010 Sébastien Santoro aka Dereckson
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD
+ * @version 0.1
+ * @link http://scherzo.dereckson.be/doc/zed
+ * @link http://zed.dereckson.be/
+ * @filesource
+ */
+
+require_once("point3D.php");
+
+/**
+ * Geo point polar+z class.
+ *
+ * This class represents a r, ρ, z point.
+ *
+ * They are useful to express coordinates in a cylinder shape, like a tower
+ * where it make senses to use polar coordinates instead x, y but where the
+ * height is not relative to a center, like it would be in a sphere.
+ *
+ * It implements IteratorAggregate to allow the foreach instruction
+ * on a GeoPointPolarZ object:
+ *
+ * <code>
+ * $point = new GeoPointPolarZ(17, '24°', -6);
+ * foreach ($point as $axis => $coordinate) {
+ * echo "\n\t$axis = $coordinate";
+ * }
+ * //This will output:
+ * // r = 17
+ * // t = 24°
+ * // z = -6
+ * </code>
+ *
+ * The point 3D representation is rtz: [ρ, θ, z] ; you can print it as a string
+ * and get this format:
+ *
+ * <code>
+ * $point = new GeoPointPolarZ(17, '24°', -6);
+ * echo (string)$point; //will output rρz: [17, 24°, -6]
+ * </code>
+ *
+ */
+class GeoPointPolarZ implements IteratorAggregate {
+ //
+ // ρ, θ, z public properties
+ //
+
+ /**
+ * the ρ coordinate
+ *
+ * @var float
+ */
+ public $r;
+
+ /**
+ * the θ coordinate
+ *
+ * This coordinate could be expressed as:
+ * - a string with a float, appended by "°" or " °" (in degree)
+ * - as a float (in radian)
+ *
+ * @var mixed
+ */
+ public $t;
+
+ /**
+ * the z coordinate
+ *
+ * @var float
+ */
+ public $z;
+
+ //
+ // constructor / toString
+ //
+
+ /**
+ * Initializes a new instance of GeoPointPolarZ class
+ *
+ * @param float $r the ρ coordinate
+ * @param mixed $t the θ coordinate, in ° (string) or radian (float)
+ * @param float $z the z coordinate
+ */
+ function __construct ($r, $t, $z) {
+ $this->r = (float)$r;
+ $this->t = trim($t);
+ $this->z = (float)$z;
+ }
+
+ /**
+ * Parses a string expression ang gets a GeoPointPolarZ object
+ *
+ * Formats recognized are:
+ * - rtz: [ρ, θ, z]
+ * - (ρ, θ, z)
+ *
+ * @param string $expression the expression to parse
+ * @return GeoPointPolarZ If the specified expression could be parsed, a GeoPointPolarZ instance ; otherwise, null.
+ */
+ static function fromString ($expression) {
+ if (string_starts_with($expression, 'rtz:', false)) {
+ $pos1 = strpos($expression, '[', 4) + 1;
+ $pos2 = strpos($expression, ']', $pos1);
+ if ($pos1 > -1 && $pos2 > -1) {
+ $expression = substr($expression, $pos1, $pos2 - $pos1);
+ $rtz = explode(',', $expression, 3);
+ return new GeoPointPolarZ($rtz[0], $rtz[1], $rtz[2]);
+ }
+ } elseif ($expression[0] = '(') {
+ $expression = substr($expression, 1, -1);
+ $rtz = explode(',', $expression, 3);
+ return new GeoPointPolarZ($rtz[0], $rtz[1], $rtz[2]);
+ }
+ return null;
+ }
+
+ /**
+ * Returns a string representation of the point coordinates.
+ *
+ * @param $format the format to use
+ * @return string a string representation of the coordinates
+ *
+ * To print a "rtz: [10, 20°, 40]" string:
+ * $point = new GeoPointPolarZ(10, '20°', 40);
+ * echo $point->sprintf("rtz: [%d, %s, %d]");
+ *
+ * //Of course, you could have (implicitely) use the __toString method:
+ * echo $point;
+ *
+ * To print a (10, 20°, 40) string:
+ * $point = new GeoPointPolarZ(10, 20°, 40);
+ * echo $point->sprintf("(%d, %s, %d)");
+ */
+ function sprintf ($format) {
+ return sprintf($format, $this->r, self::get_degrees($this->t), $this->z);
+ }
+
+ /**
+ * Returns a rρz: [r, ρ, z] string representation of the point coordinates.
+ *
+ * @return string a rtz: [ρ, θ, z] string representation of the coordinates
+ */
+ function __toString () {
+ return $this->sprintf("rtz: [%d, %s, %d]");
+ }
+
+ /**
+ * Determines if this point is equal to the specified point.
+ *
+ * @param GeoPointPolarZ $point The point to compare
+ * @return bool true if the two points are equal ; otherwise, false.
+ */
+ function equals ($point) {
+ return ($this->r == $point->r) && self::angle_equals($this->t, $point->t) && ($this->z == $point->z);
+ }
+
+ /**
+ * Detemrines if two angles are equal
+ * @param mixed $angle1 the first angle value, ie a float (angle in radian) or a string formed by an integed appended by ° (degrees)
+ * @param mixed $angle2 the second angle value, a float (angle in radian) or a string formed by an integed appended by ° (degrees)
+ * @return bool true if the angles are equal ; otherwise, false.
+ */
+ static function angle_equals ($angle1, $angle2) {
+ if ($angle1 === $angle2) return true;
+ if (!is_numerical($angle1)) {
+ $angle1 = deg2rad((float)$angle1);
+ }
+ if (!is_numerical($angle2)) {
+ $angle2 = deg2rad((float)$angle2);
+ }
+ $angle1 = self::normalize_angle($angle1);
+ $angle2 = self::normalize_angle($angle2);
+ return ($angle1 == $angle2);
+ }
+
+ /**
+ * Normalizes an angle (in radians) in the interval [0, π[ (or a custom interval)
+ *
+ * @param float $angle the angle (in radians)
+ * @param float $min the radians value the angle must be greater or equal than [optional, default value: 0]
+ * @param float $max the radains value the angle must be stricly lesser than [optional, default value: M_PI]
+ * @param float $interval the increment interval [optional, default value: 360]
+ */
+ static function normalize_angle ($angle, $min = 0, $max = M_PI, $interval = M_PI) {
+ while ($angle < $min) {
+ $angle += $interval;
+ }
+ while ($angle >= $max) {
+ $angle -= $interval;
+ }
+ return $angle;
+ }
+
+ /**
+ * Normalizes an angle (in degrees) in the interval [0, 360[ (or a custom interval)
+ *
+ * @param float $angle the angle to normalize, in degrees
+ * @param float $min the degrees value the angle must be greater or equal than [optional, default value: 0]
+ * @param float $max the degrees value the angle must be stricly lesser than [optional, default value: 360]
+ * @param float $interval the increment interval [optional, default value: 360]
+ */
+ static function normalize_angle_deg ($angle, $min = 0, $max = 360, $interval = 360) {
+ while ($angle < $min) {
+ $angle += $interval;
+ }
+ while ($angle >= $max) {
+ $angle -= $interval;
+ }
+ return $angle;
+ }
+
+ /**
+ * Gets the specified angle in radians
+ *
+ * @param mixed $angle the angle, a float in radians or a string (a float + "°" or " °" in degrees
+ * @return float the angle in radians
+ */
+ static function get_radians ($angle) {
+ return is_numeric($angle) ? $angle : deg2rad((float)$angle);
+ }
+
+ /**
+ * Gets the specified angle in degrees
+ *
+ * @param mixed $angle the angle, a float in radians or a string (a float + "°" or " °" in degrees
+ * @return string the angle (float) in degrees followed by "°"
+ */
+ static function get_degrees ($angle) {
+ return is_numeric($angle) ? rad2deg((float)$angle) . '°' : $angle;
+ }
+
+ /**
+ * Converts a polar coordinate angle to a 0-360° CW angle
+ */
+ static function get_natural_degrees ($angle) {
+ return self::normalize_angle_deg(90 - self::get_degrees($angle));
+ }
+
+ //
+ // Math
+ //
+
+ /**
+ * Gets the (x, y, z) cartesian coordinates from the current ρ, θ, z polar+z point
+ *
+ * @return array an array of 3 floats number, representing the (x, y, z) cartesian coordinates
+ */
+ function to_cartesian () {
+ $x = $this->r * cos(self::get_radians($this->t));
+ $y = $this->r * sin(self::get_radians($this->t));
+ return array($x, $y, $this->z);
+ }
+
+ /**
+ * Converts the current GeoPointPolarZ instance to a GeoPoint3D instance
+ *
+ * @return GeoPoint3D an instance of the GeoPoint3D class representing the (x, y, z) cartesian coordinates
+ */
+ function to_Point3D () {
+ $pt = $this->to_cartesian();
+ return new GeoPoint3D($pt[0], $pt[1], $pt[2]);
+ }
+
+ /**
+ * Gets the (ρ, φ, θ) spherical coordinates from the current (ρ, θ, z) polar+z point
+ *
+ * The algo used is from http://fr.wikipedia.org/wiki/Coordonn%C3%A9es_sph%C3%A9riques#Relation_avec_les_autres_syst.C3.A8mes_de_coordonn.C3.A9es_usuels
+ *
+ * @return array an array of 3 floats number, representing the (ρ, φ, θ) spherical coordinates
+ */
+ function to_spherical () {
+ $pt = $this->to_cartesian();
+ return GeoGalaxy::cartesian_to_spherical($pt[0], $pt[1], $pt[2]);
+ }
+
+ /**
+ * Gets the (ρ, φ, θ) spherical coordinates from the current (ρ, θ, z) polar+z point
+ *
+ * The algo used is from http://www.phy225.dept.shef.ac.uk/mediawiki/index.php/Cartesian_to_polar_conversion
+ *
+ * @return array an array of 3 floats number, representing the (ρ, φ, θ) spherical coordinates
+ */
+ function to_spherical2 () {
+ $pt = $this->to_cartesian();
+ return GeoGalaxy::cartesian_to_spherical2($pt[0], $pt[1], $pt[2]);
+ }
+
+ /**
+ * Translates the center and rescales.
+ *
+ * This method allow to help to represent coordinate in a new system
+ *
+ * This method is used to represent Zed objects in dojo with the following
+ * parameters:
+ * <code>
+ * $pointKaos = GeoPointPolarZ(800, 42, 220);
+ * $pointKaos->translate(500, 300, 200, 2);
+ * echo $pointKaos;
+ * //This will output rρz: [150, -129, 10]
+ * </code>
+ *
+ * @param float $dr the difference between the old ρ and new ρ (ie the value of ρ = 0 in the new system)
+ * @param float $dt the difference between the old θ and new θ (ie the value of θ = 0 in the new system)
+ * @param float $dz the difference between the old y and new z (ie the value of z = 0 in the new system)
+ * @param int $scale if specified, divides each coordinate by this value (optional)
+ */
+ function translate ($dr, $dt, $dz, $scale = 1) {
+ if ($scale == 1) {
+ $this->r += $dr;
+ $this->t += $dt;
+ $this->z += $dz;
+ } elseif ($scale == 0) {
+ $this->r = 0;
+ $this->t = 0;
+ $this->z = 0;
+ } else {
+ $this->r = $this->r * $scale + $dr;
+ $this->t = $this->t * $scale + $dt;
+ $this->z = $this->z * $scale + $dz;
+ }
+ }
+
+ /**
+ * Calculates the section number the specified angle belongs
+ *
+ * @param $angle float The natural angle in degree (North 0°, East 90°, etc. clockwise)
+ * @param int $count the number of sections
+ * @return $int the section number
+ */
+ static function calculate_section ($angle, $count = 6) {
+ if ($angle < 90) {
+ $angle += 270;
+ } else {
+ $angle -= 90;
+ }
+ return 1 + (int)($angle / (360/$count));
+ }
+
+ /**
+ * Gets the section number the θ angle belongs to.
+ *
+ * @param int $count the number of sections
+ * @return $int the section number
+ */
+ function get_section ($count = 6) {
+ return self::calculate_section(self::get_natural_degrees($this->t), $count);
+ }
+
+ //
+ // Implementing IteratorAggregate
+ //
+
+ /**
+ * Retrieves class iterator. It traverses ρ, θ and z.
+ *
+ * @return Traversable the iterator
+ */
+ function getIterator () {
+ return new ArrayIterator($this);
+ }
+}
+
+?>

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 24, 16:38 (4 h, 19 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21053
Default Alt Text
(22 KB)

Event Timeline