]> git.lizzy.rs Git - minetest.git/blob - src/collision.cpp
Fix #3955 (player dying on login).
[minetest.git] / src / collision.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "collision.h"
21 #include "mapblock.h"
22 #include "map.h"
23 #include "nodedef.h"
24 #include "gamedef.h"
25 #include "log.h"
26 #include "environment.h"
27 #include "serverobject.h"
28 #include <vector>
29 #include <set>
30 #include "util/timetaker.h"
31 #include "profiler.h"
32
33 // float error is 10 - 9.96875 = 0.03125
34 //#define COLL_ZERO 0.032 // broken unit tests
35 #define COLL_ZERO 0
36
37 // Helper function:
38 // Checks for collision of a moving aabbox with a static aabbox
39 // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
40 // The time after which the collision occurs is stored in dtime.
41 int axisAlignedCollision(
42                 const aabb3f &staticbox, const aabb3f &movingbox,
43                 const v3f &speed, f32 d, f32 *dtime)
44 {
45         //TimeTaker tt("axisAlignedCollision");
46
47         f32 xsize = (staticbox.MaxEdge.X - staticbox.MinEdge.X) - COLL_ZERO;     // reduce box size for solve collision stuck (flying sand)
48         f32 ysize = (staticbox.MaxEdge.Y - staticbox.MinEdge.Y); // - COLL_ZERO; // Y - no sense for falling, but maybe try later
49         f32 zsize = (staticbox.MaxEdge.Z - staticbox.MinEdge.Z) - COLL_ZERO;
50
51         aabb3f relbox(
52                         movingbox.MinEdge.X - staticbox.MinEdge.X,
53                         movingbox.MinEdge.Y - staticbox.MinEdge.Y,
54                         movingbox.MinEdge.Z - staticbox.MinEdge.Z,
55                         movingbox.MaxEdge.X - staticbox.MinEdge.X,
56                         movingbox.MaxEdge.Y - staticbox.MinEdge.Y,
57                         movingbox.MaxEdge.Z - staticbox.MinEdge.Z
58         );
59
60         if(speed.X > 0) // Check for collision with X- plane
61         {
62                 if (relbox.MaxEdge.X <= d) {
63                         *dtime = -relbox.MaxEdge.X / speed.X;
64                         if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
65                                         (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) &&
66                                         (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
67                                         (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
68                                 return 0;
69                 }
70                 else if(relbox.MinEdge.X > xsize)
71                 {
72                         return -1;
73                 }
74         }
75         else if(speed.X < 0) // Check for collision with X+ plane
76         {
77                 if (relbox.MinEdge.X >= xsize - d) {
78                         *dtime = (xsize - relbox.MinEdge.X) / speed.X;
79                         if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
80                                         (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) &&
81                                         (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
82                                         (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
83                                 return 0;
84                 }
85                 else if(relbox.MaxEdge.X < 0)
86                 {
87                         return -1;
88                 }
89         }
90
91         // NO else if here
92
93         if(speed.Y > 0) // Check for collision with Y- plane
94         {
95                 if (relbox.MaxEdge.Y <= d) {
96                         *dtime = -relbox.MaxEdge.Y / speed.Y;
97                         if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
98                                         (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
99                                         (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
100                                         (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
101                                 return 1;
102                 }
103                 else if(relbox.MinEdge.Y > ysize)
104                 {
105                         return -1;
106                 }
107         }
108         else if(speed.Y < 0) // Check for collision with Y+ plane
109         {
110                 if (relbox.MinEdge.Y >= ysize - d) {
111                         *dtime = (ysize - relbox.MinEdge.Y) / speed.Y;
112                         if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
113                                         (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
114                                         (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
115                                         (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
116                                 return 1;
117                 }
118                 else if(relbox.MaxEdge.Y < 0)
119                 {
120                         return -1;
121                 }
122         }
123
124         // NO else if here
125
126         if(speed.Z > 0) // Check for collision with Z- plane
127         {
128                 if (relbox.MaxEdge.Z <= d) {
129                         *dtime = -relbox.MaxEdge.Z / speed.Z;
130                         if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
131                                         (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
132                                         (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
133                                         (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO))
134                                 return 2;
135                 }
136                 //else if(relbox.MinEdge.Z > zsize)
137                 //{
138                 //      return -1;
139                 //}
140         }
141         else if(speed.Z < 0) // Check for collision with Z+ plane
142         {
143                 if (relbox.MinEdge.Z >= zsize - d) {
144                         *dtime = (zsize - relbox.MinEdge.Z) / speed.Z;
145                         if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
146                                         (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
147                                         (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
148                                         (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO))
149                                 return 2;
150                 }
151                 //else if(relbox.MaxEdge.Z < 0)
152                 //{
153                 //      return -1;
154                 //}
155         }
156
157         return -1;
158 }
159
160 // Helper function:
161 // Checks if moving the movingbox up by the given distance would hit a ceiling.
162 bool wouldCollideWithCeiling(
163                 const std::vector<aabb3f> &staticboxes,
164                 const aabb3f &movingbox,
165                 f32 y_increase, f32 d)
166 {
167         //TimeTaker tt("wouldCollideWithCeiling");
168
169         assert(y_increase >= 0);        // pre-condition
170
171         for(std::vector<aabb3f>::const_iterator
172                         i = staticboxes.begin();
173                         i != staticboxes.end(); ++i)
174         {
175                 const aabb3f& staticbox = *i;
176                 if((movingbox.MaxEdge.Y - d <= staticbox.MinEdge.Y) &&
177                                 (movingbox.MaxEdge.Y + y_increase > staticbox.MinEdge.Y) &&
178                                 (movingbox.MinEdge.X < staticbox.MaxEdge.X) &&
179                                 (movingbox.MaxEdge.X > staticbox.MinEdge.X) &&
180                                 (movingbox.MinEdge.Z < staticbox.MaxEdge.Z) &&
181                                 (movingbox.MaxEdge.Z > staticbox.MinEdge.Z))
182                         return true;
183         }
184
185         return false;
186 }
187
188 static inline void getNeighborConnectingFace(v3s16 p, INodeDefManager *nodedef,
189                 Map *map, MapNode n, int v, int *neighbors)
190 {
191         MapNode n2 = map->getNodeNoEx(p);
192         if (nodedef->nodeboxConnects(n, n2, v))
193                 *neighbors |= v;
194 }
195
196 collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
197                 f32 pos_max_d, const aabb3f &box_0,
198                 f32 stepheight, f32 dtime,
199                 v3f *pos_f, v3f *speed_f,
200                 v3f accel_f, ActiveObject *self,
201                 bool collideWithObjects)
202 {
203         static bool time_notification_done = false;
204         Map *map = &env->getMap();
205         //TimeTaker tt("collisionMoveSimple");
206         ScopeProfiler sp(g_profiler, "collisionMoveSimple avg", SPT_AVG);
207
208         collisionMoveResult result;
209
210         /*
211                 Calculate new velocity
212         */
213         if (dtime > 0.5) {
214                 if (!time_notification_done) {
215                         time_notification_done = true;
216                         infostream << "collisionMoveSimple: maximum step interval exceeded,"
217                                         " lost movement details!"<<std::endl;
218                 }
219                 dtime = 0.5;
220         } else {
221                 time_notification_done = false;
222         }
223         *speed_f += accel_f * dtime;
224
225         // If there is no speed, there are no collisions
226         if (speed_f->getLength() == 0)
227                 return result;
228
229         // Limit speed for avoiding hangs
230         speed_f->Y = rangelim(speed_f->Y, -5000, 5000);
231         speed_f->X = rangelim(speed_f->X, -5000, 5000);
232         speed_f->Z = rangelim(speed_f->Z, -5000, 5000);
233
234         /*
235                 Collect node boxes in movement range
236         */
237         std::vector<aabb3f> cboxes;
238         std::vector<bool> is_unloaded;
239         std::vector<bool> is_step_up;
240         std::vector<bool> is_object;
241         std::vector<int> bouncy_values;
242         std::vector<v3s16> node_positions;
243         {
244         //TimeTaker tt2("collisionMoveSimple collect boxes");
245         ScopeProfiler sp(g_profiler, "collisionMoveSimple collect boxes avg", SPT_AVG);
246
247         v3s16 oldpos_i = floatToInt(*pos_f, BS);
248         v3s16 newpos_i = floatToInt(*pos_f + *speed_f * dtime, BS);
249         s16 min_x = MYMIN(oldpos_i.X, newpos_i.X) + (box_0.MinEdge.X / BS) - 1;
250         s16 min_y = MYMIN(oldpos_i.Y, newpos_i.Y) + (box_0.MinEdge.Y / BS) - 1;
251         s16 min_z = MYMIN(oldpos_i.Z, newpos_i.Z) + (box_0.MinEdge.Z / BS) - 1;
252         s16 max_x = MYMAX(oldpos_i.X, newpos_i.X) + (box_0.MaxEdge.X / BS) + 1;
253         s16 max_y = MYMAX(oldpos_i.Y, newpos_i.Y) + (box_0.MaxEdge.Y / BS) + 1;
254         s16 max_z = MYMAX(oldpos_i.Z, newpos_i.Z) + (box_0.MaxEdge.Z / BS) + 1;
255
256         bool any_position_valid = false;
257
258         for(s16 x = min_x; x <= max_x; x++)
259         for(s16 y = min_y; y <= max_y; y++)
260         for(s16 z = min_z; z <= max_z; z++)
261         {
262                 v3s16 p(x,y,z);
263
264                 bool is_position_valid;
265                 MapNode n = map->getNodeNoEx(p, &is_position_valid);
266
267                 if (is_position_valid) {
268                         // Object collides into walkable nodes
269
270                         any_position_valid = true;
271                         INodeDefManager *nodedef = gamedef->getNodeDefManager();
272                         const ContentFeatures &f = nodedef->get(n);
273                         if(f.walkable == false)
274                                 continue;
275                         int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
276
277                         int neighbors = 0;
278                         if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) {
279                                 v3s16 p2 = p;
280
281                                 p2.Y++;
282                                 getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors);
283
284                                 p2 = p;
285                                 p2.Y--;
286                                 getNeighborConnectingFace(p2, nodedef, map, n, 2, &neighbors);
287
288                                 p2 = p;
289                                 p2.Z--;
290                                 getNeighborConnectingFace(p2, nodedef, map, n, 4, &neighbors);
291
292                                 p2 = p;
293                                 p2.X--;
294                                 getNeighborConnectingFace(p2, nodedef, map, n, 8, &neighbors);
295
296                                 p2 = p;
297                                 p2.Z++;
298                                 getNeighborConnectingFace(p2, nodedef, map, n, 16, &neighbors);
299
300                                 p2 = p;
301                                 p2.X++;
302                                 getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
303                         }
304                         std::vector<aabb3f> nodeboxes;
305                         n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
306                         for(std::vector<aabb3f>::iterator
307                                         i = nodeboxes.begin();
308                                         i != nodeboxes.end(); ++i)
309                         {
310                                 aabb3f box = *i;
311                                 box.MinEdge += v3f(x, y, z)*BS;
312                                 box.MaxEdge += v3f(x, y, z)*BS;
313                                 cboxes.push_back(box);
314                                 is_unloaded.push_back(false);
315                                 is_step_up.push_back(false);
316                                 bouncy_values.push_back(n_bouncy_value);
317                                 node_positions.push_back(p);
318                                 is_object.push_back(false);
319                         }
320                 }
321                 else {
322                         // Collide with unloaded nodes
323                         aabb3f box = getNodeBox(p, BS);
324                         cboxes.push_back(box);
325                         is_unloaded.push_back(true);
326                         is_step_up.push_back(false);
327                         bouncy_values.push_back(0);
328                         node_positions.push_back(p);
329                         is_object.push_back(false);
330                 }
331         }
332
333         // Do not move if world has not loaded yet, since custom node boxes
334         // are not available for collision detection.
335         if (!any_position_valid) {
336                 *speed_f = v3f(0, 0, 0);
337                 return result;
338         }
339
340         } // tt2
341
342         if(collideWithObjects)
343         {
344                 ScopeProfiler sp(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
345                 //TimeTaker tt3("collisionMoveSimple collect object boxes");
346
347                 /* add object boxes to cboxes */
348
349                 std::vector<ActiveObject*> objects;
350 #ifndef SERVER
351                 ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
352                 if (c_env != 0) {
353                         f32 distance = speed_f->getLength();
354                         std::vector<DistanceSortedActiveObject> clientobjects;
355                         c_env->getActiveObjects(*pos_f, distance * 1.5, clientobjects);
356                         for (size_t i=0; i < clientobjects.size(); i++) {
357                                 if ((self == 0) || (self != clientobjects[i].obj)) {
358                                         objects.push_back((ActiveObject*)clientobjects[i].obj);
359                                 }
360                         }
361                 }
362                 else
363 #endif
364                 {
365                         ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
366                         if (s_env != 0) {
367                                 f32 distance = speed_f->getLength();
368                                 std::vector<u16> s_objects;
369                                 s_env->getObjectsInsideRadius(s_objects, *pos_f, distance * 1.5);
370                                 for (std::vector<u16>::iterator iter = s_objects.begin(); iter != s_objects.end(); ++iter) {
371                                         ServerActiveObject *current = s_env->getActiveObject(*iter);
372                                         if ((self == 0) || (self != current)) {
373                                                 objects.push_back((ActiveObject*)current);
374                                         }
375                                 }
376                         }
377                 }
378
379                 for (std::vector<ActiveObject*>::const_iterator iter = objects.begin();
380                                 iter != objects.end(); ++iter) {
381                         ActiveObject *object = *iter;
382
383                         if (object != NULL) {
384                                 aabb3f object_collisionbox;
385                                 if (object->getCollisionBox(&object_collisionbox) &&
386                                                 object->collideWithObjects()) {
387                                         cboxes.push_back(object_collisionbox);
388                                         is_unloaded.push_back(false);
389                                         is_step_up.push_back(false);
390                                         bouncy_values.push_back(0);
391                                         node_positions.push_back(v3s16(0,0,0));
392                                         is_object.push_back(true);
393                                 }
394                         }
395                 }
396         } //tt3
397
398         assert(cboxes.size() == is_unloaded.size());    // post-condition
399         assert(cboxes.size() == is_step_up.size());     // post-condition
400         assert(cboxes.size() == bouncy_values.size());  // post-condition
401         assert(cboxes.size() == node_positions.size()); // post-condition
402         assert(cboxes.size() == is_object.size());      // post-condition
403
404         /*
405                 Collision detection
406         */
407
408         /*
409                 Collision uncertainty radius
410                 Make it a bit larger than the maximum distance of movement
411         */
412         f32 d = pos_max_d * 1.1;
413         // A fairly large value in here makes moving smoother
414         //f32 d = 0.15*BS;
415
416         // This should always apply, otherwise there are glitches
417         assert(d > pos_max_d);  // invariant
418
419         int loopcount = 0;
420
421         while(dtime > BS * 1e-10) {
422                 //TimeTaker tt3("collisionMoveSimple dtime loop");
423                 ScopeProfiler sp(g_profiler, "collisionMoveSimple dtime loop avg", SPT_AVG);
424
425                 // Avoid infinite loop
426                 loopcount++;
427                 if (loopcount >= 100) {
428                         warningstream << "collisionMoveSimple: Loop count exceeded, aborting to avoid infiniite loop" << std::endl;
429                         break;
430                 }
431
432                 aabb3f movingbox = box_0;
433                 movingbox.MinEdge += *pos_f;
434                 movingbox.MaxEdge += *pos_f;
435
436                 int nearest_collided = -1;
437                 f32 nearest_dtime = dtime;
438                 int nearest_boxindex = -1;
439
440                 /*
441                         Go through every nodebox, find nearest collision
442                 */
443                 for (u32 boxindex = 0; boxindex < cboxes.size(); boxindex++) {
444                         // Ignore if already stepped up this nodebox.
445                         if(is_step_up[boxindex])
446                                 continue;
447
448                         // Find nearest collision of the two boxes (raytracing-like)
449                         f32 dtime_tmp;
450                         int collided = axisAlignedCollision(
451                                         cboxes[boxindex], movingbox, *speed_f, d, &dtime_tmp);
452
453                         if (collided == -1 || dtime_tmp >= nearest_dtime)
454                                 continue;
455
456                         nearest_dtime = dtime_tmp;
457                         nearest_collided = collided;
458                         nearest_boxindex = boxindex;
459                 }
460
461                 if (nearest_collided == -1) {
462                         // No collision with any collision box.
463                         *pos_f += *speed_f * dtime;
464                         dtime = 0;  // Set to 0 to avoid "infinite" loop due to small FP numbers
465                 } else {
466                         // Otherwise, a collision occurred.
467
468                         const aabb3f& cbox = cboxes[nearest_boxindex];
469                         // Check for stairs.
470                         bool step_up = (nearest_collided != 1) && // must not be Y direction
471                                         (movingbox.MinEdge.Y < cbox.MaxEdge.Y) &&
472                                         (movingbox.MinEdge.Y + stepheight > cbox.MaxEdge.Y) &&
473                                         (!wouldCollideWithCeiling(cboxes, movingbox,
474                                                         cbox.MaxEdge.Y - movingbox.MinEdge.Y,
475                                                         d));
476
477                         // Get bounce multiplier
478                         bool bouncy = (bouncy_values[nearest_boxindex] >= 1);
479                         float bounce = -(float)bouncy_values[nearest_boxindex] / 100.0;
480
481                         // Move to the point of collision and reduce dtime by nearest_dtime
482                         if (nearest_dtime < 0) {
483                                 // Handle negative nearest_dtime (can be caused by the d allowance)
484                                 if (!step_up) {
485                                         if (nearest_collided == 0)
486                                                 pos_f->X += speed_f->X * nearest_dtime;
487                                         if (nearest_collided == 1)
488                                                 pos_f->Y += speed_f->Y * nearest_dtime;
489                                         if (nearest_collided == 2)
490                                                 pos_f->Z += speed_f->Z * nearest_dtime;
491                                 }
492                         } else {
493                                 *pos_f += *speed_f * nearest_dtime;
494                                 dtime -= nearest_dtime;
495                         }
496
497                         bool is_collision = true;
498                         if (is_unloaded[nearest_boxindex])
499                                 is_collision = false;
500
501                         CollisionInfo info;
502                         if (is_object[nearest_boxindex])
503                                 info.type = COLLISION_OBJECT;
504                         else
505                                 info.type = COLLISION_NODE;
506
507                         info.node_p = node_positions[nearest_boxindex];
508                         info.bouncy = bouncy;
509                         info.old_speed = *speed_f;
510
511                         // Set the speed component that caused the collision to zero
512                         if (step_up) {
513                                 // Special case: Handle stairs
514                                 is_step_up[nearest_boxindex] = true;
515                                 is_collision = false;
516                         } else if(nearest_collided == 0) { // X
517                                 if (fabs(speed_f->X) > BS * 3)
518                                         speed_f->X *= bounce;
519                                 else
520                                         speed_f->X = 0;
521                                 result.collides = true;
522                                 result.collides_xz = true;
523                         }
524                         else if(nearest_collided == 1) { // Y
525                                 if (fabs(speed_f->Y) > BS * 3)
526                                         speed_f->Y *= bounce;
527                                 else
528                                         speed_f->Y = 0;
529                                 result.collides = true;
530                         } else if(nearest_collided == 2) { // Z
531                                 if (fabs(speed_f->Z) > BS * 3)
532                                         speed_f->Z *= bounce;
533                                 else
534                                         speed_f->Z = 0;
535                                 result.collides = true;
536                                 result.collides_xz = true;
537                         }
538
539                         info.new_speed = *speed_f;
540                         if (info.new_speed.getDistanceFrom(info.old_speed) < 0.1 * BS)
541                                 is_collision = false;
542
543                         if (is_collision) {
544                                 result.collisions.push_back(info);
545                         }
546                 }
547         }
548
549         /*
550                 Final touches: Check if standing on ground, step up stairs.
551         */
552         aabb3f box = box_0;
553         box.MinEdge += *pos_f;
554         box.MaxEdge += *pos_f;
555         for (u32 boxindex = 0; boxindex < cboxes.size(); boxindex++) {
556                 const aabb3f& cbox = cboxes[boxindex];
557
558                 /*
559                         See if the object is touching ground.
560
561                         Object touches ground if object's minimum Y is near node's
562                         maximum Y and object's X-Z-area overlaps with the node's
563                         X-Z-area.
564
565                         Use 0.15*BS so that it is easier to get on a node.
566                 */
567                 if (cbox.MaxEdge.X - d > box.MinEdge.X && cbox.MinEdge.X + d < box.MaxEdge.X &&
568                                 cbox.MaxEdge.Z - d > box.MinEdge.Z &&
569                                 cbox.MinEdge.Z + d < box.MaxEdge.Z) {
570                         if (is_step_up[boxindex]) {
571                                 pos_f->Y += (cbox.MaxEdge.Y - box.MinEdge.Y);
572                                 box = box_0;
573                                 box.MinEdge += *pos_f;
574                                 box.MaxEdge += *pos_f;
575                         }
576                         if (fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.15 * BS) {
577                                 result.touching_ground = true;
578
579                                 if (is_object[boxindex])
580                                         result.standing_on_object = true;
581                                 if (is_unloaded[boxindex])
582                                         result.standing_on_unloaded = true;
583                         }
584                 }
585         }
586
587         return result;
588 }