rubysketch 0.9.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ module RubySketch
7
7
  module_function
8
8
 
9
9
  def name(downcase = false)
10
- super().split('::')[-2].then {|s|
10
+ super().split('::')[..-2].join.then {|s|
11
11
  downcase ? s.downcase : s
12
12
  }
13
13
  end
@@ -4,3 +4,13 @@ class Rays::Point
4
4
  Processing::Vector.new x, y, z
5
5
  end
6
6
  end
7
+
8
+
9
+ module RubySketch
10
+
11
+ # @private
12
+ def self.unwrap__(arg)
13
+ arg.respond_to?(:getInternal__) ? arg.getInternal__ : arg
14
+ end
15
+
16
+ end# RubySketch
@@ -0,0 +1,108 @@
1
+ module RubySketch
2
+
3
+
4
+ # A pin fastened at a point on a sprite.
5
+ # Creating a constraint between sprites starts from a pin.
6
+ #
7
+ class Pin
8
+
9
+ # @private
10
+ def initialize(sprite, x = nil, y = nil, pin__: nil)
11
+ if pin__
12
+ @sprite__ = pin__.view&.sprite
13
+ @pin__ = pin__
14
+ else
15
+ @sprite__ = sprite
16
+ @pin__ = x ? sprite.getInternal__.pin(x, y) : sprite.getInternal__.pin
17
+ end
18
+ end
19
+
20
+ # Creates a constraint that makes the pin and the target point coincide.
21
+ #
22
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
23
+ # the center of a sprite, a pin, or a point in the world.
24
+ # snaps to the world when target is omitted
25
+ #
26
+ # @return [SnapConstraint] a new constraint
27
+ #
28
+ def snap(*args, **options, &block)
29
+ create__ SnapConstraint, @pin__.snap(*unwrap__(args)), options, block
30
+ end
31
+
32
+ # Creates a constraint that keeps the distance to the target point.
33
+ #
34
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
35
+ # the center of a sprite, a pin, or a point in the world.
36
+ # links to the world when target is omitted
37
+ #
38
+ # @return [LinkConstraint] a new constraint
39
+ #
40
+ def link(*args, **options, &block)
41
+ create__ LinkConstraint, @pin__.link(*unwrap__(args)), options, block
42
+ end
43
+
44
+ # Creates a constraint that makes the pin ride on the target like a
45
+ # wheel: it slides along an axis for the suspension and spins freely.
46
+ #
47
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
48
+ # the center of a sprite, a pin, or a point in the world.
49
+ # rides on the world when target is omitted
50
+ #
51
+ # @return [WheelConstraint] a new constraint
52
+ #
53
+ def wheel(*args, **options, &block)
54
+ create__ WheelConstraint, @pin__.wheel(*unwrap__(args)), options, block
55
+ end
56
+
57
+ # Creates a constraint that moves the pin toward the target every frame.
58
+ #
59
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
60
+ # the center of a sprite, a pin, or a point in the world.
61
+ # chases nothing when target is omitted
62
+ #
63
+ # @return [ChaseConstraint] a new constraint
64
+ #
65
+ def chase(*args, **options, &block)
66
+ create__ ChaseConstraint, @pin__.chase(*unwrap__(args)), options, block
67
+ end
68
+
69
+ # Returns the sprite the pin is fastened to.
70
+ #
71
+ # @return [Sprite, nil] nil for a pin in the world
72
+ #
73
+ def sprite()
74
+ @sprite__
75
+ end
76
+
77
+ # Returns the position of the pin.
78
+ #
79
+ # @return [Vector, nil] sprite-local position, or nil for the center
80
+ #
81
+ def position()
82
+ @pin__.position&.toVector
83
+ end
84
+
85
+ alias pos position
86
+
87
+ # @private
88
+ def getInternal__()
89
+ @pin__
90
+ end
91
+
92
+ private
93
+
94
+ def create__(klass, constraint, options, block)
95
+ klass.new(constraint).tap do |c|
96
+ c.set options unless options.empty?
97
+ Xot::BlockUtil.instance_eval_or_block_call c, &block if block
98
+ end
99
+ end
100
+
101
+ def unwrap__(args)
102
+ args.map {|arg| RubySketch.unwrap__ arg}
103
+ end
104
+
105
+ end# Pin
106
+
107
+
108
+ end# RubySketch
@@ -83,7 +83,7 @@ module RubySketch
83
83
 
84
84
  # @deprecated Use {#contactEnd} instead.
85
85
  def contact_end(&block)
86
- warn "Shape#contact_end is deprecated, use #contactEnd instead", uniq: true
86
+ Xot.warn "Shape#contact_end is deprecated, use #contactEnd instead", uniq: true
87
87
  contactEnd(&block)
88
88
  end
89
89