bezier_curve 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bezier_curve/version.rb +2 -2
- data/lib/bezier_curve.rb +24 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 709f03eca452fc052bfd88bcfd82ba5fd164d9e5
|
4
|
+
data.tar.gz: 7984799097c6219ee7fbd93eebcd5a896f012784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c716841eb06ea58bdc2ddfbd32ac49cd3ed7943c79218a88f75fe8a32dec23b32ccb68ed07b0311f3b5bbb427b41c241723f926ed443b1ef6beaefe71442a769
|
7
|
+
data.tar.gz: 6c872c796a68fd935d95750d77e2859aa0001dd274f083e6eaa474c81dbb30c1b89799d6a1c96670f87c45a79e497079dfcdeb12e0c41d99ce63e037bdc1a9b3
|
data/lib/bezier_curve/version.rb
CHANGED
data/lib/bezier_curve.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
require 'bezier_curve/version'
|
6
6
|
require 'bezier_curve/n_point'
|
7
7
|
|
8
|
-
#
|
8
|
+
# Creates a bezier curve. Usage:
|
9
9
|
# c = BezierCurve.new([0,0], [0,1], [1,1])
|
10
10
|
# c.first #=> [0,0]
|
11
11
|
# c.last #=> [1,1]
|
@@ -86,13 +86,22 @@ class BezierCurve
|
|
86
86
|
end
|
87
87
|
|
88
88
|
# recursively subdivides the curve until each is straight within the
|
89
|
-
# given tolerance value, in radians
|
89
|
+
# given tolerance value, in radians. Then, subdivides further as
|
90
|
+
# needed to remove remaining corners.
|
90
91
|
def subdivide(tolerance)
|
91
|
-
if is_straight?
|
92
|
+
if is_straight? tolerance
|
92
93
|
[self]
|
93
94
|
else
|
94
|
-
a,b = split_at(0.5)
|
95
|
-
a
|
95
|
+
a,b = split_at(0.5).map{|c| c.subdivide(tolerance)}
|
96
|
+
# now make sure the angle from a to b is good
|
97
|
+
while a.last.first.angle_to(a.last.last,b.first.last) > tolerance
|
98
|
+
if a.last.divergence > b.first.divergence
|
99
|
+
a[-1,1] = a[-1].split_at(0.5)
|
100
|
+
else
|
101
|
+
b[0,1] = b[0].split_at(0.5)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
a+b
|
96
105
|
end
|
97
106
|
end
|
98
107
|
|
@@ -100,8 +109,8 @@ class BezierCurve
|
|
100
109
|
# test this curve to see of it can be considered straight, optionally
|
101
110
|
# within the given angular tolerance, in radians
|
102
111
|
def is_straight?(tolerance)
|
103
|
-
#
|
104
|
-
if
|
112
|
+
# normal check for tolerance
|
113
|
+
if divergence <= tolerance
|
105
114
|
# maximum wavyness is `degree` - 1; split at `degree` points
|
106
115
|
pts = points(count:degree)
|
107
116
|
# size-3, because we ignore the last 2 points as starting points;
|
@@ -109,11 +118,18 @@ class BezierCurve
|
|
109
118
|
(0..pts.size-3).all? do |i|
|
110
119
|
pts[i].angle_to(pts[i+1], pts[i+2]) < tolerance
|
111
120
|
end
|
121
|
+
else
|
122
|
+
false
|
112
123
|
end
|
113
124
|
end
|
114
125
|
|
126
|
+
# How much this curve diverges from straight, measuring from `t=0.5`
|
127
|
+
def divergence
|
128
|
+
first.angle_to(self[0.5],last)
|
129
|
+
end
|
130
|
+
|
115
131
|
# Indicates an error where the control points are in zero dimensions.
|
116
|
-
# Sounds silly, but you never know when software is generating the
|
132
|
+
# Sounds silly, but you never know, when software is generating the
|
117
133
|
# points.
|
118
134
|
class ZeroDimensionError < ArgumentError
|
119
135
|
def initialize
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bezier_curve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Hubbart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A bézier curve library for Ruby, supporting n-dimensional, nth-degree
|
14
14
|
curves
|