Class: SLComponents::Edge

Inherits:
Object
  • Object
show all
Defined in:
lib/mk_semi_lattice/sl_components.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to) ⇒ Edge

Returns a new instance of Edge.



259
260
261
262
263
264
265
# File 'lib/mk_semi_lattice/sl_components.rb', line 259

def initialize(from, to)
  @from = from
  @to = to
  @len = 75.0
  @line = nil
  @created = nil
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



258
259
260
# File 'lib/mk_semi_lattice/sl_components.rb', line 258

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



258
259
260
# File 'lib/mk_semi_lattice/sl_components.rb', line 258

def to
  @to
end

Instance Method Details

#create_graphicsObject



286
287
288
289
290
291
292
293
# File 'lib/mk_semi_lattice/sl_components.rb', line 286

def create_graphics
  return if @created
  @line = Line.new(
    x1: from.x, y1: from.y, x2: to.x, y2: to.y,
    width: 2, color: EDGE_COLOR, opacity: 0.3, z: 5 # opacityを追加
  )
  @created = true
end

#drawObject



295
296
297
298
299
300
301
302
# File 'lib/mk_semi_lattice/sl_components.rb', line 295

def draw
  create_graphics
  # 既存ラインのプロパティを更新
  @line.x1 = from.x
  @line.y1 = from.y
  @line.x2 = to.x
  @line.y2 = to.y
end

#relaxObject



267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/mk_semi_lattice/sl_components.rb', line 267

def relax
  vx = to.x - from.x
  vy = to.y - from.y
  d = Math.hypot(vx, vy)
  if d > 0
    f = (@len - d) / (d * 5)
    dx = f * vx
    dy = f * vy
    to.dx += dx
    to.dy += dy
    from.dx -= dx
    from.dy -= dy
  end
end

#updateObject



282
283
284
# File 'lib/mk_semi_lattice/sl_components.rb', line 282

def update
  # 何も処理しないが、将来拡張用
end