spiro 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -2
- data/lib/spiro.rb +0 -1
- data/lib/spiro/version.rb +1 -1
- data/test/test_spiro.rb +2 -24
- 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: d7ea81ccb6dc0f98c003f24d474ba3b34f246601
|
4
|
+
data.tar.gz: 8d0f682b693e55e32acfe428aef0ca6dc0338b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc6f2f0a04843331562b99cf8eb5733671c8993215a61ee911ccb1affd3b642f37e71a7c4dba8371dca4b0390c3b46df9d60c807eae66453ac5873f7e0d138d9
|
7
|
+
data.tar.gz: 363483c7472837abf2d1dd8197b453e780e287a63433542567dd4f450eb3e20396808b79fd8bb90e57d33fe507ade009c458609cce6efbcbf6136ad26dfe44fb
|
data/README.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Spiro
|
2
2
|
|
3
|
-
|
3
|
+
A Ruby wrapper for [libspiro](https://github.com/fontforge/libspiro), which is itself a bundling of [Spiro](http://levien.com/spiro/) by Raph Levien.
|
4
|
+
|
5
|
+
Spiro makes drawing beautiful curves easy.
|
6
|
+
|
7
|
+
Usually Bézier splines are used for curves. These require off-curve points which "bend" the line towards them. As these points aren't on the line they are quite unintuitive and it's hard to imagine where the line will end up without a GUI.
|
8
|
+
|
9
|
+
Raph Levien's Spiro splines only use on-curve points and so are easier to use and more intuitive to the artist. They make it easy to maintain constant curvature as well as constant slope. Such curves will simply look nicer.
|
10
|
+
|
11
|
+
This library will take an array of Spiro control points and convert them into a series of Bézier splines which can then be used in the myriad of ways the world has come to use Béziers.
|
12
|
+
|
13
|
+
It was created for the design as code tool [Vector Salad](https://github.com/sfcgeorge/vector_salad).
|
14
|
+
|
4
15
|
|
5
16
|
## Installation
|
6
17
|
|
@@ -18,9 +29,30 @@ Or install it yourself as:
|
|
18
29
|
|
19
30
|
$ gem install spiro
|
20
31
|
|
32
|
+
|
21
33
|
## Usage
|
22
34
|
|
23
|
-
|
35
|
+
```ruby
|
36
|
+
# takes an array of spiro points and returns an array of bezier points
|
37
|
+
# (this will potentially contain both cubic and quadratic beziers)
|
38
|
+
splines = Spiro.spiros_to_splines(
|
39
|
+
[[0, 0, :node], [100, 50, :g2], [-50, 300, :node]],
|
40
|
+
true # the path is closed
|
41
|
+
)
|
42
|
+
```
|
43
|
+
|
44
|
+
### Node types:
|
45
|
+
|
46
|
+
* :node, a standard non curved point
|
47
|
+
* :g2, a node with g2 curvature
|
48
|
+
* :g4, a node with g4 curvature
|
49
|
+
* :left, used to connect a curved line to a straight one
|
50
|
+
* :right, used to connect a straight line to a curved one. If you have a contour which is drawn clockwise, and you have a straight segment at the top, then the left point of that straight segment should be a left constraint, and the right point should be a right constraint.
|
51
|
+
|
52
|
+
It's often best to just experiment with the above until you get the desired result.
|
53
|
+
|
54
|
+
If it fails to produce a curve, then try switching between g2 and g4 points, and generally experimenting with moving nodes around.
|
55
|
+
|
24
56
|
|
25
57
|
## Contributing
|
26
58
|
|
data/lib/spiro.rb
CHANGED
data/lib/spiro/version.rb
CHANGED
data/test/test_spiro.rb
CHANGED
@@ -31,12 +31,12 @@ class TestSpiro < Minitest::Test
|
|
31
31
|
def test_spiros_to_splines_returns_array
|
32
32
|
splines = Spiro.spiros_to_splines(
|
33
33
|
[[0, 0, :node], [100, 50, :g2], [-50, 300, :node]],
|
34
|
-
|
34
|
+
true
|
35
|
+
)
|
35
36
|
assert_kind_of Array, splines
|
36
37
|
end
|
37
38
|
|
38
39
|
#def test_spiros_to_splines_with_random_data_stress_test
|
39
|
-
## It will crash after a while, see below
|
40
40
|
#while true do
|
41
41
|
#path = Random.rand(5..50).times.map{rand_n}
|
42
42
|
#p path
|
@@ -44,26 +44,4 @@ class TestSpiro < Minitest::Test
|
|
44
44
|
#assert_includes [Array, NilClass], splines.class
|
45
45
|
#end
|
46
46
|
#end
|
47
|
-
|
48
|
-
def test_this_one_crashes
|
49
|
-
# I sometimes get "pointer being freed was not allocated" but it takes a while.
|
50
|
-
# I thought it might be some nodes that Spiro doesn't like, but these are fine
|
51
|
-
# sometimes, it's only after running several times that it crashes.
|
52
|
-
# There must be a bad bit of memory management somewhere :-/
|
53
|
-
#
|
54
|
-
# Other times I get "Segmentation fault".
|
55
|
-
#
|
56
|
-
# It can crash very quickly, or it can take several seconds. So I'm guessing
|
57
|
-
# that there a piece of memory is being freed when it shouldn't somewhere,
|
58
|
-
# and it depends where that memory is whether it hurts anything. Not good.
|
59
|
-
#
|
60
|
-
# Anyway, I don't really know C and because all of the Ruby stacktrace
|
61
|
-
# thrown in I can't figure out if the problem is in my code or Spiro.
|
62
|
-
# Does anyone know C well enough to fix this?
|
63
|
-
path = [[-39, -57, :g2], [-59, 20, :right], [37, -14, :g2], [-67, -40, :g2], [-83, 20, :g2], [56, -87, :left], [-11, 86, :left], [11, 29, :left], [-87, 54, :left]]
|
64
|
-
while true do
|
65
|
-
splines = Spiro.spiros_to_splines(path, true)
|
66
|
-
assert_includes [Array, NilClass], splines.class
|
67
|
-
end
|
68
|
-
end
|
69
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spiro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raph Levien
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-09-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|