Class: Topolys::DirectedEdge

Inherits:
Object
  • Object
show all
Defined in:
lib/topolys/model.rb

Overview

Edge

Instance Attribute Summary collapse

Attributes inherited from Object

#attributes, #children, #id, #parents

Instance Method Summary collapse

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

Parameters:

  • edge (Edge)

    The underlying edge

  • inverted (Boolean)

    True if this is a forward DirectedEdge, false otherwise



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

#edgeEdge (readonly)

Returns the edge this directed edge points to.

Returns:

  • (Edge)

    the edge this directed edge points to



940
941
942
# File 'lib/topolys/model.rb', line 940

def edge
  @edge
end

#invertedBoolean (readonly)

Returns true if this is a forward directed edge, false otherwise.

Returns:

  • (Boolean)

    true if this is a forward directed edge, false otherwise



943
944
945
# File 'lib/topolys/model.rb', line 943

def inverted
  @inverted
end

#lengthNumeric (readonly)

Returns the length of this edge.

Returns:

  • (Numeric)

    the length of this edge



946
947
948
# File 'lib/topolys/model.rb', line 946

def length
  @length
end

#v0Vertex (readonly)

Returns the initial vertex, the directed edge origin.

Returns:

  • (Vertex)

    the initial vertex, the directed edge origin



934
935
936
# File 'lib/topolys/model.rb', line 934

def v0
  @v0
end

#v1Vertex (readonly)

Returns the second vertex, the directed edge terminal point.

Returns:

  • (Vertex)

    the second vertex, the directed edge terminal point



937
938
939
# File 'lib/topolys/model.rb', line 937

def v1
  @v1
end

#vectorVector3D (readonly)

Returns the vector of this directed edge.

Returns:

  • (Vector3D)

    the vector of this directed edge



949
950
951
# File 'lib/topolys/model.rb', line 949

def vector
  @vector
end

Instance Method Details

#child_classObject



1003
1004
1005
# File 'lib/topolys/model.rb', line 1003

def child_class
  Edge
end

#edgesObject



1011
1012
1013
# File 'lib/topolys/model.rb', line 1011

def edges
  @children
end

#parent_classObject



999
1000
1001
# File 'lib/topolys/model.rb', line 999

def parent_class
  Wire
end

#recalculateObject



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_jsonObject



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

#wiresObject



1007
1008
1009
# File 'lib/topolys/model.rb', line 1007

def wires
  @parents
end