Class: Topolys::Edge
Overview
Vertex
Instance Attribute Summary collapse
-
#length ⇒ Numeric
(also: #magnitude)
readonly
The length of this edge.
-
#v0 ⇒ Vertex
readonly
The initial vertex, the edge origin.
-
#v1 ⇒ Vertex
readonly
The second vertex, the edge terminal point.
Attributes inherited from Object
#attributes, #children, #id, #parents
Instance Method Summary collapse
- #child_class ⇒ Object
- #directed_edges ⇒ Object
- #forward_edge ⇒ Object
-
#initialize(v0, v1) ⇒ Edge
constructor
Initializes an Edge object, use Model.get_edge instead.
- #parent_class ⇒ Object
- #recalculate ⇒ Object
- #reverse_edge ⇒ Object
- #to_json ⇒ Object
- #vertices ⇒ Object
Methods inherited from Object
#debug, #hash, link, #link_child, #link_parent, #short_id, #short_name, #to_s, unlink, #unlink_child, #unlink_parent
Constructor Details
#initialize(v0, v1) ⇒ Edge
Initializes an Edge object, use Model.get_edge instead
Throws if v0 or v1 are incorrect type or refer to same vertex
868 869 870 871 872 873 874 |
# File 'lib/topolys/model.rb', line 868 def initialize(v0, v1) super() @v0 = v0 @v1 = v1 recalculate end |
Instance Attribute Details
#length ⇒ Numeric (readonly) Also known as: magnitude
Returns the length of this edge.
858 859 860 |
# File 'lib/topolys/model.rb', line 858 def length @length end |
#v0 ⇒ Vertex (readonly)
Returns the initial vertex, the edge origin.
852 853 854 |
# File 'lib/topolys/model.rb', line 852 def v0 @v0 end |
#v1 ⇒ Vertex (readonly)
Returns the second vertex, the edge terminal point.
855 856 857 |
# File 'lib/topolys/model.rb', line 855 def v1 @v1 end |
Instance Method Details
#child_class ⇒ Object
909 910 911 |
# File 'lib/topolys/model.rb', line 909 def child_class Vertex end |
#directed_edges ⇒ Object
921 922 923 |
# File 'lib/topolys/model.rb', line 921 def directed_edges @parents end |
#forward_edge ⇒ Object
913 914 915 |
# File 'lib/topolys/model.rb', line 913 def forward_edge @parents.first{|de| !de.inverted} end |
#parent_class ⇒ Object
905 906 907 |
# File 'lib/topolys/model.rb', line 905 def parent_class DirectedEdge end |
#recalculate ⇒ Object
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
# File 'lib/topolys/model.rb', line 883 def recalculate super() # TODO: should catch if 'origin' or 'terminal' are not Vertex objects # TODO: should also catch if 'origin' or 'terminal' refer to same object or are within tol of each other debug("before: ") # unlink from any previous vertices @children.reverse_each {|child| Object.unlink(self, child)} # link to current vertices Object.link(self, @v0) Object.link(self, @v1) debug("after: ") # recompute cached properties and check invariants vector = @v1.point - @v0.point @length = vector.magnitude end |
#reverse_edge ⇒ Object
917 918 919 |
# File 'lib/topolys/model.rb', line 917 def reverse_edge @parents.first{|de| de.inverted} end |
#to_json ⇒ Object
876 877 878 879 880 881 |
# File 'lib/topolys/model.rb', line 876 def to_json result = super result[:v0] = @v0.id result[:v1] = @v1.id return result end |
#vertices ⇒ Object
925 926 927 |
# File 'lib/topolys/model.rb', line 925 def vertices @children end |