Page MenuHomeCode

No OneTemporary

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
diff --git a/content/scenes/B00001002.tpl b/content/scenes/B00001002.tpl
new file mode 100644
index 0000000..b8c2121
--- /dev/null
+++ b/content/scenes/B00001002.tpl
@@ -0,0 +1,7 @@
+{$xyz = explode(',', substr($CurrentPerso->location_local, 1 -1))}
+{$x = $xyz[0]}{$y = $xyz[1]}{$z = $xyz[2]}
+<p>
+ Secteur C<span id="sector">{GeoOctocube::get_sector($x, $y, $z)}</span><br />
+ Niveau <span id="level">{$z}</span><br />
+ Zone <span id="area">{abs($x)}, {abs($y)}</span>
+</p>
\ No newline at end of file
diff --git a/dev/tests/GeoOctocubeTest.php b/dev/tests/GeoOctocubeTest.php
new file mode 100644
index 0000000..8c562e3
--- /dev/null
+++ b/dev/tests/GeoOctocubeTest.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Unit testing : class GeoOctocube
+ *
+ * Zed. The immensity of stars. The HyperShip. The people.
+ *
+ * (c) 2010, Dereckson, some rights reserved.
+ * Released under BSD license.
+ *
+ * @package Zed
+ * @subpackage Tests
+ * @author S饕astien Santoro aka Dereckson <dereckson@espace-win.org>
+ * @copyright 2010 S饕astien 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('PHPUnit/Framework.php');
+require_once('../../includes/geo/octocube.php');
+
+/**
+ * Test cases for the class GeoPlace
+ */
+class GeoOctocubeTest extends PHPUnit_Framework_TestCase {
+ /**
+ * Tests the GeoPlace::is_valid_local_location($local_location) method.
+ */
+ public function testGetSector () {
+ //Testing HyperShip Tower T2C3 format
+ $this->assertTrue(GeoOctocube::get_sector(0, 0, 0) == 0);
+ $this->assertTrue(GeoOctocube::get_sector(-10, 6, -4) == 1);
+ $this->assertTrue(GeoOctocube::get_sector(10, 6, -4) == 2);
+ $this->assertTrue(GeoOctocube::get_sector(-10, -6, -4) == 3);
+ $this->assertTrue(GeoOctocube::get_sector(10, -6, -4) == 4);
+ $this->assertTrue(GeoOctocube::get_sector(-10, 6, 4) == 5);
+ $this->assertTrue(GeoOctocube::get_sector(10, 6, 4) == 6);
+ $this->assertTrue(GeoOctocube::get_sector(-10, -6, 4) == 7);
+ $this->assertTrue(GeoOctocube::get_sector(10, -6, 4) == 8);
+ }
+}
+?>
diff --git a/includes/geo/octocube.php b/includes/geo/octocube.php
new file mode 100644
index 0000000..1c60738
--- /dev/null
+++ b/includes/geo/octocube.php
@@ -0,0 +1,81 @@
+<?php
+
+/**
+ * Geo octocube class.
+ *
+ * Zed. The immensity of stars. The HyperShip. The people.
+ *
+ * (c) 2010, Dereckson, some rights reserved.
+ * Released under BSD license.
+ *
+ * 0.1 2010-02-25 3:33 DcK
+ *
+ * @package Zed
+ * @subpackage Geo
+ * @author S饕astien Santoro aka Dereckson <dereckson@espace-win.org>
+ * @copyright 2010 S饕astien 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
+ * @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);
+ }
+}
+
+?>
+
+
diff --git a/includes/geo/point3D.php b/includes/geo/point3D.php
index 93c8b76..0fc0b32 100644
--- a/includes/geo/point3D.php
+++ b/includes/geo/point3D.php
@@ -1,114 +1,118 @@
<?php
/**
* Geo point 3D class.
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* 0.1 2010-02-23 14:14 DcK
*
* @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 point 3D class.
*
- * This class reprensents a x, y, z point.
+ * This class represents a x, y, z point.
*
* It implements IteratorAggregate to allow the foreach instruction
* on a GeoPoint3D object:
*
* <code>
* $point = new GeoPoint3D(17, 24, -6);
* foreach ($point as $axis => $coordinate) {
* echo "\n\t$axis = $coordinate";
* }
* //This will output:
* // x = 17
* // y = 24
* // z = -6
* </code>
*
* The point 3D representation is xyz: [x, y, z] ; you can print it as a string
* and get this format:
*
* <code>
* $point = new GeoPoint3D(17, 24, -6);
* echo (string)$point; //will output xyz: [17, 24, -6]
* </code>
*
*/
class GeoPoint3D implements IteratorAggregate {
//
// x, y, z public properties
//
/**
* the x coordinate
*
* @var integer
*/
public $x;
/**
* the y coordinate
*
* @var integer
*/
public $y;
/**
* the z coordinate
*
* @var integer
*/
public $z;
//
// constructor / toString
//
/**
* Initializes a new instance of GeoPoint3D class
+ *
+ * @param int $x the x coordinate
+ * @param int $y the y coordinate
+ * @param int $z the z coordinate
*/
function __construct ($x, $y, $z) {
$this->x = $x;
$this->y = $y;
$this->z = $z;
}
/**
* Returns a xyz: [x, y, z] string representation of the point coordinates
*
* @return string a xyz: [x, y, z] string representation of the coordinates
*/
function __toString () {
return sprintf("xyz: [%d, %d, %d]", $this->x, $this->y, $this->z);
}
//
// Implementing IteratorAggregate
//
/**
* Retrieves class iterator. It traverses x, y and z.
*
* @return Traversable the iterator
*/
function getIterator () {
return new ArrayIterator($this);
}
}
?>
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 15, 18:27 (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21055
Default Alt Text
(7 KB)

Event Timeline