spiro 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,53 @@
1
+ #ifndef _SPIROENTRYPOINTS_H
2
+ # define _SPIROENTRYPOINTS_H
3
+ # include "bezctx_intf.h"
4
+ # include "_spiro.h"
5
+
6
+ /* Possible values of the "ty" field. */
7
+ #define SPIRO_CORNER 'v'
8
+ #define SPIRO_G4 'o'
9
+ #define SPIRO_G2 'c'
10
+ #define SPIRO_LEFT '['
11
+ #define SPIRO_RIGHT ']'
12
+
13
+ /* For a closed contour add an extra cp with a ty set to */
14
+ #define SPIRO_END 'z'
15
+ /* For an open contour the first cp must have a ty set to*/
16
+ #define SPIRO_OPEN_CONTOUR '{'
17
+ /* For an open contour the last cp must have a ty set to */
18
+ #define SPIRO_END_OPEN_CONTOUR '}'
19
+
20
+ /* These 2 functions are kept for backwards compatibility for older */
21
+ /* programs. Please use the functions listed afterwards that return */
22
+ /* success/failure replies when done. */
23
+ extern void TaggedSpiroCPsToBezier(spiro_cp *spiros,bezctx *bc);
24
+ extern void SpiroCPsToBezier(spiro_cp *spiros,int n,int isclosed,bezctx *bc);
25
+
26
+
27
+
28
+ /* These functions are available in libspiro-0.2.20130930 or higher */
29
+
30
+ /* The two functions below return 1 upon success and 0 upon failure */
31
+
32
+ /* The spiros array should indicate it's own end... So */
33
+ /* Open contours must have the ty field of the first cp set to '{' */
34
+ /* and have the ty field of the last cp set to '}' */
35
+ /* Closed contours must have an extra cp at the end whose ty is 'z' */
36
+ /* the x&y values of this extra cp are ignored */
37
+ extern int TaggedSpiroCPsToBezier0(spiro_cp *spiros,bezctx *bc);
38
+
39
+ /* The first argument is an array of spiro control points. */
40
+ /* Open contours do not need to start with '{', nor to end with '}' */
41
+ /* Close contours do not need to end with 'z' */
42
+ extern int SpiroCPsToBezier0(spiro_cp *spiros,int n,int isclosed,bezctx *bc);
43
+
44
+
45
+
46
+ /* These functions are available in libspiro-0.3.20150131 or higher */
47
+
48
+ /* If you can't use TaggedSpiroCPsToBezier0(), SpiroCPsToBezier0(), */
49
+ /* these functions are enhanced versions of the original functions, */
50
+ /* where spiro success/failure replies are passd back through *done */
51
+ extern void TaggedSpiroCPsToBezier1(spiro_cp *spiros,bezctx *bc,int *done);
52
+ extern void SpiroCPsToBezier1(spiro_cp *spiros,int n,int isclosed,bezctx *bc,int *done);
53
+ #endif
@@ -0,0 +1,17 @@
1
+ #ifndef _ZMISC_H
2
+ # define _ZMISC_H
3
+ /**
4
+ * Misc portability and convenience macros.
5
+ **/
6
+
7
+ #include <stdlib.h>
8
+
9
+ #define zalloc malloc
10
+ #define zrealloc realloc
11
+ #define zfree free
12
+
13
+ #define znew(type, n) (type *)zalloc(sizeof(type) * (n))
14
+ #define zrenew(type, p, n) (type *)zrealloc((p), sizeof(type) * (n))
15
+ #endif
16
+
17
+
@@ -0,0 +1,6 @@
1
+ require 'spiro/version'
2
+ require 'spiro/spiro'
3
+
4
+ module Spiro
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,3 @@
1
+ module Spiro
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spiro/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spiro"
8
+ spec.version = Spiro::VERSION
9
+ spec.authors = ["Raph Levien", "George Williams", "Simon George"]
10
+ spec.email = ["simon@sfcgeorge.co.uk"]
11
+ spec.summary = %q{Ruby bindings for Spiro}
12
+ spec.description = %q{Bundle the C library.}
13
+ spec.homepage = ""
14
+ spec.license = "GNU GPL 3+"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test)/})
19
+ spec.require_paths = ["lib"]
20
+ spec.extensions = "ext/spiro/extconf.rb"
21
+
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "hoe-debugging", "~> 1.2"
26
+ spec.add_development_dependency "hoe", "~> 3.13"
27
+ end
@@ -0,0 +1,69 @@
1
+ require 'minitest/autorun'
2
+ require 'spiro'
3
+
4
+ class TestSpiro < Minitest::Test
5
+ def rand_n
6
+ [
7
+ Random.rand(-100..100),
8
+ Random.rand(-100..100),
9
+ [:node, :g2, :g4, :left, :right].sample
10
+ ]
11
+ end
12
+
13
+ def test_spiros_to_splines_raises_on_bad_input
14
+ assert_raises TypeError do
15
+ Spiro.spiros_to_splines(nil, true)
16
+ end
17
+ assert_raises TypeError do
18
+ Spiro.spiros_to_splines([1, 2, 3], true)
19
+ end
20
+ assert_raises TypeError do
21
+ Spiro.spiros_to_splines([[1, 2, 3]], true)
22
+ end
23
+ assert_raises ArgumentError do
24
+ Spiro.spiros_to_splines([[1, 2, :foo]], true)
25
+ end
26
+ assert_raises ArgumentError do
27
+ Spiro.spiros_to_splines([[1, 2, :node, 4]], true)
28
+ end
29
+ end
30
+
31
+ def test_spiros_to_splines_returns_array
32
+ splines = Spiro.spiros_to_splines(
33
+ [[0, 0, :node], [100, 50, :g2], [-50, 300, :node]],
34
+ true)
35
+ assert_kind_of Array, splines
36
+ end
37
+
38
+ #def test_spiros_to_splines_with_random_data_stress_test
39
+ ## It will crash after a while, see below
40
+ #while true do
41
+ #path = Random.rand(5..50).times.map{rand_n}
42
+ #p path
43
+ #splines = Spiro.spiros_to_splines(path, true)
44
+ #assert_includes [Array, NilClass], splines.class
45
+ #end
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
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spiro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Raph Levien
8
+ - George Williams
9
+ - Simon George
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-04-05 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.7'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: hoe-debugging
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.2'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.2'
57
+ - !ruby/object:Gem::Dependency
58
+ name: hoe
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.13'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '3.13'
71
+ description: Bundle the C library.
72
+ email:
73
+ - simon@sfcgeorge.co.uk
74
+ executables: []
75
+ extensions:
76
+ - ext/spiro/extconf.rb
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - ext/spiro/_spiro.c
85
+ - ext/spiro/_spiro.h
86
+ - ext/spiro/bezctx.c
87
+ - ext/spiro/bezctx.h
88
+ - ext/spiro/bezctx_intf.h
89
+ - ext/spiro/bezctx_rb.c
90
+ - ext/spiro/bezctx_rb.h
91
+ - ext/spiro/extconf.rb
92
+ - ext/spiro/spiro.c
93
+ - ext/spiro/spiroentrypoints.c
94
+ - ext/spiro/spiroentrypoints.h
95
+ - ext/spiro/zmisc.h
96
+ - lib/spiro.rb
97
+ - lib/spiro/version.rb
98
+ - spiro.gemspec
99
+ - test/test_spiro.rb
100
+ homepage: ''
101
+ licenses:
102
+ - GNU GPL 3+
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.4.5
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Ruby bindings for Spiro
124
+ test_files:
125
+ - test/test_spiro.rb
126
+ has_rdoc: