rubysketch 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90fb6bf8a945c62f9ac122dc4df7515aa2ebf271cb100836c76cb8cc1d4f7c50
4
- data.tar.gz: 53e61d592dbc5090d98e3c6bb015d406f018683767997c3f2f4d53462a9f27b4
3
+ metadata.gz: e9914f7b869e2dfeb80a8ba58a8c6678c0a995a974124b2b88974e477af3fdd8
4
+ data.tar.gz: 2b7d45e918f60be716bc9edc8f5bfbb7ceb800954965af32163431e681709250
5
5
  SHA512:
6
- metadata.gz: deb1f851efbcfd3feff20a7495ad55c9ef3a2d1e9ee416d6b87de89069197cc397a64303c69929f212cb0dda658f739a6ca1f1e83bea3050afa219b889509a9d
7
- data.tar.gz: ba13f0ce8a03a0b86f1ad20078e0b473d2e6058a446a3059c21f8c9e5ccabcaa72f065bcbfee13bb7b105960f0e658b1ee3e609c44c1429f1d4a9851ce122eab
6
+ metadata.gz: 5f1192007cfb3a80c6335dd8a881358a9fa2b9dac8b6a0931836f295f2658ac0d4723b9a9d51800e6923ccfcc625f6fd92fd9444732339a338773681d6921299
7
+ data.tar.gz: afefa27c322e08e0be3c1c6099b3ef3a3c86d0fadfc3140e4ec4c26c4686573d1a733ce0791f94241a4e73a67cda5998029fcfd4ebc6e7f3a1de6c8994ecdb0e
@@ -1,6 +1,11 @@
1
1
  # RubySketch ChangeLog
2
2
 
3
3
 
4
+ ## [0.3.4] - 2020-08-02
5
+
6
+ - delete Utility module
7
+
8
+
4
9
  ## [0.3.3] - 2020-08-01
5
10
 
6
11
  - add Vector class
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -6,6 +6,13 @@ module RubySketch
6
6
  module Processing
7
7
 
8
8
 
9
+ # @private
10
+ DEG2RAD__ = Math::PI / 180.0
11
+
12
+ # @private
13
+ RAD2DEG__ = 180.0 / Math::PI
14
+
15
+
9
16
  # Vector class.
10
17
  #
11
18
  class Vector
@@ -27,14 +34,14 @@ module RubySketch
27
34
  # @param v [Vector] vector object to copy
28
35
  # @param a [Array] array like [x, y, z]
29
36
  #
30
- def initialize (x = 0, y = 0, z = 0, context: context)
37
+ def initialize (x = 0, y = 0, z = 0, context: nil)
31
38
  @point = case x
32
39
  when Rays::Point then x.dup
33
40
  when Vector then x.getInternal__.dup
34
41
  when Array then Rays::Point.new x[0] || 0, x[1] || 0, x[2] || 0
35
42
  else Rays::Point.new x || 0, y || 0, z || 0
36
43
  end
37
- @context = context
44
+ @context = context || Context.context__
38
45
  end
39
46
 
40
47
  # Initializer for dup or clone
@@ -464,7 +471,7 @@ module RubySketch
464
471
  # @return [Vector] rotated this object
465
472
  #
466
473
  def rotate (angle)
467
- angle = @context ? @context.toAngle__(angle) : angle * Utility::RAD2DEG__
474
+ angle = @context ? @context.toAngle__(angle) : angle * RAD2DEG__
468
475
  @point.rotate! angle
469
476
  self
470
477
  end
@@ -915,7 +922,7 @@ module RubySketch
915
922
  #
916
923
  def angleMode (mode)
917
924
  @angleScale__ = case mode.upcase.to_sym
918
- when RADIANS then Utility::RAD2DEG__
925
+ when RADIANS then RAD2DEG__
919
926
  when DEGREES then 1.0
920
927
  else raise ArgumentError, "invalid angle mode: #{mode}"
921
928
  end
@@ -1617,13 +1624,248 @@ module RubySketch
1617
1624
  end# Graphics
1618
1625
 
1619
1626
 
1620
- module Utility
1627
+ # Processing context
1628
+ #
1629
+ module Context
1630
+
1631
+ include GraphicsContext, Math
1632
+
1633
+ @@context__ = nil
1634
+
1635
+ def self.context__ ()
1636
+ @@context__
1637
+ end
1621
1638
 
1622
1639
  # @private
1623
- DEG2RAD__ = Math::PI / 180.0
1640
+ def setup__ (window)
1641
+ @@context__ = self
1642
+
1643
+ @window__ = window
1644
+ @image__ = @window__.canvas
1645
+ super @window__.canvas_painter.paint {background 0.8}
1646
+
1647
+ @loop__ = true
1648
+ @redraw__ = false
1649
+ @frameCount__ = 0
1650
+ @mousePos__ =
1651
+ @mousePrevPos__ = Rays::Point.new 0
1652
+ @mousePressed__ = false
1653
+ @touches__ = []
1654
+
1655
+ @window__.before_draw = proc {beginDraw}
1656
+ @window__.after_draw = proc {endDraw}
1657
+
1658
+ drawFrame = -> {
1659
+ @image__ = @window__.canvas
1660
+ @painter__ = @window__.canvas_painter
1661
+ begin
1662
+ push
1663
+ @drawBlock__.call if @drawBlock__
1664
+ ensure
1665
+ pop
1666
+ @frameCount__ += 1
1667
+ end
1668
+ }
1669
+
1670
+ @window__.draw = proc do |e|
1671
+ if @loop__ || @redraw__
1672
+ @redraw__ = false
1673
+ drawFrame.call
1674
+ end
1675
+ @mousePrevPos__ = @mousePos__
1676
+ end
1677
+
1678
+ updatePointerStates = -> event, pressed = nil {
1679
+ @mousePos__ = event.pos
1680
+ @mousePressed__ = pressed if pressed != nil
1681
+ @touches__ = event.positions.map {|pos| Touch.new pos.x, pos.y}
1682
+ }
1683
+
1684
+ @window__.pointer_down = proc do |e|
1685
+ updatePointerStates.call e, true
1686
+ (@touchStartedBlock__ || @mousePressedBlock__)&.call
1687
+ end
1688
+
1689
+ @window__.pointer_up = proc do |e|
1690
+ updatePointerStates.call e, false
1691
+ (@touchEndedBlock__ || @mouseReleasedBlock__)&.call
1692
+ end
1693
+
1694
+ @window__.pointer_move = proc do |e|
1695
+ updatePointerStates.call e
1696
+ (@touchMovedBlock__ || @mouseMovedBlock__)&.call
1697
+ end
1698
+
1699
+ @window__.pointer_drag = proc do |e|
1700
+ updatePointerStates.call e
1701
+ (@touchMovedBlock__ || @mouseDraggedBlock__)&.call
1702
+ end
1703
+ end
1704
+
1705
+ # Define setup block.
1706
+ #
1707
+ def setup (&block)
1708
+ @window__.setup = block
1709
+ nil
1710
+ end
1711
+
1712
+ # Define draw block.
1713
+ #
1714
+ def draw (&block)
1715
+ @drawBlock__ = block if block
1716
+ nil
1717
+ end
1718
+
1719
+ def key (&block)
1720
+ @window__.key = block
1721
+ nil
1722
+ end
1723
+
1724
+ def mousePressed (&block)
1725
+ @mousePressedBlock__ = block if block
1726
+ @mousePressed__
1727
+ end
1728
+
1729
+ def mouseReleased (&block)
1730
+ @mouseReleasedBlock__ = block if block
1731
+ nil
1732
+ end
1733
+
1734
+ def mouseMoved (&block)
1735
+ @mouseMovedBlock__ = block if block
1736
+ nil
1737
+ end
1738
+
1739
+ def mouseDragged (&block)
1740
+ @mouseDraggedBlock__ = block if block
1741
+ nil
1742
+ end
1743
+
1744
+ def touchStarted (&block)
1745
+ @touchStartedBlock__ = block if block
1746
+ nil
1747
+ end
1748
+
1749
+ def touchEnded (&block)
1750
+ @touchEndedBlock__ = block if block
1751
+ nil
1752
+ end
1753
+
1754
+ def touchMoved (&block)
1755
+ @touchMovedBlock__ = block if block
1756
+ nil
1757
+ end
1624
1758
 
1625
1759
  # @private
1626
- RAD2DEG__ = 180.0 / Math::PI
1760
+ private def size__ (width, height)
1761
+ raise 'size() must be called on startup or setup block' if @started__
1762
+
1763
+ @painter__.__send__ :end_paint
1764
+ @window__.__send__ :reset_canvas, width, height
1765
+ @painter__.__send__ :begin_paint
1766
+
1767
+ @auto_resize__ = false
1768
+ end
1769
+
1770
+ def windowWidth ()
1771
+ @window__.width
1772
+ end
1773
+
1774
+ def windowHeight ()
1775
+ @window__.height
1776
+ end
1777
+
1778
+ # Returns number of frames since program started.
1779
+ #
1780
+ # @return [Integer] total number of frames
1781
+ #
1782
+ def frameCount ()
1783
+ @frameCount__
1784
+ end
1785
+
1786
+ # Returns number of frames per second.
1787
+ #
1788
+ # @return [Float] frames per second
1789
+ #
1790
+ def frameRate ()
1791
+ @window__.event.fps
1792
+ end
1793
+
1794
+ # Returns pixel density
1795
+ #
1796
+ # @return [Numeric] pixel density
1797
+ #
1798
+ def displayDensity ()
1799
+ @painter__.pixel_density
1800
+ end
1801
+
1802
+ # Returns mouse x position
1803
+ #
1804
+ # @return [Numeric] horizontal position of mouse
1805
+ #
1806
+ def mouseX ()
1807
+ @mousePos__.x
1808
+ end
1809
+
1810
+ # Returns mouse y position
1811
+ #
1812
+ # @return [Numeric] vertical position of mouse
1813
+ #
1814
+ def mouseY ()
1815
+ @mousePos__.y
1816
+ end
1817
+
1818
+ # Returns mouse x position in previous frame
1819
+ #
1820
+ # @return [Numeric] horizontal position of mouse
1821
+ #
1822
+ def pmouseX ()
1823
+ @mousePrevPos__.x
1824
+ end
1825
+
1826
+ # Returns mouse y position in previous frame
1827
+ #
1828
+ # @return [Numeric] vertical position of mouse
1829
+ #
1830
+ def pmouseY ()
1831
+ @mousePrevPos__.y
1832
+ end
1833
+
1834
+ # Returns array of touches
1835
+ #
1836
+ # @return [Array] Touch objects
1837
+ #
1838
+ def touches ()
1839
+ @touches__
1840
+ end
1841
+
1842
+ # Enables calling draw block on every frame.
1843
+ #
1844
+ # @return [nil] nil
1845
+ #
1846
+ def loop ()
1847
+ @loop__ = true
1848
+ end
1849
+
1850
+ # Disables calling draw block on every frame.
1851
+ #
1852
+ # @return [nil] nil
1853
+ #
1854
+ def noLoop ()
1855
+ @loop__ = false
1856
+ end
1857
+
1858
+ # Calls draw block to redraw frame.
1859
+ #
1860
+ # @return [nil] nil
1861
+ #
1862
+ def redraw ()
1863
+ @redraw__ = true
1864
+ end
1865
+
1866
+ #
1867
+ # Utility functions
1868
+ #
1627
1869
 
1628
1870
  # Converts degree to radian.
1629
1871
  #
@@ -1854,6 +2096,33 @@ module RubySketch
1854
2096
  Rays.perlin(x, y, z) / 2.0 + 0.5
1855
2097
  end
1856
2098
 
2099
+ # Creates a new vector.
2100
+ #
2101
+ # @overload createVector()
2102
+ # @overload createVector(x, y)
2103
+ # @overload createVector(x, y, z)
2104
+ #
2105
+ # @param x [Numeric] x of new vector
2106
+ # @param y [Numeric] y of new vector
2107
+ # @param z [Numeric] z of new vector
2108
+ #
2109
+ # @return [Vector] new vector
2110
+ #
2111
+ def createVector (*args)
2112
+ Vector.new *args
2113
+ end
2114
+
2115
+ # Creates a new off-screen graphics context object.
2116
+ #
2117
+ # @param width [Numeric] width of graphics image
2118
+ # @param height [Numeric] height of graphics image
2119
+ #
2120
+ # @return [Graphics] graphics object
2121
+ #
2122
+ def createGraphics (width, height)
2123
+ Graphics.new width, height
2124
+ end
2125
+
1857
2126
  # Loads image.
1858
2127
  #
1859
2128
  # @param filename [String] file name to load image
@@ -1888,244 +2157,6 @@ module RubySketch
1888
2157
  path.to_s
1889
2158
  end
1890
2159
 
1891
- def createGraphics (width, height)
1892
- Graphics.new width, height
1893
- end
1894
-
1895
- end# Utility
1896
-
1897
-
1898
- # Processing context
1899
- #
1900
- module Context
1901
-
1902
- include GraphicsContext, Utility, Math
1903
-
1904
- # @private
1905
- def setup__ (window)
1906
- @window__ = window
1907
- @image__ = @window__.canvas
1908
- super @window__.canvas_painter.paint {background 0.8}
1909
-
1910
- @loop__ = true
1911
- @redraw__ = false
1912
- @frameCount__ = 0
1913
- @mousePos__ =
1914
- @mousePrevPos__ = Rays::Point.new 0
1915
- @mousePressed__ = false
1916
- @touches__ = []
1917
-
1918
- @window__.before_draw = proc {beginDraw}
1919
- @window__.after_draw = proc {endDraw}
1920
-
1921
- drawFrame = -> {
1922
- @image__ = @window__.canvas
1923
- @painter__ = @window__.canvas_painter
1924
- begin
1925
- push
1926
- @drawBlock__.call if @drawBlock__
1927
- ensure
1928
- pop
1929
- @frameCount__ += 1
1930
- end
1931
- }
1932
-
1933
- @window__.draw = proc do |e|
1934
- if @loop__ || @redraw__
1935
- @redraw__ = false
1936
- drawFrame.call
1937
- end
1938
- @mousePrevPos__ = @mousePos__
1939
- end
1940
-
1941
- updatePointerStates = -> event, pressed = nil {
1942
- @mousePos__ = event.pos
1943
- @mousePressed__ = pressed if pressed != nil
1944
- @touches__ = event.positions.map {|pos| Touch.new pos.x, pos.y}
1945
- }
1946
-
1947
- @window__.pointer_down = proc do |e|
1948
- updatePointerStates.call e, true
1949
- (@touchStartedBlock__ || @mousePressedBlock__)&.call
1950
- end
1951
-
1952
- @window__.pointer_up = proc do |e|
1953
- updatePointerStates.call e, false
1954
- (@touchEndedBlock__ || @mouseReleasedBlock__)&.call
1955
- end
1956
-
1957
- @window__.pointer_move = proc do |e|
1958
- updatePointerStates.call e
1959
- (@touchMovedBlock__ || @mouseMovedBlock__)&.call
1960
- end
1961
-
1962
- @window__.pointer_drag = proc do |e|
1963
- updatePointerStates.call e
1964
- (@touchMovedBlock__ || @mouseDraggedBlock__)&.call
1965
- end
1966
- end
1967
-
1968
- # Define setup block.
1969
- #
1970
- def setup (&block)
1971
- @window__.setup = block
1972
- nil
1973
- end
1974
-
1975
- # Define draw block.
1976
- #
1977
- def draw (&block)
1978
- @drawBlock__ = block if block
1979
- nil
1980
- end
1981
-
1982
- def key (&block)
1983
- @window__.key = block
1984
- nil
1985
- end
1986
-
1987
- def mousePressed (&block)
1988
- @mousePressedBlock__ = block if block
1989
- @mousePressed__
1990
- end
1991
-
1992
- def mouseReleased (&block)
1993
- @mouseReleasedBlock__ = block if block
1994
- nil
1995
- end
1996
-
1997
- def mouseMoved (&block)
1998
- @mouseMovedBlock__ = block if block
1999
- nil
2000
- end
2001
-
2002
- def mouseDragged (&block)
2003
- @mouseDraggedBlock__ = block if block
2004
- nil
2005
- end
2006
-
2007
- def touchStarted (&block)
2008
- @touchStartedBlock__ = block if block
2009
- nil
2010
- end
2011
-
2012
- def touchEnded (&block)
2013
- @touchEndedBlock__ = block if block
2014
- nil
2015
- end
2016
-
2017
- def touchMoved (&block)
2018
- @touchMovedBlock__ = block if block
2019
- nil
2020
- end
2021
-
2022
- # @private
2023
- private def size__ (width, height)
2024
- raise 'size() must be called on startup or setup block' if @started__
2025
-
2026
- @painter__.__send__ :end_paint
2027
- @window__.__send__ :reset_canvas, width, height
2028
- @painter__.__send__ :begin_paint
2029
-
2030
- @auto_resize__ = false
2031
- end
2032
-
2033
- def windowWidth ()
2034
- @window__.width
2035
- end
2036
-
2037
- def windowHeight ()
2038
- @window__.height
2039
- end
2040
-
2041
- # Returns number of frames since program started.
2042
- #
2043
- # @return [Integer] total number of frames
2044
- #
2045
- def frameCount ()
2046
- @frameCount__
2047
- end
2048
-
2049
- # Returns number of frames per second.
2050
- #
2051
- # @return [Float] frames per second
2052
- #
2053
- def frameRate ()
2054
- @window__.event.fps
2055
- end
2056
-
2057
- # Returns pixel density
2058
- #
2059
- # @return [Numeric] pixel density
2060
- #
2061
- def displayDensity ()
2062
- @painter__.pixel_density
2063
- end
2064
-
2065
- # Returns mouse x position
2066
- #
2067
- # @return [Numeric] horizontal position of mouse
2068
- #
2069
- def mouseX ()
2070
- @mousePos__.x
2071
- end
2072
-
2073
- # Returns mouse y position
2074
- #
2075
- # @return [Numeric] vertical position of mouse
2076
- #
2077
- def mouseY ()
2078
- @mousePos__.y
2079
- end
2080
-
2081
- # Returns mouse x position in previous frame
2082
- #
2083
- # @return [Numeric] horizontal position of mouse
2084
- #
2085
- def pmouseX ()
2086
- @mousePrevPos__.x
2087
- end
2088
-
2089
- # Returns mouse y position in previous frame
2090
- #
2091
- # @return [Numeric] vertical position of mouse
2092
- #
2093
- def pmouseY ()
2094
- @mousePrevPos__.y
2095
- end
2096
-
2097
- # Returns array of touches
2098
- #
2099
- # @return [Array] Touch objects
2100
- #
2101
- def touches ()
2102
- @touches__
2103
- end
2104
-
2105
- # Enables calling draw block on every frame.
2106
- #
2107
- # @return [nil] nil
2108
- #
2109
- def loop ()
2110
- @loop__ = true
2111
- end
2112
-
2113
- # Disables calling draw block on every frame.
2114
- #
2115
- # @return [nil] nil
2116
- #
2117
- def noLoop ()
2118
- @loop__ = false
2119
- end
2120
-
2121
- # Calls draw block to redraw frame.
2122
- #
2123
- # @return [nil] nil
2124
- #
2125
- def redraw ()
2126
- @redraw__ = true
2127
- end
2128
-
2129
2160
  end# Context
2130
2161
 
2131
2162
 
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ %w[../xot ../rucy ../rays ../reflex .]
5
+ .map {|s| File.expand_path "../../#{s}/lib", __FILE__}
6
+ .each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
7
+
8
+ require 'test/unit'
9
+ require 'xot/test'
10
+ require 'rubysketch'
11
+
12
+ include Xot::Test
13
+
14
+
15
+ unless $RAYS_NOAUTOINIT
16
+ #def Rays.fin! () end
17
+ end
18
+
19
+
20
+ def assert_equal_vector (v1, v2, delta = 0.000001)
21
+ assert_in_delta v1.x, v2.x, delta
22
+ assert_in_delta v1.y, v2.y, delta
23
+ assert_in_delta v1.z, v2.z, delta
24
+ end
@@ -6,7 +6,9 @@ require_relative '../helper'
6
6
 
7
7
  class TestProcessingVector < Test::Unit::TestCase
8
8
 
9
- V = RubySketch::Processing::Vector
9
+ P = RubySketch::Processing
10
+
11
+ V = P::Vector
10
12
 
11
13
  M = Math
12
14
 
@@ -21,76 +23,76 @@ class TestProcessingVector < Test::Unit::TestCase
21
23
  end
22
24
 
23
25
  def test_initialize ()
24
- assert_equal vec(0, 0, 0), vec()
25
- assert_equal vec(1, 0, 0), vec(1)
26
- assert_equal vec(1, 2, 0), vec(1, 2)
27
- assert_equal vec(1, 2, 3), vec(1, 2, 3)
26
+ assert_equal_vector vec(0, 0, 0), vec()
27
+ assert_equal_vector vec(1, 0, 0), vec(1)
28
+ assert_equal_vector vec(1, 2, 0), vec(1, 2)
29
+ assert_equal_vector vec(1, 2, 3), vec(1, 2, 3)
28
30
 
29
- assert_equal vec(0, 0, 0), vec([])
30
- assert_equal vec(1, 0, 0), vec([1])
31
- assert_equal vec(1, 2, 0), vec([1, 2])
32
- assert_equal vec(1, 2, 3), vec([1, 2, 3])
31
+ assert_equal_vector vec(0, 0, 0), vec([])
32
+ assert_equal_vector vec(1, 0, 0), vec([1])
33
+ assert_equal_vector vec(1, 2, 0), vec([1, 2])
34
+ assert_equal_vector vec(1, 2, 3), vec([1, 2, 3])
33
35
 
34
- assert_equal vec(1, 2, 3), vec(vec 1, 2, 3)
35
- assert_equal vec(1, 2, 3), vec(point 1, 2, 3)
36
+ assert_equal_vector vec(1, 2, 3), vec(vec 1, 2, 3)
37
+ assert_equal_vector vec(1, 2, 3), vec(point 1, 2, 3)
36
38
  end
37
39
 
38
40
  def test_set ()
39
41
  v0 = vec 9, 9, 9
40
42
 
41
- v = v0.dup; v.set; assert_equal vec(0, 0, 0), v
42
- v = v0.dup; v.set 1; assert_equal vec(1, 0, 0), v
43
- v = v0.dup; v.set 1, 2; assert_equal vec(1, 2, 0), v
44
- v = v0.dup; v.set 1, 2, 3; assert_equal vec(1, 2, 3), v
43
+ v = v0.dup; v.set; assert_equal_vector vec(0, 0, 0), v
44
+ v = v0.dup; v.set 1; assert_equal_vector vec(1, 0, 0), v
45
+ v = v0.dup; v.set 1, 2; assert_equal_vector vec(1, 2, 0), v
46
+ v = v0.dup; v.set 1, 2, 3; assert_equal_vector vec(1, 2, 3), v
45
47
 
46
- v = v0.dup; v.set []; assert_equal vec(0, 0, 0), v
47
- v = v0.dup; v.set [1]; assert_equal vec(1, 0, 0), v
48
- v = v0.dup; v.set [1, 2]; assert_equal vec(1, 2, 0), v
49
- v = v0.dup; v.set [1, 2, 3]; assert_equal vec(1, 2, 3), v
48
+ v = v0.dup; v.set []; assert_equal_vector vec(0, 0, 0), v
49
+ v = v0.dup; v.set [1]; assert_equal_vector vec(1, 0, 0), v
50
+ v = v0.dup; v.set [1, 2]; assert_equal_vector vec(1, 2, 0), v
51
+ v = v0.dup; v.set [1, 2, 3]; assert_equal_vector vec(1, 2, 3), v
50
52
 
51
- v = v0.dup; v.set vec(1, 2, 3); assert_equal vec(1, 2, 3), v
52
- v = v0.dup; v.set point(1, 2, 3); assert_equal vec(1, 2, 3), v
53
+ v = v0.dup; v.set vec(1, 2, 3); assert_equal_vector vec(1, 2, 3), v
54
+ v = v0.dup; v.set point(1, 2, 3); assert_equal_vector vec(1, 2, 3), v
53
55
  end
54
56
 
55
57
  def test_dup ()
56
58
  v1 = vec 1, 2, 3
57
- assert_equal vec(1, 2, 3), v1
59
+ assert_equal_vector vec(1, 2, 3), v1
58
60
 
59
61
  v2 = v1.dup
60
- assert_equal vec(1, 2, 3), v1
61
- assert_equal vec(1, 2, 3), v2
62
+ assert_equal_vector vec(1, 2, 3), v1
63
+ assert_equal_vector vec(1, 2, 3), v2
62
64
 
63
65
  v1.set 7, 8, 9
64
- assert_equal vec(7, 8, 9), v1
65
- assert_equal vec(1, 2, 3), v2
66
+ assert_equal_vector vec(7, 8, 9), v1
67
+ assert_equal_vector vec(1, 2, 3), v2
66
68
  end
67
69
 
68
70
  def test_copy ()
69
71
  v1 = vec 1, 2, 3
70
- assert_equal vec(1, 2, 3), v1
72
+ assert_equal_vector vec(1, 2, 3), v1
71
73
 
72
74
  v2 = v1.copy
73
- assert_equal vec(1, 2, 3), v1
74
- assert_equal vec(1, 2, 3), v2
75
+ assert_equal_vector vec(1, 2, 3), v1
76
+ assert_equal_vector vec(1, 2, 3), v2
75
77
 
76
78
  v1.set 7, 8, 9
77
- assert_equal vec(7, 8, 9), v1
78
- assert_equal vec(1, 2, 3), v2
79
+ assert_equal_vector vec(7, 8, 9), v1
80
+ assert_equal_vector vec(1, 2, 3), v2
79
81
  end
80
82
 
81
83
  def test_xyz ()
82
84
  v = vec 1, 2, 3
83
- assert_equal vec(1, 2, 3), v
84
- assert_equal [1, 2, 3], [v.x, v.y, v.z]
85
+ assert_equal_vector vec(1, 2, 3), v
86
+ assert_equal [1, 2, 3], [v.x, v.y, v.z]
85
87
 
86
88
  v.x = 7
87
- assert_equal vec(7, 2, 3), v
89
+ assert_equal_vector vec(7, 2, 3), v
88
90
 
89
91
  v.y = 8
90
- assert_equal vec(7, 8, 3), v
92
+ assert_equal_vector vec(7, 8, 3), v
91
93
 
92
94
  v.z = 9
93
- assert_equal vec(7, 8, 9), v
95
+ assert_equal_vector vec(7, 8, 9), v
94
96
  end
95
97
 
96
98
  def test_array ()
@@ -100,135 +102,135 @@ class TestProcessingVector < Test::Unit::TestCase
100
102
  def test_add ()
101
103
  v = vec 1, 2, 3
102
104
  v.add 4, 5, 6
103
- assert_equal vec(5, 7, 9), v
105
+ assert_equal_vector vec(5, 7, 9), v
104
106
 
105
- assert_equal vec(1, 2, 3), vec(1, 2, 3).add()
106
- assert_equal vec(5, 2, 3), vec(1, 2, 3).add(4)
107
- assert_equal vec(5, 7, 3), vec(1, 2, 3).add(4, 5)
108
- assert_equal vec(5, 7, 9), vec(1, 2, 3).add(4, 5, 6)
107
+ assert_equal_vector vec(1, 2, 3), vec(1, 2, 3).add()
108
+ assert_equal_vector vec(5, 2, 3), vec(1, 2, 3).add(4)
109
+ assert_equal_vector vec(5, 7, 3), vec(1, 2, 3).add(4, 5)
110
+ assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add(4, 5, 6)
109
111
 
110
- assert_equal vec(1, 2, 3), vec(1, 2, 3).add([])
111
- assert_equal vec(5, 2, 3), vec(1, 2, 3).add([4])
112
- assert_equal vec(5, 7, 3), vec(1, 2, 3).add([4, 5])
113
- assert_equal vec(5, 7, 9), vec(1, 2, 3).add([4, 5, 6])
112
+ assert_equal_vector vec(1, 2, 3), vec(1, 2, 3).add([])
113
+ assert_equal_vector vec(5, 2, 3), vec(1, 2, 3).add([4])
114
+ assert_equal_vector vec(5, 7, 3), vec(1, 2, 3).add([4, 5])
115
+ assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add([4, 5, 6])
114
116
 
115
- assert_equal vec(5, 7, 9), vec(1, 2, 3).add( vec(4, 5, 6))
116
- assert_equal vec(5, 7, 9), vec(1, 2, 3).add(point(4, 5, 6))
117
+ assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add( vec(4, 5, 6))
118
+ assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add(point(4, 5, 6))
117
119
  end
118
120
 
119
121
  def test_sub ()
120
122
  v = vec 9, 8, 7
121
123
  v.sub 1, 2, 3
122
- assert_equal vec(8, 6, 4), v
124
+ assert_equal_vector vec(8, 6, 4), v
123
125
 
124
- assert_equal vec(9, 8, 7), vec(9, 8, 7).sub()
125
- assert_equal vec(8, 8, 7), vec(9, 8, 7).sub(1)
126
- assert_equal vec(8, 6, 7), vec(9, 8, 7).sub(1, 2)
127
- assert_equal vec(8, 6, 4), vec(9, 8, 7).sub(1, 2, 3)
126
+ assert_equal_vector vec(9, 8, 7), vec(9, 8, 7).sub()
127
+ assert_equal_vector vec(8, 8, 7), vec(9, 8, 7).sub(1)
128
+ assert_equal_vector vec(8, 6, 7), vec(9, 8, 7).sub(1, 2)
129
+ assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub(1, 2, 3)
128
130
 
129
- assert_equal vec(9, 8, 7), vec(9, 8, 7).sub([])
130
- assert_equal vec(8, 8, 7), vec(9, 8, 7).sub([1])
131
- assert_equal vec(8, 6, 7), vec(9, 8, 7).sub([1, 2])
132
- assert_equal vec(8, 6, 4), vec(9, 8, 7).sub([1, 2, 3])
131
+ assert_equal_vector vec(9, 8, 7), vec(9, 8, 7).sub([])
132
+ assert_equal_vector vec(8, 8, 7), vec(9, 8, 7).sub([1])
133
+ assert_equal_vector vec(8, 6, 7), vec(9, 8, 7).sub([1, 2])
134
+ assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub([1, 2, 3])
133
135
 
134
- assert_equal vec(8, 6, 4), vec(9, 8, 7).sub( vec(1, 2, 3))
135
- assert_equal vec(8, 6, 4), vec(9, 8, 7).sub(point(1, 2, 3))
136
+ assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub( vec(1, 2, 3))
137
+ assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub(point(1, 2, 3))
136
138
  end
137
139
 
138
140
  def test_mult ()
139
141
  v = vec 1, 2, 3
140
142
  v.mult 2
141
- assert_equal vec(2, 4, 6), v
143
+ assert_equal_vector vec(2, 4, 6), v
142
144
  end
143
145
 
144
146
  def test_div ()
145
147
  v = vec 2, 4, 6
146
148
  v.div 2
147
- assert_equal vec(1, 2, 3), v
149
+ assert_equal_vector vec(1, 2, 3), v
148
150
  end
149
151
 
150
152
  def test_op_add ()
151
153
  v1 = vec 1, 2, 3
152
154
  v2 = vec 4, 5, 6
153
- assert_equal vec(5, 7, 9), v1 + v2
154
- assert_equal vec(1, 2, 3), v1
155
- assert_equal vec(4, 5, 6), v2
155
+ assert_equal_vector vec(5, 7, 9), v1 + v2
156
+ assert_equal_vector vec(1, 2, 3), v1
157
+ assert_equal_vector vec(4, 5, 6), v2
156
158
 
157
- assert_equal vec(5, 2, 3), vec(1, 2, 3) + 4
159
+ assert_equal_vector vec(5, 2, 3), vec(1, 2, 3) + 4
158
160
 
159
- assert_equal vec(1, 2, 3), vec(1, 2, 3) + []
160
- assert_equal vec(5, 2, 3), vec(1, 2, 3) + [4]
161
- assert_equal vec(5, 7, 3), vec(1, 2, 3) + [4, 5]
162
- assert_equal vec(5, 7, 9), vec(1, 2, 3) + [4, 5, 6]
161
+ assert_equal_vector vec(1, 2, 3), vec(1, 2, 3) + []
162
+ assert_equal_vector vec(5, 2, 3), vec(1, 2, 3) + [4]
163
+ assert_equal_vector vec(5, 7, 3), vec(1, 2, 3) + [4, 5]
164
+ assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + [4, 5, 6]
163
165
 
164
- assert_equal vec(5, 7, 9), vec(1, 2, 3) + vec(4, 5, 6)
165
- assert_equal vec(5, 7, 9), vec(1, 2, 3) + point(4, 5, 6)
166
+ assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + vec(4, 5, 6)
167
+ assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + point(4, 5, 6)
166
168
  end
167
169
 
168
170
  def test_op_sub ()
169
171
  v1 = vec 9, 8, 7
170
172
  v2 = vec 1, 2, 3
171
- assert_equal vec(8, 6, 4), v1 - v2
172
- assert_equal vec(9, 8, 7), v1
173
- assert_equal vec(1, 2, 3), v2
173
+ assert_equal_vector vec(8, 6, 4), v1 - v2
174
+ assert_equal_vector vec(9, 8, 7), v1
175
+ assert_equal_vector vec(1, 2, 3), v2
174
176
 
175
- assert_equal vec(8, 8, 7), vec(9, 8, 7) - 1
177
+ assert_equal_vector vec(8, 8, 7), vec(9, 8, 7) - 1
176
178
 
177
- assert_equal vec(9, 8, 7), vec(9, 8, 7) - []
178
- assert_equal vec(8, 8, 7), vec(9, 8, 7) - [1]
179
- assert_equal vec(8, 6, 7), vec(9, 8, 7) - [1, 2]
180
- assert_equal vec(8, 6, 4), vec(9, 8, 7) - [1, 2, 3]
179
+ assert_equal_vector vec(9, 8, 7), vec(9, 8, 7) - []
180
+ assert_equal_vector vec(8, 8, 7), vec(9, 8, 7) - [1]
181
+ assert_equal_vector vec(8, 6, 7), vec(9, 8, 7) - [1, 2]
182
+ assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - [1, 2, 3]
181
183
 
182
- assert_equal vec(8, 6, 4), vec(9, 8, 7) - vec(1, 2, 3)
183
- assert_equal vec(8, 6, 4), vec(9, 8, 7) - point(1, 2, 3)
184
+ assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - vec(1, 2, 3)
185
+ assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - point(1, 2, 3)
184
186
  end
185
187
 
186
188
  def test_op_mult ()
187
189
  v = vec 1, 2, 3
188
- assert_equal vec(2, 4, 6), v * 2
189
- assert_equal vec(1, 2, 3), v
190
+ assert_equal_vector vec(2, 4, 6), v * 2
191
+ assert_equal_vector vec(1, 2, 3), v
190
192
  end
191
193
 
192
194
  def test_op_div ()
193
195
  v = vec 2, 4, 6
194
- assert_equal vec(1, 2, 3), v / 2
195
- assert_equal vec(2, 4, 6), v
196
+ assert_equal_vector vec(1, 2, 3), v / 2
197
+ assert_equal_vector vec(2, 4, 6), v
196
198
  end
197
199
 
198
200
  def test_fun_add ()
199
201
  v1 = vec 1, 2, 3
200
202
  v2 = vec 4, 5, 6
201
203
  result = vec
202
- assert_equal vec(5, 7, 9), V.add(v1, v2, result)
203
- assert_equal vec(1, 2, 3), v1
204
- assert_equal vec(4, 5, 6), v2
205
- assert_equal vec(5, 7, 9), result
204
+ assert_equal_vector vec(5, 7, 9), V.add(v1, v2, result)
205
+ assert_equal_vector vec(1, 2, 3), v1
206
+ assert_equal_vector vec(4, 5, 6), v2
207
+ assert_equal_vector vec(5, 7, 9), result
206
208
  end
207
209
 
208
210
  def test_fun_sub ()
209
211
  v1 = vec 9, 8, 7
210
212
  v2 = vec 1, 2, 3
211
213
  result = vec
212
- assert_equal vec(8, 6, 4), V.sub(v1, v2, result)
213
- assert_equal vec(9, 8, 7), v1
214
- assert_equal vec(1, 2, 3), v2
215
- assert_equal vec(8, 6, 4), result
214
+ assert_equal_vector vec(8, 6, 4), V.sub(v1, v2, result)
215
+ assert_equal_vector vec(9, 8, 7), v1
216
+ assert_equal_vector vec(1, 2, 3), v2
217
+ assert_equal_vector vec(8, 6, 4), result
216
218
  end
217
219
 
218
220
  def test_fun_mult ()
219
221
  v1 = vec 1, 2, 3
220
222
  result = vec
221
- assert_equal vec(2, 4, 6), V.mult(v1, 2, result)
222
- assert_equal vec(1, 2, 3), v1
223
- assert_equal vec(2, 4, 6), result
223
+ assert_equal_vector vec(2, 4, 6), V.mult(v1, 2, result)
224
+ assert_equal_vector vec(1, 2, 3), v1
225
+ assert_equal_vector vec(2, 4, 6), result
224
226
  end
225
227
 
226
228
  def test_fun_div ()
227
229
  v1 = vec 2, 4, 6
228
230
  result = vec
229
- assert_equal vec(1, 2, 3), V.div(v1, 2, result)
230
- assert_equal vec(2, 4, 6), v1
231
- assert_equal vec(1, 2, 3), result
231
+ assert_equal_vector vec(1, 2, 3), V.div(v1, 2, result)
232
+ assert_equal_vector vec(2, 4, 6), v1
233
+ assert_equal_vector vec(1, 2, 3), result
232
234
  end
233
235
 
234
236
  def test_mag ()
@@ -243,27 +245,27 @@ class TestProcessingVector < Test::Unit::TestCase
243
245
 
244
246
  def test_setMag ()
245
247
  v = vec 3, 4, 0
246
- assert_equal vec(6, 8, 0), v.setMag(10)
247
- assert_equal vec(6, 8, 0), v
248
+ assert_equal_vector vec(6, 8, 0), v.setMag(10)
249
+ assert_equal_vector vec(6, 8, 0), v
248
250
 
249
251
  v = vec 3, 4, 0
250
252
  result = vec
251
- assert_equal vec(6, 8, 0), v.setMag(result, 10)
252
- assert_equal vec(3, 4, 0), v
253
- assert_equal vec(6, 8, 0), result
253
+ assert_equal_vector vec(6, 8, 0), v.setMag(result, 10)
254
+ assert_equal_vector vec(3, 4, 0), v
255
+ assert_equal_vector vec(6, 8, 0), result
254
256
  end
255
257
 
256
258
  def test_normalize ()
257
259
  v = vec 1, 2, 3
258
260
  normal = v / v.mag
259
- assert_equal normal, v.normalize
260
- assert_equal normal, v
261
+ assert_equal_vector normal, v.normalize
262
+ assert_equal_vector normal, v
261
263
 
262
264
  v = vec 1, 2, 3
263
265
  result = vec
264
- assert_equal normal, v.normalize(result)
265
- assert_equal vec(1, 2, 3), v
266
- assert_equal normal, result
266
+ assert_equal_vector normal, v.normalize(result)
267
+ assert_equal_vector vec(1, 2, 3), v
268
+ assert_equal_vector normal, result
267
269
  end
268
270
 
269
271
  def test_limit ()
@@ -282,12 +284,12 @@ class TestProcessingVector < Test::Unit::TestCase
282
284
  v2 = vec 4, 5, 6
283
285
 
284
286
  assert_in_delta M.sqrt((4-1)**2 + (5-2)**2 + (6-3)**2), v1.dist(v2), 0.000001
285
- assert_equal vec(1, 2, 3), v1
286
- assert_equal vec(4, 5, 6), v2
287
+ assert_equal_vector vec(1, 2, 3), v1
288
+ assert_equal_vector vec(4, 5, 6), v2
287
289
 
288
290
  assert_in_delta M.sqrt((4-1)**2 + (5-2)**2 + (6-3)**2), V.dist(v1, v2), 0.000001
289
- assert_equal vec(1, 2, 3), v1
290
- assert_equal vec(4, 5, 6), v2
291
+ assert_equal_vector vec(1, 2, 3), v1
292
+ assert_equal_vector vec(4, 5, 6), v2
291
293
  end
292
294
 
293
295
  def test_dot ()
@@ -295,55 +297,55 @@ class TestProcessingVector < Test::Unit::TestCase
295
297
  v2 = vec 4, 5, 6
296
298
 
297
299
  assert_equal 1*4 + 2*5 + 3*6, v1.dot(4, 5, 6)
298
- assert_equal vec(1, 2, 3), v1
300
+ assert_equal_vector vec(1, 2, 3), v1
299
301
 
300
302
  assert_equal 1*4 + 2*5 + 3*6, v1.dot(v2)
301
- assert_equal vec(1, 2, 3), v1
302
- assert_equal vec(4, 5, 6), v2
303
+ assert_equal_vector vec(1, 2, 3), v1
304
+ assert_equal_vector vec(4, 5, 6), v2
303
305
 
304
306
  assert_equal 1*4 + 2*5 + 3*6, V.dot(v1, v2)
305
- assert_equal vec(1, 2, 3), v1
306
- assert_equal vec(4, 5, 6), v2
307
+ assert_equal_vector vec(1, 2, 3), v1
308
+ assert_equal_vector vec(4, 5, 6), v2
307
309
  end
308
310
 
309
311
  def test_cross ()
310
312
  v1 = vec 1, 0, 0
311
313
  v2 = vec 0, 1, 0
312
314
 
313
- assert_equal vec(0, 0, 1), v1.cross(0, 1, 0)
314
- assert_equal vec(1, 0, 0), v1
315
+ assert_equal_vector vec(0, 0, 1), v1.cross(0, 1, 0)
316
+ assert_equal_vector vec(1, 0, 0), v1
315
317
 
316
318
  result = vec 1, 2, 3
317
- assert_equal vec(0, 0, 1), v1.cross(v2, result)
318
- assert_equal vec(1, 0, 0), v1
319
- assert_equal vec(0, 1, 0), v2
320
- assert_equal vec(0, 0, 1), result
319
+ assert_equal_vector vec(0, 0, 1), v1.cross(v2, result)
320
+ assert_equal_vector vec(1, 0, 0), v1
321
+ assert_equal_vector vec(0, 1, 0), v2
322
+ assert_equal_vector vec(0, 0, 1), result
321
323
 
322
324
  result = vec 1, 2, 3
323
- assert_equal vec(0, 0, 1), V.cross(v1, v2, result)
324
- assert_equal vec(1, 0, 0), v1
325
- assert_equal vec(0, 1, 0), v2
326
- assert_equal vec(0, 0, 1), result
325
+ assert_equal_vector vec(0, 0, 1), V.cross(v1, v2, result)
326
+ assert_equal_vector vec(1, 0, 0), v1
327
+ assert_equal_vector vec(0, 1, 0), v2
328
+ assert_equal_vector vec(0, 0, 1), result
327
329
  end
328
330
 
329
331
  def test_rotate ()
330
332
  angle = PI * 2 * 0.1
331
- context = Object.new.tap {|o| def o.toAngle__ (angle); angle; end}
333
+ context = Object.new.tap {|o| def o.toAngle__ (a); a * 2 * P::RAD2DEG__; end}
332
334
 
333
335
  v = vec 1, 0, 0
334
- assert_equal vec(M.cos(angle), M.sin(angle), 0), v.rotate(angle)
335
- assert_equal vec(M.cos(angle), M.sin(angle), 0), v
336
+ assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), v.rotate(angle)
337
+ assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), v
336
338
 
337
339
  v = vec 1, 0, 0, context: context
338
- assert_equal vec(M.cos(angle), M.sin(angle), 0), v.rotate(36)
340
+ assert_equal_vector vec(M.cos(angle * 2), M.sin(angle * 2), 0), v.rotate(angle)
339
341
  end
340
342
 
341
343
  def test_fromAngle ()
342
344
  angle = PI * 2 * 0.1
343
345
  result = vec
344
- assert_equal vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle)
345
- assert_equal vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle, result)
346
- assert_equal vec(M.cos(angle), M.sin(angle), 0), result
346
+ assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle)
347
+ assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle, result)
348
+ assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), result
347
349
  end
348
350
 
349
351
  def test_heading ()
@@ -359,9 +361,9 @@ class TestProcessingVector < Test::Unit::TestCase
359
361
  end
360
362
 
361
363
  def test_lerp ()
362
- assert_equal vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp(vec(1, 1, 1), 0.5)
363
- assert_equal vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp( 1, 1, 1, 0.5)
364
- assert_equal vec(0.5, 0.5, 0.5), V.lerp(vec(0, 0, 0), vec(1, 1, 1), 0.5)
364
+ assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp(vec(1, 1, 1), 0.5)
365
+ assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp( 1, 1, 1, 0.5)
366
+ assert_equal_vector vec(0.5, 0.5, 0.5), V.lerp(vec(0, 0, 0), vec(1, 1, 1), 0.5)
365
367
  end
366
368
 
367
369
  def test_random2D ()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-01 00:00:00.000000000 Z
11
+ date: 2020-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
@@ -120,6 +120,7 @@ files:
120
120
  - lib/rubysketch/processing.rb
121
121
  - lib/rubysketch/window.rb
122
122
  - rubysketch.gemspec
123
+ - test/helper.rb
123
124
  - test/processing/test_vector.rb
124
125
  homepage: https://github.com/xord/rubysketch
125
126
  licenses: []
@@ -144,4 +145,5 @@ signing_key:
144
145
  specification_version: 4
145
146
  summary: Processing like Creative Coding Framework.
146
147
  test_files:
148
+ - test/helper.rb
147
149
  - test/processing/test_vector.rb