Module: Yzz
- Defined in:
- lib/yzz.rb,
lib/yzz/version.rb
Overview
Yzz implements Ted Nelson’s zz (hyperorthogonal, Zig-Zag…) structure. It provides a mixin that imbues objects with zz properties.
A zz structure consists of zz objects, which exist in multiple dimensions. Zz objects can be connected by directed edges – connections. Connected objects are called neighbors. Each connection belongs to some dimension. A zz object is considered as having two sides in each dimension: posward side and negward side. A connection always points away from the posward side, and towards the neighbor’s negward side. In each dimension, zz object can have at most one posward and one negward neighbor. A zz object can be connected to itself, forming a loop.
To these basic properties, Ted Nelson adds a bunch of other terminology. A rank is a series of zz objects connected along one dimension. A rank viewed horizontally is referred to as row. A rank viewed vertically is referred to as column.
Mixin defining Zz structure (aka. hyperorthogonal structure). As represented by YTed::Zz, a Zz structure is a collection of objects, whose connectivity is defined in a multidimensional space in such way, that each object, along each dimension, has at most one posward neighbor, and one negward neighbor. The relation is bijective: If B is a posward neighbor of A along some dimension, then A must be a negward neighbor of B along that dimension, and vice-versa.
Defined Under Namespace
Constant Summary collapse
- VERSION =
"2.0.2"
Instance Method Summary collapse
-
#along(dimension) ⇒ Object
Returns a SidePair instance along the requested dimension.
-
#connections ⇒ Object
(also: #connectivity)
Returns all sides actually connected to a zz object.
-
#initialize(*args) ⇒ Object
Adds initialization of the @zz_dimensions hash to #initialize.
-
#neighbors ⇒ Object
Returns all neighbors of a zz object.
-
#towards(other) ⇒ Object
Returns all sides facing another zz object supplied as argument.
Instance Method Details
#along(dimension) ⇒ Object
Returns a SidePair instance along the requested dimension.
44 45 46 |
# File 'lib/yzz.rb', line 44 def along dimension @zz_dimensions[ dimension ] end |
#connections ⇒ Object Also known as: connectivity
Returns all sides actually connected to a zz object.
50 51 52 53 |
# File 'lib/yzz.rb', line 50 def connections @zz_dimensions.map { |_, pair| [ pair.negward, pair.posward ] } .reduce( [], :+ ).select { |side| side.neighbor.is_a_zz? } end |
#initialize(*args) ⇒ Object
Adds initialization of the @zz_dimensions hash to #initialize.
34 35 36 37 38 39 40 |
# File 'lib/yzz.rb', line 34 def initialize *args @zz_dimensions = Hash.new { | |
#neighbors ⇒ Object
Returns all neighbors of a zz object.
58 59 60 |
# File 'lib/yzz.rb', line 58 def neighbors connections.map &:neighbor end |
#towards(other) ⇒ Object
Returns all sides facing another zz object supplied as argument. (Note that this can be more than 1 side: object A can be connected to B along more than 1 dimension.
66 67 68 |
# File 'lib/yzz.rb', line 66 def towards other connectivity.select { |side| side.neighbor == other } end |