Class: Topolys::DirectedEdge
Overview
Edge
Instance Attribute Summary collapse
-
#edge ⇒ Edge
readonly
The edge this directed edge points to.
-
#inverted ⇒ Boolean
readonly
True if this is a forward directed edge, false otherwise.
-
#length ⇒ Numeric
readonly
The length of this edge.
-
#v0 ⇒ Vertex
readonly
The initial vertex, the directed edge origin.
-
#v1 ⇒ Vertex
readonly
The second vertex, the directed edge terminal point.
-
#vector ⇒ Vector3D
readonly
The vector of this directed edge.
Attributes inherited from Object
#attributes, #children, #id, #parents
Instance Method Summary collapse
- #child_class ⇒ Object
- #edges ⇒ Object
-
#initialize(edge, inverted) ⇒ DirectedEdge
constructor
Initializes a DirectedEdge object, use Model.get_directed_edge instead.
- #parent_class ⇒ Object
- #recalculate ⇒ Object
- #to_json ⇒ Object
- #wires ⇒ 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(edge, inverted) ⇒ DirectedEdge
Initializes a DirectedEdge object, use Model.get_directed_edge instead
Throws if edge or inverted are incorrect type
958 959 960 961 962 963 964 |
# File 'lib/topolys/model.rb', line 958 def initialize(edge, inverted) super() @edge = edge @inverted = inverted recalculate end |
Instance Attribute Details
#edge ⇒ Edge (readonly)
Returns the edge this directed edge points to.
940 941 942 |
# File 'lib/topolys/model.rb', line 940 def edge @edge end |
#inverted ⇒ Boolean (readonly)
Returns true if this is a forward directed edge, false otherwise.
943 944 945 |
# File 'lib/topolys/model.rb', line 943 def inverted @inverted end |
#length ⇒ Numeric (readonly)
Returns the length of this edge.
946 947 948 |
# File 'lib/topolys/model.rb', line 946 def length @length end |
#v0 ⇒ Vertex (readonly)
Returns the initial vertex, the directed edge origin.
934 935 936 |
# File 'lib/topolys/model.rb', line 934 def v0 @v0 end |
#v1 ⇒ Vertex (readonly)
Returns the second vertex, the directed edge terminal point.
937 938 939 |
# File 'lib/topolys/model.rb', line 937 def v1 @v1 end |
#vector ⇒ Vector3D (readonly)
Returns the vector of this directed edge.
949 950 951 |
# File 'lib/topolys/model.rb', line 949 def vector @vector end |
Instance Method Details
#child_class ⇒ Object
1003 1004 1005 |
# File 'lib/topolys/model.rb', line 1003 def child_class Edge end |
#edges ⇒ Object
1011 1012 1013 |
# File 'lib/topolys/model.rb', line 1011 def edges @children end |
#parent_class ⇒ Object
999 1000 1001 |
# File 'lib/topolys/model.rb', line 999 def parent_class Wire end |
#recalculate ⇒ Object
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 |
# File 'lib/topolys/model.rb', line 973 def recalculate super() debug("before: ") # unlink from any previous edges @children.reverse_each {|child| Object.unlink(self, child)} # link with current edge Object.link(self, @edge) debug("after: ") # recompute cached properties and check invariants if @inverted @v0 = edge.v1 @v1 = edge.v0 else @v0 = edge.v0 @v1 = edge.v1 end @vector = @v1.point - @v0.point @length = @vector.magnitude end |
#to_json ⇒ Object
966 967 968 969 970 971 |
# File 'lib/topolys/model.rb', line 966 def to_json result = super result[:edge] = @edge.id result[:inverted] = @inverted return result end |
#wires ⇒ Object
1007 1008 1009 |
# File 'lib/topolys/model.rb', line 1007 def wires @parents end |