rbclipper 6.4.2.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog +13 -0
- data/Gemfile +4 -0
- data/LICENSE.bindings +4 -0
- data/LICENSE.clipper +29 -0
- data/README.md +188 -0
- data/Rakefile +15 -0
- data/ext/clipper/clipper.cpp +4629 -0
- data/ext/clipper/clipper.hpp +406 -0
- data/ext/clipper/extconf.rb +6 -0
- data/ext/clipper/rbclipper.cpp +530 -0
- data/lib/clipper/version.rb +6 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ee44553b5149133be9e0b584f7fd640c78cfe8af0f955422711fe161f95bee54
|
4
|
+
data.tar.gz: bc6bb6faf63513bc38af6e985f45fbe72253af58086f15f7c947a409304e9baa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4610eebd6a2344715ad801c2009e223d9010d6e9189622b92b12369be9593dc63eceecb9709464de6efa4cc084a06a9a4aef29e191ee39a07991fd553aafaf85
|
7
|
+
data.tar.gz: 02acf0f35cddb8f2ebacf1e8f55bb17d0546a308490e2af6b0c2e05d885480d352a46e301dee918c30b483a9ba5d54e89a737a85b064fece8fc01ab50ae3b761
|
data/Changelog
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
2018-04-22 Kjell Morgenstern
|
2
|
+
* Upstream 6.4.2
|
3
|
+
* Added unit tests and travis.ci
|
4
|
+
* Added support for polylines
|
5
|
+
* Added support for minkowski sum and diff
|
6
|
+
* Breaking change: PtInPolygon was replaced with PointInPolygon. Now returns same values as Clipper.
|
7
|
+
|
8
|
+
2010-12-08 Mike Owens <http://mike.filespanker.com>
|
9
|
+
* Gemification and Ruby 1.8.7 fixes courtesy of Tom Agnew
|
10
|
+
* Upstream 2.9
|
11
|
+
|
12
|
+
2010-10-17 Mike Owens <http://mike.filespanker.com>
|
13
|
+
* Pull upstream 2.522
|
data/Gemfile
ADDED
data/LICENSE.bindings
ADDED
data/LICENSE.clipper
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
The Clipper code library, the "Software" (including Delphi and C++ code
|
2
|
+
and accompanying documentation), has been released under the following
|
3
|
+
license, terms and conditions:
|
4
|
+
|
5
|
+
Boost Software License - Version 1.0 - August 17th, 2003
|
6
|
+
http://www.boost.org/LICENSE_1_0.txt
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person or organization
|
9
|
+
obtaining a copy of the software and accompanying documentation covered by
|
10
|
+
this license (the "Software") to use, reproduce, display, distribute,
|
11
|
+
execute, and transmit the Software, and to prepare derivative works of the
|
12
|
+
Software, and to permit third-parties to whom the Software is furnished to
|
13
|
+
do so, all subject to the following:
|
14
|
+
|
15
|
+
The copyright notices in the Software and this entire statement, including
|
16
|
+
the above license grant, this restriction and the following disclaimer,
|
17
|
+
must be included in all copies of the Software, in whole or in part, and
|
18
|
+
all derivative works of the Software, unless such copies or derivative
|
19
|
+
works are solely in the form of machine-executable object code generated by
|
20
|
+
a source language processor.
|
21
|
+
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
25
|
+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
26
|
+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
27
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
28
|
+
DEALINGS IN THE SOFTWARE.
|
29
|
+
|
data/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/KjellMorgenstern/rbclipper.svg?branch=master)](https://travis-ci.org/KjellMorgenstern/rbclipper)
|
2
|
+
|
3
|
+
|
4
|
+
Synopsis
|
5
|
+
==========
|
6
|
+
These are Ruby bindings to Clipper, Angus Johnson's Polygon clipping
|
7
|
+
library. Because Clipper is not readily packaged, and is so beautifully
|
8
|
+
self-contained, I've included the two required files in the package.
|
9
|
+
|
10
|
+
This release contains version 6.4.2 of Clipper and some improvements by
|
11
|
+
Kjell Morgenstern to add tests and support polylines.
|
12
|
+
|
13
|
+
* [Clipper Homepage](http://angusj.com/delphi/clipper.php)
|
14
|
+
* [rbclipper](http://github.com/mieko/rbclipper)
|
15
|
+
|
16
|
+
|
17
|
+
Installation
|
18
|
+
==========
|
19
|
+
|
20
|
+
This version is published as the rbclipper gem. The original mieko-based gem seems not to be maintained.
|
21
|
+
|
22
|
+
gem install rbclipper
|
23
|
+
|
24
|
+
|
25
|
+
To build locally:
|
26
|
+
|
27
|
+
rake install
|
28
|
+
|
29
|
+
|
30
|
+
Simple Usage:
|
31
|
+
===========
|
32
|
+
This should be enough to get you started. Slightly fuller documentation is below.
|
33
|
+
|
34
|
+
require 'clipper'
|
35
|
+
|
36
|
+
a = [[0, 0], [0, 100], [100, 100], [100, 0]]
|
37
|
+
b = [[-5, 50], [200, 50], [100, 5]]
|
38
|
+
|
39
|
+
c = Clipper::Clipper.new
|
40
|
+
|
41
|
+
c.add_subject_polygon(a)
|
42
|
+
c.add_clip_polygon(b)
|
43
|
+
c.union :non_zero, :non_zero
|
44
|
+
|
45
|
+
=> [[[100.0, 0.0], [0.0, 0.0], [0.0, 47.85714326530613], [-4.999999, 50.0],
|
46
|
+
[0.0, 50.0], [0.0, 100.0], [100.0, 100.0], [100.0, 50.0],
|
47
|
+
[200.0, 50.0], [100.0, 5.0]]]
|
48
|
+
|
49
|
+
Documentation
|
50
|
+
================
|
51
|
+
|
52
|
+
Clipper is a two-dimensional polygon clipping library. `rbclipper`, the Ruby
|
53
|
+
bindings can be accessed by:
|
54
|
+
|
55
|
+
require 'clipper'
|
56
|
+
|
57
|
+
|
58
|
+
Polygons
|
59
|
+
--------
|
60
|
+
Operations that accept or return polygons are specified as an array of `[x,y]`
|
61
|
+
coordinates, for example, to specify a triangle:
|
62
|
+
|
63
|
+
triangle = [[0,0], [0,100], [50, -100]]
|
64
|
+
|
65
|
+
Clipper supports both holes and complex polygons. Coordinates for output
|
66
|
+
polygons are clockwise for shells, and and counter-clockwise for holes.
|
67
|
+
See force_orientation.
|
68
|
+
|
69
|
+
Note that since 2.8, Clipper defines orientation with respect to a
|
70
|
+
_downward-increasing Y axis_, similar to how many 2D GUI/drawing APIs position
|
71
|
+
coordinate (0,0) at the top-left corner. The bindings have followed Clipper
|
72
|
+
proper in this regard.
|
73
|
+
|
74
|
+
Multiple polygons are represented as simply an array of polygons.
|
75
|
+
|
76
|
+
Fill Types
|
77
|
+
-----------
|
78
|
+
* `:even_odd`
|
79
|
+
|
80
|
+
A point is considered inside the polygon if the number of edge-crossings to
|
81
|
+
get there from outside the shape is an even number.
|
82
|
+
|
83
|
+
* `:non_zero`
|
84
|
+
|
85
|
+
A point is considered inside the polygon if the number of edge-crossings to
|
86
|
+
get there is greater than zero.
|
87
|
+
|
88
|
+
* `:positive`
|
89
|
+
|
90
|
+
See Clipper Homepage.
|
91
|
+
|
92
|
+
* `:negative`
|
93
|
+
|
94
|
+
See Clipper Homepage.
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
Clipper::Clipper Methods
|
99
|
+
-------
|
100
|
+
|
101
|
+
* `Clipper#initialize`
|
102
|
+
|
103
|
+
Creates a new clipper object.
|
104
|
+
|
105
|
+
* `Clipper#add_subject_polygon(polygon)`
|
106
|
+
|
107
|
+
* `Clipper#add_clip_polygon(polygon)`
|
108
|
+
|
109
|
+
Adds a subject or clip polygon to the engine. Boolean operations are
|
110
|
+
calculated as `SUBJECT` *operatation* `CLIP`. Multiple polygons can Pay attention
|
111
|
+
to the orientation of the coordinates given; counter-clockwise for shells and
|
112
|
+
clockwise for holes.
|
113
|
+
|
114
|
+
Multiple subject and clip polygons can be added to the engine for operations.
|
115
|
+
|
116
|
+
* `Clipper#add_subject_polygons(expolygon)`
|
117
|
+
|
118
|
+
* `Clipper#add_clip_polygons(expolygon)`
|
119
|
+
|
120
|
+
Add an "ExPolygon" to the engine. Which is basically a list of polygons - the first is the
|
121
|
+
outside (counter-clock-wise) and the rest, if any, are the holes (clock-wise).
|
122
|
+
Boolean operations consider every expolygon added in this manner to be the same object.
|
123
|
+
|
124
|
+
* `Clipper#add_subject_polyline(polyline)`
|
125
|
+
|
126
|
+
Add an open polygon (ie a polyline) to the engine.
|
127
|
+
NB. polylines can only be present as a subject shape, and will only interact with clip shapes.
|
128
|
+
|
129
|
+
* `Clipper#multiplier`
|
130
|
+
|
131
|
+
* `Clipper#multiplier=`
|
132
|
+
|
133
|
+
Defaults to 2^10 = 1048576. Clipper since version 4.0 uses integer math instead of floating point.
|
134
|
+
To simplify using floating point coordinates, this multiplier is multiplied to each coordinate value
|
135
|
+
before beeing sent to Clipper, and each result coordinate is divided by the multiplier. Use 1 if you
|
136
|
+
want to use integer coordinates.
|
137
|
+
|
138
|
+
* `Clipper#intersection(subject_fill=:even_odd, clip_fill=:even_odd, result_type=:polygons)`
|
139
|
+
|
140
|
+
* `Clipper#union(subject_fill=:even_odd, clip_fill=:even_odd, result_type=:polygons)`
|
141
|
+
|
142
|
+
* `Clipper#difference(subject_fill=:even_odd, clip_fill=:even_odd, result_type=:polygons)`
|
143
|
+
|
144
|
+
* `Clipper#xor(subject_fill=:even_odd, clip_fill=:even_odd, result_type=:polygons)`
|
145
|
+
|
146
|
+
Performs a boolean operation on the polygons that have been added to the
|
147
|
+
clipper object. The result is a list of polygons or expolygons, depending on result_type being :polygons or :expolygons
|
148
|
+
FIXME: :expolygons functionality is not implemented.
|
149
|
+
|
150
|
+
If the result contains open polygons, they will also be returned. To see if a polygon is open, check if the first point is nil.
|
151
|
+
FIXME: Instead of this, directly support Polytrees from Clipper
|
152
|
+
|
153
|
+
* `Clipper#offset_polygons(polygons, delta, join_type, miter_limit=0)`
|
154
|
+
|
155
|
+
Expands the polygons by delta. Use negative delta to compress the polygons. join_type is any of :jtSquare, :jtButt, :jtMiter or :jtRound.
|
156
|
+
Use miter_limit to make sharp joints not extend too long, by cutting off the edge.
|
157
|
+
|
158
|
+
* `Clipper#area(polygon)`
|
159
|
+
|
160
|
+
Returns the area of the supplied polygon. The returned area is negative if the polygon points are oriented clockwise, positive otherwise. Obeys the multiplier and use_full_coordinate_range settings for the clipper object.
|
161
|
+
|
162
|
+
* `Clipper#Orientation(polygon)`
|
163
|
+
|
164
|
+
Orientation returns a boolean value that is based on the polygon's orientation relative to the display's orientation (ie Y-axis positive upward vs Y-axis positive downward).
|
165
|
+
|
166
|
+
* On Y-axis positive upward displays, Orientation will return true if the polygon's orientation is counter-clockwise.
|
167
|
+
* On Y-axis positive downward displays, Orientation will return true if the polygon's orientation is clockwise.
|
168
|
+
|
169
|
+
Minkowski sum
|
170
|
+
-------------
|
171
|
+
|
172
|
+
# Greek capital sigma (sum sign) ...
|
173
|
+
sigma = [[300, 400], [100, 400], [200,300], [100,200], [300,200]]
|
174
|
+
|
175
|
+
# diagonal brush pattern ...
|
176
|
+
brush = [[4, -6], [6, -6], [-4, 6], [-6, 6]]
|
177
|
+
|
178
|
+
solution = Clipper::Clipper.new.minkowski_sum(brush, [sigma], false)
|
179
|
+
|
180
|
+
# ...
|
181
|
+
|
182
|
+
![Minkowski sum of sigma and brush](minkowski_sum.svg)
|
183
|
+
|
184
|
+
PointInPolygon
|
185
|
+
--------------
|
186
|
+
|
187
|
+
# drop all points inside of polygon
|
188
|
+
points.select! { |e| c.point_in_polygon(*e, poly) == 0 }
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
# require 'rake/extensiontask'
|
5
|
+
|
6
|
+
# Rake::ExtensionTask.new('clipper')
|
7
|
+
|
8
|
+
require 'rake/testtask'
|
9
|
+
|
10
|
+
Rake::TestTask.new do |t|
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = "test/test_*.rb"
|
13
|
+
t.verbose = false
|
14
|
+
t.options = "--max-duration=0.1 --junit --verbose"
|
15
|
+
end
|