geo 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/common.c +0 -3
- data/ext/geo.c +1 -6
- data/ext/geo_set.c +0 -4
- data/ext/intersection.c +0 -4
- data/ext/line.c +69 -9
- data/ext/line.h +3 -0
- data/ext/line_set.c +3 -5
- data/ext/point.c +1 -4
- data/ext/point_set.c +3 -4
- data/ext/triangle.c +1 -4
- data/ext/triangle_set.c +3 -4
- metadata +37 -44
data/ext/common.c
CHANGED
data/ext/geo.c
CHANGED
@@ -33,7 +33,6 @@ extern "C" {
|
|
33
33
|
rb_define_method(rb_cFloat, "intlike?", rb_float_intlike, 0);
|
34
34
|
|
35
35
|
VALUE rb_geo = rb_define_module("Geo");
|
36
|
-
rb_define_const(rb_geo, "VERSION", rb_str_new2("0.1.6"));
|
37
36
|
|
38
37
|
rb_triangle_set = rb_define_class_under(rb_geo,
|
39
38
|
"TriangleSet",
|
@@ -155,6 +154,7 @@ extern "C" {
|
|
155
154
|
rb_define_method(rb_line, "contains?", rb_line_contains, 1);
|
156
155
|
rb_define_method(rb_line, "parallel", rb_line_parallel, 1);
|
157
156
|
rb_define_method(rb_line, "<=>", rb_line_cmp, 1);
|
157
|
+
rb_define_method(rb_line, "mirror", rb_line_mirror, 1);
|
158
158
|
|
159
159
|
rb_define_alloc_func(rb_point, rb_point_alloc);
|
160
160
|
rb_define_method(rb_point, "initialize", rb_point_initialize, 2);
|
@@ -180,8 +180,3 @@ extern "C" {
|
|
180
180
|
#ifdef __cplusplus
|
181
181
|
}
|
182
182
|
#endif
|
183
|
-
|
184
|
-
void
|
185
|
-
init_geo_o() {
|
186
|
-
}
|
187
|
-
|
data/ext/geo_set.c
CHANGED
data/ext/intersection.c
CHANGED
data/ext/line.c
CHANGED
@@ -95,7 +95,7 @@ rb_line_initialize(int argc, VALUE *argv, VALUE self) {
|
|
95
95
|
RB_POINT(p1, rb_point);
|
96
96
|
RB_POINT(p2, rb_point);
|
97
97
|
} else {
|
98
|
-
rb_raise(rb_eTypeError, "Arguments to %s#new have to be 2
|
98
|
+
rb_raise(rb_eTypeError, "Arguments to %s#new have to be 2 Geo::Points or 4 numbers.", rb_obj_classname(self));
|
99
99
|
}
|
100
100
|
LINE(self, l);
|
101
101
|
l->p1 = p1;
|
@@ -193,7 +193,7 @@ rb_line_within(VALUE self, VALUE arg) {
|
|
193
193
|
return Qfalse;
|
194
194
|
}
|
195
195
|
} else {
|
196
|
-
rb_raise(rb_eTypeError, "Argument to %s#within? has to be either
|
196
|
+
rb_raise(rb_eTypeError, "Argument to %s#within? has to be either Geo::Line or Geo::Point.", rb_obj_classname(self));
|
197
197
|
}
|
198
198
|
}
|
199
199
|
|
@@ -225,7 +225,7 @@ rb_line_outside(VALUE self, VALUE arg) {
|
|
225
225
|
return Qfalse;
|
226
226
|
}
|
227
227
|
} else {
|
228
|
-
rb_raise(rb_eTypeError, "Argument to %s#outside? has to be either
|
228
|
+
rb_raise(rb_eTypeError, "Argument to %s#outside? has to be either Geo::Line or Geo::Point.", rb_obj_classname(self));
|
229
229
|
}
|
230
230
|
}
|
231
231
|
|
@@ -386,8 +386,10 @@ rb_line_cmp(VALUE self, VALUE o) {
|
|
386
386
|
VALUE
|
387
387
|
rb_line_reverse(VALUE self) {
|
388
388
|
Line *me;
|
389
|
+
Line *rval;
|
389
390
|
LINE(self, me);
|
390
|
-
|
391
|
+
rval = new_line_with_points(me->p2, me->p1);
|
392
|
+
return RB_LINE(rval, CLASS(self));
|
391
393
|
}
|
392
394
|
|
393
395
|
VALUE
|
@@ -417,8 +419,8 @@ rb_line_angle(VALUE self) {
|
|
417
419
|
void
|
418
420
|
line_set_abs(Line *me, double new_abs) {
|
419
421
|
double ratio = new_abs / DISTANCE(me->p1, me->p2);
|
420
|
-
me->p2->x = me->p2->x * ratio;
|
421
|
-
me->p2->y = me->p2->y * ratio;
|
422
|
+
me->p2->x = me->p1->x + ((me->p2->x - me->p1->x) * ratio);
|
423
|
+
me->p2->y = me->p1->y + ((me->p2->y - me->p1->y) * ratio);
|
422
424
|
}
|
423
425
|
|
424
426
|
VALUE
|
@@ -442,6 +444,67 @@ rb_line_clone(VALUE self) {
|
|
442
444
|
return RB_LINE(rval, CLASS(self));
|
443
445
|
}
|
444
446
|
|
447
|
+
static Point*
|
448
|
+
line_mirror_point(Line *l, Point *p) {
|
449
|
+
Point *rval;
|
450
|
+
if (DBL_EQL(l->p1->x, l->p2->x)) {
|
451
|
+
rval = new_point(-p->x + (2 * l->p1->x),
|
452
|
+
p->y);
|
453
|
+
} else {
|
454
|
+
gdouble line_k1 = (l->p2->y - l->p1->y) / (l->p2->x - l->p1->x);
|
455
|
+
gdouble line_k2 = l->p1->y - (line_k1 * l->p1->x);
|
456
|
+
|
457
|
+
gdouble normal_x_coord = line_k1;
|
458
|
+
gdouble normal_y_coord = -1.0;
|
459
|
+
gdouble normal_abs = sqrt((normal_x_coord * normal_x_coord) + (normal_y_coord * normal_y_coord));
|
460
|
+
|
461
|
+
// here we translate the point by subtracting line_k2 from p->y to force the projection to be against the line as it crosses origo
|
462
|
+
gdouble projection_factor = ((p->x * normal_x_coord + (p->y - line_k2) * normal_y_coord) /
|
463
|
+
(normal_abs * normal_abs));
|
464
|
+
gdouble projection_x_coord = normal_x_coord * projection_factor;
|
465
|
+
gdouble projection_y_coord = normal_y_coord * projection_factor;
|
466
|
+
|
467
|
+
rval = new_point(p->x - (2 * projection_x_coord),
|
468
|
+
p->y - (2 * projection_y_coord));
|
469
|
+
}
|
470
|
+
return rval;
|
471
|
+
}
|
472
|
+
|
473
|
+
static VALUE
|
474
|
+
rb_line_mirror_point(Line *me, Point *p) {
|
475
|
+
Point *rval = line_mirror_point(me, p);
|
476
|
+
return RB_POINT(rval, CLASS(p->rbPoint));
|
477
|
+
}
|
478
|
+
|
479
|
+
static VALUE
|
480
|
+
rb_line_mirror_line(Line *me, Line *o) {
|
481
|
+
Point *p1 = line_mirror_point(me, o->p1);
|
482
|
+
Point *p2 = line_mirror_point(me, o->p2);
|
483
|
+
Line *rval;
|
484
|
+
RB_POINT(p1, CLASS(o->p1->rbPoint));
|
485
|
+
RB_POINT(p2, CLASS(o->p2->rbPoint));
|
486
|
+
rval = new_line_with_points(p1, p2);
|
487
|
+
return RB_LINE(rval, CLASS(o->rbLine));
|
488
|
+
}
|
489
|
+
|
490
|
+
VALUE
|
491
|
+
rb_line_mirror(VALUE self, VALUE other) {
|
492
|
+
Line *me;
|
493
|
+
if (LINE_P(other)) {
|
494
|
+
Line *o;
|
495
|
+
LINE(self, me);
|
496
|
+
LINE(other, o);
|
497
|
+
return rb_line_mirror_line(me, o);
|
498
|
+
} else if (POINT_P(other)) {
|
499
|
+
Point *o;
|
500
|
+
LINE(self, me);
|
501
|
+
POINT(other, o);
|
502
|
+
return rb_line_mirror_point(me, o);
|
503
|
+
} else {
|
504
|
+
rb_raise(rb_eTypeError, "Argument to %s#mirror have to be either Geo::Line or Geo::Point.", rb_obj_classname(self));
|
505
|
+
}
|
506
|
+
}
|
507
|
+
|
445
508
|
VALUE
|
446
509
|
rb_line_side(VALUE self, VALUE p) {
|
447
510
|
Line *me;
|
@@ -598,6 +661,3 @@ line_hash(gconstpointer l) {
|
|
598
661
|
return (guint) (line->p1->x + line->p1->y + line->p2->x + line->p2->y);
|
599
662
|
}
|
600
663
|
|
601
|
-
void
|
602
|
-
init_line_o() {
|
603
|
-
}
|
data/ext/line.h
CHANGED
data/ext/line_set.c
CHANGED
@@ -374,8 +374,10 @@ rb_line_set_closest_intersection(VALUE self, VALUE l) {
|
|
374
374
|
VALUE
|
375
375
|
rb_line_set_clone(VALUE self) {
|
376
376
|
GeoSet *me;
|
377
|
+
GeoSet *rval;
|
377
378
|
GEO_SET(self, me);
|
378
|
-
|
379
|
+
rval = geo_set_clone(me);
|
380
|
+
return RB_LINE_SET(rval, CLASS(self));
|
379
381
|
}
|
380
382
|
|
381
383
|
VALUE
|
@@ -522,7 +524,3 @@ rb_line_set_reindex(VALUE self) {
|
|
522
524
|
return GBOOL2RB(line_set_reindex(me));
|
523
525
|
}
|
524
526
|
|
525
|
-
void
|
526
|
-
init_line_set_o() {
|
527
|
-
}
|
528
|
-
|
data/ext/point.c
CHANGED
@@ -233,7 +233,7 @@ rb_point_to(int argc, VALUE *argv, VALUE self) {
|
|
233
233
|
rval = new_line_with_points(me, other_end);
|
234
234
|
return RB_LINE(rval, rb_line);
|
235
235
|
} else {
|
236
|
-
rb_raise(rb_eTypeError, "Arguments to %s#to has to be either a
|
236
|
+
rb_raise(rb_eTypeError, "Arguments to %s#to has to be either a Geo::Point or 2 numbers.", rb_obj_classname(self));
|
237
237
|
}
|
238
238
|
}
|
239
239
|
|
@@ -301,6 +301,3 @@ point_hash(gconstpointer p) {
|
|
301
301
|
return (guint) (point->x + point->y);
|
302
302
|
}
|
303
303
|
|
304
|
-
void
|
305
|
-
init_point_o() {
|
306
|
-
}
|
data/ext/point_set.c
CHANGED
@@ -86,8 +86,10 @@ rb_point_set_each(VALUE self) {
|
|
86
86
|
VALUE
|
87
87
|
rb_point_set_clone(VALUE self) {
|
88
88
|
GeoSet *me;
|
89
|
+
GeoSet *rval;
|
89
90
|
GEO_SET(self, me);
|
90
|
-
|
91
|
+
rval = geo_set_clone(me);
|
92
|
+
return RB_POINT_SET(rval, CLASS(self));
|
91
93
|
}
|
92
94
|
|
93
95
|
gpointer
|
@@ -109,6 +111,3 @@ geo_set_each_structure_having_common_segment_id_with_point_until(GeoSet *set,
|
|
109
111
|
return rval;
|
110
112
|
}
|
111
113
|
|
112
|
-
void
|
113
|
-
init_point_set_o() {
|
114
|
-
}
|
data/ext/triangle.c
CHANGED
@@ -82,7 +82,7 @@ rb_triangle_initialize(int argc, VALUE *argv, VALUE self) {
|
|
82
82
|
RB_POINT(p2, rb_point);
|
83
83
|
RB_POINT(p3, rb_point);
|
84
84
|
} else {
|
85
|
-
rb_raise(rb_eTypeError, "Arguments to %s#new have to be 3
|
85
|
+
rb_raise(rb_eTypeError, "Arguments to %s#new have to be 3 Geo::Points or 6 numbers.", rb_obj_classname(self));
|
86
86
|
}
|
87
87
|
TRIANGLE(self, t);
|
88
88
|
t->p1 = p1;
|
@@ -446,6 +446,3 @@ rb_triangle_from_gpointer(gpointer l) {
|
|
446
446
|
return ( (Triangle *) l)->rbTriangle;
|
447
447
|
}
|
448
448
|
|
449
|
-
void
|
450
|
-
init_triangle_o() {
|
451
|
-
}
|
data/ext/triangle_set.c
CHANGED
@@ -211,8 +211,10 @@ rb_triangle_set_contains(VALUE self, VALUE p) {
|
|
211
211
|
VALUE
|
212
212
|
rb_triangle_set_clone(VALUE self) {
|
213
213
|
GeoSet *me;
|
214
|
+
GeoSet *rval;
|
214
215
|
GEO_SET(self, me);
|
215
|
-
|
216
|
+
rval = geo_set_clone(me);
|
217
|
+
return RB_TRIANGLE_SET(rval, CLASS(self));
|
216
218
|
}
|
217
219
|
|
218
220
|
VALUE
|
@@ -436,6 +438,3 @@ rb_triangle_set_containers(VALUE self, VALUE p) {
|
|
436
438
|
return rval;
|
437
439
|
}
|
438
440
|
|
439
|
-
void
|
440
|
-
init_triangle_set_o() {
|
441
|
-
}
|
metadata
CHANGED
@@ -1,38 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
2
4
|
name: geo
|
3
5
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
6
|
+
version: 0.1.7
|
7
|
+
date: 2008-08-19 00:00:00 +02:00
|
8
|
+
summary: A 2D geometry engine.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: geo at troja dot ath dot cx
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
5
25
|
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
6
29
|
authors:
|
7
30
|
- Martin Kihlgren
|
8
|
-
autorequire:
|
9
|
-
bindir: bin
|
10
|
-
cert_chain: []
|
11
|
-
|
12
|
-
date: 2008-01-19 00:00:00 +01:00
|
13
|
-
default_executable:
|
14
|
-
dependencies: []
|
15
|
-
|
16
|
-
description:
|
17
|
-
email: geo at troja dot ath dot cx
|
18
|
-
executables: []
|
19
|
-
|
20
|
-
extensions:
|
21
|
-
- ext/extconf.rb
|
22
|
-
extra_rdoc_files:
|
23
|
-
- README
|
24
31
|
files:
|
25
32
|
- ext/common.c
|
26
33
|
- ext/common.h
|
27
34
|
- ext/extconf.rb
|
28
|
-
- ext/geo.c
|
29
|
-
- ext/geo_set.c
|
30
|
-
- ext/geo_set.h
|
31
35
|
- ext/intersection.c
|
32
36
|
- ext/intersection.h
|
33
37
|
- ext/line.c
|
34
38
|
- ext/line.h
|
35
|
-
- ext/line_set.c
|
36
39
|
- ext/line_set.h
|
37
40
|
- ext/point.c
|
38
41
|
- ext/point.h
|
@@ -42,35 +45,25 @@ files:
|
|
42
45
|
- ext/triangle.h
|
43
46
|
- ext/triangle_set.c
|
44
47
|
- ext/triangle_set.h
|
48
|
+
- ext/geo_set.c
|
49
|
+
- ext/geo_set.h
|
50
|
+
- ext/geo.c
|
51
|
+
- ext/line_set.c
|
45
52
|
- ext/types.h
|
46
53
|
- examples/intersects.rb
|
47
54
|
- README
|
48
|
-
|
49
|
-
|
50
|
-
post_install_message:
|
55
|
+
test_files: []
|
56
|
+
|
51
57
|
rdoc_options:
|
52
58
|
- --line-numbers
|
53
59
|
- --inline-source
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
version: "0"
|
61
|
-
version:
|
62
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: "0"
|
67
|
-
version:
|
60
|
+
extra_rdoc_files:
|
61
|
+
- README
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions:
|
65
|
+
- ext/extconf.rb
|
68
66
|
requirements: []
|
69
67
|
|
70
|
-
|
71
|
-
rubygems_version: 1.0.1
|
72
|
-
signing_key:
|
73
|
-
specification_version: 2
|
74
|
-
summary: A 2D geometry engine.
|
75
|
-
test_files: []
|
68
|
+
dependencies: []
|
76
69
|
|