vector_salad 0.0.7 → 0.0.8

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.yardopts +1 -0
  4. data/README.md +6 -5
  5. data/examples/birthday.png +0 -0
  6. data/examples/birthday.svg +604 -604
  7. data/examples/bunny_card.png +0 -0
  8. data/examples/bunny_card.svg +110 -110
  9. data/examples/circles.png +0 -0
  10. data/examples/circles.svg +2 -2
  11. data/examples/rects.rb +4 -4
  12. data/examples/squares.png +0 -0
  13. data/examples/squares.rb +4 -4
  14. data/examples/squares.svg +6 -6
  15. data/lib/contracts_contracts.rb +4 -4
  16. data/lib/vector_salad/canvas.rb +17 -0
  17. data/lib/vector_salad/dsl.rb +29 -28
  18. data/lib/vector_salad/export_with_magic.rb +1 -0
  19. data/lib/vector_salad/exporters/base_exporter.rb +1 -0
  20. data/lib/vector_salad/exporters/svg_exporter.rb +30 -22
  21. data/lib/vector_salad/interpolate.rb +13 -12
  22. data/lib/vector_salad/magic.rb +4 -3
  23. data/lib/vector_salad/mixins/at.rb +1 -0
  24. data/lib/vector_salad/mixins/mixins.rb +5 -0
  25. data/lib/vector_salad/monkeypatches.rb +4 -0
  26. data/lib/vector_salad/shape_proxy.rb +1 -0
  27. data/lib/vector_salad/standard_shapes/basic_shape.rb +25 -17
  28. data/lib/vector_salad/standard_shapes/circle.rb +9 -3
  29. data/lib/vector_salad/standard_shapes/clip.rb +10 -9
  30. data/lib/vector_salad/standard_shapes/custom.rb +23 -4
  31. data/lib/vector_salad/standard_shapes/difference.rb +5 -6
  32. data/lib/vector_salad/standard_shapes/exclusion.rb +5 -6
  33. data/lib/vector_salad/standard_shapes/flip.rb +8 -2
  34. data/lib/vector_salad/standard_shapes/heart.rb +3 -1
  35. data/lib/vector_salad/standard_shapes/hexagon.rb +3 -2
  36. data/lib/vector_salad/standard_shapes/intersection.rb +5 -6
  37. data/lib/vector_salad/standard_shapes/iso_tri.rb +3 -2
  38. data/lib/vector_salad/standard_shapes/jitter.rb +10 -7
  39. data/lib/vector_salad/standard_shapes/move.rb +7 -1
  40. data/lib/vector_salad/standard_shapes/multi_path.rb +17 -6
  41. data/lib/vector_salad/standard_shapes/n.rb +6 -3
  42. data/lib/vector_salad/standard_shapes/oval.rb +3 -1
  43. data/lib/vector_salad/standard_shapes/path.rb +28 -14
  44. data/lib/vector_salad/standard_shapes/pentagon.rb +2 -1
  45. data/lib/vector_salad/standard_shapes/polygon.rb +3 -1
  46. data/lib/vector_salad/standard_shapes/rect.rb +3 -1
  47. data/lib/vector_salad/standard_shapes/rotate.rb +3 -5
  48. data/lib/vector_salad/standard_shapes/scale.rb +8 -7
  49. data/lib/vector_salad/standard_shapes/square.rb +6 -21
  50. data/lib/vector_salad/standard_shapes/standard_shapes.rb +6 -0
  51. data/lib/vector_salad/standard_shapes/transform.rb +6 -5
  52. data/lib/vector_salad/standard_shapes/triangle.rb +3 -2
  53. data/lib/vector_salad/standard_shapes/union.rb +5 -6
  54. data/lib/vector_salad/version.rb +1 -1
  55. data/lib/vector_salad.rb +1 -1
  56. metadata +4 -2
@@ -2,10 +2,11 @@ require "vector_salad/standard_shapes/polygon"
2
2
 
3
3
  module VectorSalad
4
4
  module StandardShapes
5
+ # Regular pentagon shape.
5
6
  class Pentagon < Polygon
6
7
  # Create a regular pentagon.
7
8
  #
8
- # Examples:
9
+ # @example
9
10
  # new(100)
10
11
  def initialize(radius, **options)
11
12
  super(5, radius, **options)
@@ -4,13 +4,14 @@ require "vector_salad/mixins/at"
4
4
 
5
5
  module VectorSalad
6
6
  module StandardShapes
7
+ # Regular polygon shape.
7
8
  class Polygon < BasicShape
8
9
  include VectorSalad::Mixins::At
9
10
  attr_reader :sides
10
11
 
11
12
  # Create a regular polygon with a specified number of sides.
12
13
  #
13
- # Examples:
14
+ # @example
14
15
  # new(6, 100)
15
16
  Contract PolySides, Pos, {} => Polygon
16
17
  def initialize(sides, radius, **options)
@@ -20,6 +21,7 @@ module VectorSalad
20
21
  self
21
22
  end
22
23
 
24
+ # Convert the shape to a path
23
25
  def to_path
24
26
  nodes = []
25
27
  angle = 2 * Math::PI / @sides
@@ -4,13 +4,14 @@ require "vector_salad/mixins/at"
4
4
 
5
5
  module VectorSalad
6
6
  module StandardShapes
7
+ # Rectangle shape.
7
8
  class Rect < BasicShape
8
9
  include VectorSalad::Mixins::At
9
10
  attr_reader :width, :height
10
11
 
11
12
  # Create a rectangle with specified width and height.
12
13
  #
13
- # Examples:
14
+ # @example
14
15
  # new(100, 200)
15
16
  Contract Pos, Pos, {} => Rect
16
17
  def initialize(width, height, **options)
@@ -20,6 +21,7 @@ module VectorSalad
20
21
  self
21
22
  end
22
23
 
24
+ # Convert the shape to a path
23
25
  def to_path
24
26
  Path.new(
25
27
  N.n(@x, @y),
@@ -1,12 +1,10 @@
1
- require 'vector_salad/standard_shapes/transform'
1
+ require "vector_salad/standard_shapes/transform"
2
2
 
3
3
  module VectorSalad
4
4
  module StandardShapes
5
+ # Rotates the contained shapes by the specified angle about the origin.
5
6
  class Rotate < Transform
6
- # Rotates the contained shapes by the specified angle about the origin.
7
- #
8
- # Examples:
9
- #
7
+ # @example
10
8
  # rotate(45) do
11
9
  # triangle(30, at: [50, -50])
12
10
  # pentagon(40, at: [50, -100])
@@ -1,24 +1,25 @@
1
- require 'vector_salad/standard_shapes/transform'
1
+ require "vector_salad/standard_shapes/transform"
2
2
 
3
3
  module VectorSalad
4
4
  module StandardShapes
5
+ # Scale the contained shapes by multiplier about the origin.
5
6
  class Scale < Transform
6
- # Scale the contained shapes by multiplier about the origin.
7
- # Supply just 1 multiplier to scale evenly, or x and y multipliers
8
- # to stretch or squash the axies.
9
- # @param x_multiplier 1 is no change, 2 is double size, 0.5 is half, etc.
10
- #
11
- # Examples:
7
+ # Supply just 1 multiplier to scale evenly,
8
+ # or x and y multipliers to stretch or squash the axies.
12
9
  #
10
+ # @example
13
11
  # scale(2) do
14
12
  # triangle(30, at: [50, -50])
15
13
  # pentagon(40, at: [50, -100])
16
14
  # end
17
15
  #
16
+ # @example Uneven scaling
18
17
  # scale(2, 0.5) do
19
18
  # triangle(30, at: [50, -50])
20
19
  # pentagon(40, at: [50, -100])
21
20
  # end
21
+ #
22
+ # @param x_multiplier 1 is no change, 2 is double size, 0.5 is half, etc.
22
23
  Contract Coord, Coord, { canvas: VectorSalad::Canvas }, Proc => Any
23
24
  def initialize(x_multiplier,
24
25
  y_multiplier = x_multiplier,
@@ -1,34 +1,19 @@
1
- require "vector_salad/standard_shapes/path"
2
- require "vector_salad/standard_shapes/n"
1
+ require "vector_salad/standard_shapes/rect"
3
2
  require "vector_salad/mixins/at"
4
3
 
5
4
  module VectorSalad
6
5
  module StandardShapes
7
- class Square < BasicShape
8
- include VectorSalad::Mixins::At
9
- attr_reader :size
10
-
6
+ # Square shape with equal width and height.
7
+ class Square < Rect
11
8
  # Create a square with equal width and height.
12
9
  #
13
- # Examples:
14
- # new(100).detail 'Square sides 100x100 at 0,0.'
10
+ # @example Square with sides 100x100
11
+ # new(100)
15
12
  Contract Pos, {} => Square
16
13
  def initialize(size, **options)
17
- @size = size
18
- @options = options
19
- @x, @y = 0, 0
14
+ super(size, size, **options)
20
15
  self
21
16
  end
22
-
23
- def to_path
24
- Path.new(
25
- N.n(@x, @y),
26
- N.n(@x, @y + @size),
27
- N.n(@x + @size, @y + @size),
28
- N.n(@x + @size, @y),
29
- **@options
30
- )
31
- end
32
17
  end
33
18
  end
34
19
  end
@@ -0,0 +1,6 @@
1
+ module VectorSalad
2
+ # All standard shapes built into Vector Salad.
3
+ # Your compositions will be made from combinations of these.
4
+ module StandardShapes
5
+ end
6
+ end
@@ -1,12 +1,13 @@
1
- require 'contracts'
2
- require 'contracts_contracts'
1
+ require "contracts"
2
+ require "contracts_contracts"
3
3
 
4
- require 'vector_salad/dsl'
5
- require 'vector_salad/canvas'
6
- require 'vector_salad/standard_shapes/path'
4
+ require "vector_salad/dsl"
5
+ require "vector_salad/canvas"
6
+ require "vector_salad/standard_shapes/path"
7
7
 
8
8
  module VectorSalad
9
9
  module StandardShapes
10
+ # @api private
10
11
  class Transform
11
12
  include VectorSalad::DSL
12
13
  include VectorSalad::StandardShapes
@@ -2,10 +2,11 @@ require "vector_salad/standard_shapes/polygon"
2
2
 
3
3
  module VectorSalad
4
4
  module StandardShapes
5
+ # Equilateral triangle shape.
5
6
  class Triangle < Polygon
6
- # Create an equilateral triangle.
7
+ # Create a new equilateral triangle.
7
8
  #
8
- # Examples:
9
+ # @example
9
10
  # new(100)
10
11
  def initialize(radius, **options)
11
12
  super(3, radius, **options)
@@ -1,21 +1,20 @@
1
- require 'vector_salad/standard_shapes/clip'
2
- require 'vector_salad/standard_shapes/multi_path'
1
+ require "vector_salad/standard_shapes/clip"
2
+ require "vector_salad/standard_shapes/multi_path"
3
3
 
4
4
  module VectorSalad
5
5
  module StandardShapes
6
+ # Unite the contained shapes.
6
7
  class Union < Clip
7
- # Unite paths.
8
8
  # The first path is used as the subject, subsequent paths are united
9
9
  # with the first.
10
10
  #
11
- # Examples:
12
- #
11
+ # @example
13
12
  # Union.new do
14
13
  # canvas << Path.new([0,0], [90,90], [0,90])
15
14
  # canvas << Path.new([50,0], [95,0], [50, 70])
16
15
  # end
17
16
  #
18
- # # Using DSL:
17
+ # @example Using DSL:
19
18
  # union do
20
19
  # path([0,0], [90,90], [0,90])
21
20
  # path([50,0], [95,0], [50, 70])
@@ -1,3 +1,3 @@
1
1
  module VectorSalad
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8" # Version of VectorSalad
3
3
  end
data/lib/vector_salad.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "vector_salad/version"
2
2
 
3
+ # Top level namespace for Vector Salad, the design as code tool.
3
4
  module VectorSalad
4
- # Your code goes here...
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vector_salad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon George
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-12 00:00:00.000000000 Z
11
+ date: 2015-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pretty_backtrace
@@ -208,6 +208,7 @@ files:
208
208
  - lib/vector_salad/interpolate.rb
209
209
  - lib/vector_salad/magic.rb
210
210
  - lib/vector_salad/mixins/at.rb
211
+ - lib/vector_salad/mixins/mixins.rb
211
212
  - lib/vector_salad/monkeypatches.rb
212
213
  - lib/vector_salad/shape_proxy.rb
213
214
  - lib/vector_salad/standard_shapes/basic_shape.rb
@@ -233,6 +234,7 @@ files:
233
234
  - lib/vector_salad/standard_shapes/rotate.rb
234
235
  - lib/vector_salad/standard_shapes/scale.rb
235
236
  - lib/vector_salad/standard_shapes/square.rb
237
+ - lib/vector_salad/standard_shapes/standard_shapes.rb
236
238
  - lib/vector_salad/standard_shapes/transform.rb
237
239
  - lib/vector_salad/standard_shapes/triangle.rb
238
240
  - lib/vector_salad/standard_shapes/union.rb