find_beads 0.9.3-java → 0.9.4-java

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.
@@ -26,7 +26,7 @@
26
26
 
27
27
  module FindBeads
28
28
 
29
- VERSION = '0.9.3'
29
+ VERSION = '0.9.4'
30
30
 
31
31
  end
32
32
 
data/lib/find_beads.rb CHANGED
@@ -32,6 +32,8 @@ require 'rimageanalysistools/graythresh'
32
32
 
33
33
  require 'trollop'
34
34
 
35
+ require 'matrix'
36
+
35
37
  java_import Java::edu.stanford.cfuller.imageanalysistools.image.ImageFactory
36
38
 
37
39
  ##
@@ -89,6 +91,35 @@ module FindBeads
89
91
 
90
92
  end
91
93
 
94
+
95
+ ##
96
+ # Projects a point in space onto a specified line.
97
+ #
98
+ # @param [Array] origin the point in space the will serve as the origin
99
+ # for the purposes of the projection (this should be on the line)
100
+ # @param [Array] point_to_project the point in space that will be projected
101
+ # this should be in the same coordinate system in which the origin is
102
+ # specified, not relative to the origin
103
+ # @param [Array] point_on_line another point on the line specified in the
104
+ # same coordinate system in which the origin is specified, not relative to
105
+ # the origin
106
+ #
107
+ # @return [Array] the projected point (in the same coordinate system as
108
+ # the other points were specified)
109
+ #
110
+ def self.project_point_onto_vector(origin, point_to_project, point_on_line)
111
+
112
+ unit_vec = (Vector[*point_on_line] - Vector[*origin]).normalize
113
+
114
+ proj_vec = Vector[*point_to_project] - Vector[*origin]
115
+
116
+ projected = unit_vec * (proj_vec.inner_product(unit_vec)) + Vector[*origin]
117
+
118
+ projected.to_a
119
+
120
+ end
121
+
122
+
92
123
  ##
93
124
  # Checks if a given coordinate would be approximately on the boundary between two regions of a
94
125
  # Voronoi diagram of constructed from a set of points. The approximation is calculated such that no
@@ -134,9 +165,15 @@ module FindBeads
134
165
 
135
166
  end
136
167
 
168
+ proj_point = project_point_onto_vector(points[closest_index], [x,y], points[next_index])
169
+
170
+ next_dist_proj = Math.hypot(points[next_index][0]-proj_point[0], points[next_index][1]-proj_point[1])
171
+ closest_dist_proj = Math.hypot(points[closest_index][0]-proj_point[0], points[closest_index][1]-proj_point[1])
172
+
173
+
137
174
  cutoff = 1.01*Math.sqrt(2)
138
175
 
139
- if next_dist - closest_dist < cutoff then
176
+ if next_dist_proj - closest_dist_proj < cutoff then
140
177
 
141
178
  true
142
179
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: find_beads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  prerelease:
6
6
  platform: java
7
7
  authors: