Class: RubySketch::LinkConstraint

Inherits:
Constraint show all
Defined in:
lib/rubysketch/constraint.rb

Overview

Keeps two points apart at a distance, or slides them along an axis like a rail.

Instance Method Summary collapse

Methods inherited from Constraint

#active?, #collide=, #collide?, #damping, #damping=, #force, #force=, #remove, #removed?, #spring, #spring=, #sprites

Instance Method Details

#axisVector?

Returns the axis to slide along.

Returns:

  • (Vector, nil)

    axis, or nil for a radial link



251
252
253
# File 'lib/rubysketch/constraint.rb', line 251

def axis()
  @constraint__.axis&.toVector
end

#axis=(axis) ⇒ Vector, ...

Sets the axis to slide along. With an axis, the separation is measured along it instead of radially, and the relative rotation is locked like a rail.

Parameters:

  • axis (Vector, Array<Numeric>, nil)

    direction in the target local space, or nil to link radially

Returns:

  • (Vector, Array<Numeric>, nil)

    axis



243
244
245
# File 'lib/rubysketch/constraint.rb', line 243

def axis=(axis)
  @constraint__.axis = RubySketch.unwrap__ axis
end

#currentDistanceNumeric

Returns the current distance between the two points.

Returns:

  • (Numeric)

    distance in pixels, or 0 if not active in a world



277
278
279
# File 'lib/rubysketch/constraint.rb', line 277

def currentDistance()
  @constraint__.current_distance
end

#distanceNumeric Also known as: dist

Returns the distance to keep.

Returns:

  • (Numeric)

    distance in pixels



269
270
271
# File 'lib/rubysketch/constraint.rb', line 269

def distance()
  @constraint__.distance
end

#distance=(distance) ⇒ Numeric Also known as: dist=

Sets the distance to keep.

Parameters:

  • distance (Numeric)

    distance in pixels

Returns:

  • (Numeric)

    distance



261
262
263
# File 'lib/rubysketch/constraint.rb', line 261

def distance=(distance)
  @constraint__.distance = distance
end

#motorNumeric?

Returns the motor speed.

Returns:

  • (Numeric, nil)

    speed in pixels per second



314
315
316
# File 'lib/rubysketch/constraint.rb', line 314

def motor()
  @constraint__.motor
end

#motor=(speed) ⇒ Numeric?

Sets the motor speed that drives the separation.

Parameters:

  • speed (Numeric, nil)

    speed in pixels per second, or nil to stop

Returns:

  • (Numeric, nil)

    speed



306
307
308
# File 'lib/rubysketch/constraint.rb', line 306

def motor=(speed)
  @constraint__.motor = speed
end

#rangeRange?

Returns the range of the separation.

Returns:

  • (Range, nil)

    separation range



296
297
298
# File 'lib/rubysketch/constraint.rb', line 296

def range()
  @constraint__.range
end

#range=(range) ⇒ Range, ...

Sets the range of the separation.

Parameters:

  • range (Range, Numeric, nil)

    distance range like a rope, or the translation range along the axis

Returns:

  • (Range, Numeric, nil)

    range



288
289
290
# File 'lib/rubysketch/constraint.rb', line 288

def range=(range)
  @constraint__.range = range
end