geo 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,6 +48,3 @@ gpointer_compare_as_uint(gconstpointer p1, gconstpointer p2) {
48
48
  return GPOINTER_TO_UINT(p1) - GPOINTER_TO_UINT(p2);
49
49
  }
50
50
 
51
- void
52
- init_common_o() {
53
- }
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
-
@@ -530,7 +530,3 @@ rb_geo_set_height(VALUE self) {
530
530
  return rb_float_new(GEO_SET_HEIGHT(set));
531
531
  }
532
532
 
533
- void
534
- init_geo_set_o() {
535
- }
536
-
@@ -73,7 +73,3 @@ rb_intersection(Intersection *intersection, Point *from) {
73
73
  }
74
74
  }
75
75
 
76
- void
77
- init_intersection_o() {
78
- }
79
-
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 Grueserve::Map::Points or 4 numbers.", rb_obj_classname(self));
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 Grueserve::Map::Line or Grueserve::Map::Point.", rb_obj_classname(self));
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 Grueserve::Map::Line or Grueserve::Map::Point.", rb_obj_classname(self));
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
- return RB_LINE(new_line_with_points(me->p2, me->p1), rb_line);
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
@@ -199,4 +199,7 @@ line_equals(gconstpointer a, gconstpointer b);
199
199
  void
200
200
  line_free(Line *l);
201
201
 
202
+ VALUE
203
+ rb_line_mirror(VALUE self, VALUE other);
204
+
202
205
  #endif
@@ -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
- return RB_LINE_SET(geo_set_clone(me), CLASS(self));
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
-
@@ -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 Grueserve::Map::Point or 2 numbers.", rb_obj_classname(self));
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
- }
@@ -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
- return RB_POINT_SET(geo_set_clone(me), CLASS(self));
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
- }
@@ -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 Grueserve::Map::Points or 6 numbers.", rb_obj_classname(self));
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
- }
@@ -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
- return RB_TRIANGLE_SET(geo_set_clone(me), CLASS(self));
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
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
- has_rdoc: true
49
- homepage:
50
- post_install_message:
55
+ test_files: []
56
+
51
57
  rdoc_options:
52
58
  - --line-numbers
53
59
  - --inline-source
54
- require_paths:
55
- - lib
56
- required_ruby_version: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
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
- rubyforge_project:
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