beziercurve 0.2 → 0.6
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.
- checksums.yaml +4 -4
- data/lib/beziercurve.rb +18 -25
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27e5be3280b88a9b7f105e9684bb3e92fad3ed9c
|
4
|
+
data.tar.gz: a2ec45dfe488b6deb17073ca90c140d5a2acdf10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3344ae1275b60c6fb196efcd50f0cc30e8aafc07de95a075b4e8b6509c12577dbadc805caf6aee60d82440f1dd4c8b3017c71e4b1d0e4a7f99040d8e55f80a22
|
7
|
+
data.tar.gz: 65a9f4e29b4d02cb99facde883c9e5a1f5c98f650ef4cb2b610bfe3aee288e15d849ff2a78bfb879c6366ac62003d8e88ad091c0aa163e1c182e98715fed488b
|
data/lib/beziercurve.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Bezier
|
2
2
|
|
3
3
|
class ControlPoint
|
4
|
-
# maybe replace the accessors and initialization with Struct
|
5
4
|
attr_accessor :x, :y
|
6
5
|
def initialize(x,y)
|
7
6
|
@x = x
|
@@ -20,39 +19,40 @@ module Bezier
|
|
20
19
|
CurvePoint.new(self.x, self.y)
|
21
20
|
end
|
22
21
|
end
|
23
|
-
class CurvePoint < ControlPoint
|
22
|
+
class CurvePoint < ControlPoint
|
23
|
+
# @return [ControlPoint] the object converted into the expected format.
|
24
24
|
def to_control
|
25
25
|
ControlPoint.new(self.x, self.y)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
class Curve
|
29
|
-
attr_accessor :
|
29
|
+
attr_accessor :controlpoints
|
30
30
|
|
31
|
-
def initialize(*
|
31
|
+
def initialize(*controlpoints)
|
32
32
|
# need at least 3 control points
|
33
|
-
if
|
34
|
-
raise
|
33
|
+
if controlpoints.length < 3
|
34
|
+
raise 'Cannot create Bézier curve with less than 3 control points'
|
35
35
|
end
|
36
36
|
|
37
|
-
# check for
|
38
|
-
if
|
39
|
-
@
|
37
|
+
# check for proper types
|
38
|
+
if controlpoints.find {|p| p.class != ControlPoint} == nil
|
39
|
+
@controlpoints = controlpoints
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
def add(point)
|
44
44
|
if point.class == ControlPoint
|
45
|
-
@
|
45
|
+
@controlpoints << point
|
46
46
|
else
|
47
|
-
raise TypeError,
|
47
|
+
raise TypeError, 'Point should be type of ControlPoint'
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def point_on_curve(t)
|
52
|
-
|
52
|
+
|
53
53
|
def point_on_hull(point1, point2, t) # making this local
|
54
54
|
if (point1.class != ControlPoint) or (point2.class != ControlPoint)
|
55
|
-
raise TypeError,
|
55
|
+
raise TypeError, 'Both points should be type of ControlPoint'
|
56
56
|
end
|
57
57
|
new_x = (point1.x - point2.x) * t
|
58
58
|
new_y = (point1.y - point2.y) * t
|
@@ -60,14 +60,14 @@ module Bezier
|
|
60
60
|
end
|
61
61
|
|
62
62
|
# imperatively ugly but works, refactor later. point_on_curve and point_on_hull should be one method
|
63
|
-
ary = @
|
63
|
+
ary = @controlpoints
|
64
64
|
return ary if ary.length <= 1 # zero or one element as argument, return unmodified
|
65
65
|
|
66
66
|
while ary.length > 1
|
67
67
|
temp = []
|
68
68
|
0.upto(ary.length-2) do |index|
|
69
|
-
memoize1 = point_on_hull(ary[index], ary[index+1], t)
|
70
|
-
temp << ary[index+0] - memoize1
|
69
|
+
memoize1 = point_on_hull(ary[index], ary[index+1], t)
|
70
|
+
temp << ary[index+0] - memoize1
|
71
71
|
end
|
72
72
|
ary = temp
|
73
73
|
end
|
@@ -75,7 +75,7 @@ module Bezier
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def display_points # just a helper, for quickly put CotrolPOints to STDOUT in a gnuplottable format
|
78
|
-
@
|
78
|
+
@controlpoints.map{|point| puts "#{point.x} #{point.y}"}
|
79
79
|
end
|
80
80
|
|
81
81
|
def enumerated(start_t, delta_t)
|
@@ -92,14 +92,7 @@ module Bezier
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def order
|
95
|
-
@
|
95
|
+
@controlpoints.length
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
100
|
-
__END__
|
101
|
-
|
102
|
-
bezier = Bezier::Curve.new(Bezier::ControlPoint.new(40,250), Bezier::ControlPoint.new(35,100), Bezier::ControlPoint.new(150,70), Bezier::ControlPoint.new(210,120)) # cubic curve, 4 coordinates
|
103
|
-
|
104
|
-
puts bezier.hullpoints[0].x
|
105
|
-
#puts "#{bezier.point_on_curve(0.013).x} #{bezier.point_on_curve(0.013).y}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beziercurve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Földes László
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Creates a Bézier curve by its control points. Implemented with de Casteljau
|
14
14
|
method.
|
@@ -41,6 +41,6 @@ rubyforge_project:
|
|
41
41
|
rubygems_version: 2.1.10
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
|
-
summary: Create
|
44
|
+
summary: Create and analyze Bézier curves
|
45
45
|
test_files: []
|
46
46
|
has_rdoc:
|