Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineString with 1 point causes ! on null #154

Open
leiflinse-trivector opened this issue Jan 20, 2024 · 0 comments
Open

LineString with 1 point causes ! on null #154

leiflinse-trivector opened this issue Jan 20, 2024 · 0 comments

Comments

@leiflinse-trivector
Copy link
Contributor

Steps to reproduce

Add this to test/components/nearest_point_on_line_test.dart:

  test('nearest_point_on_line -- linestring with one point', () {
    final start = Point(coordinates: Position.of([-122.457175, 37.720033]));
    final line = LineString(coordinates: [
      start.coordinates,
    ]);

    final snapped = nearestPointOnLine(line, start);

    expect(snapped.geometry, start);
    expect(snapped.properties!['dist'], 0);
  });

Then run dart test:

 test\components\nearest_point_on_line_test.dart: nearest_point_on_line -- linestring with one point [E]
  Null check operator used on a null value
  package:turf/src/nearest_point_on_line.dart 151:17      _nearestPointOnLine
  package:turf/src/nearest_point_on_line.dart 206:10      nearestPointOnLine
  test\components\nearest_point_on_line_test.dart 234:21  main.<fn>

Comparing to turf.js

npm install @turf/turf

Create index.js:

const turf = require('@turf/turf');

var line = turf.lineString([[-24, 43]]);
console.log(line);

node index.js:

C:\..\turf\node_modules\@turf\helpers\dist\js\index.js:294
        throw new Error("coordinates must be an array of two or more positions");
        ^

Error: coordinates must be an array of two or more positions
    at Object.lineString (_C:\.._\turf\node_modules\@turf\helpers\dist\js\index.js:294:15)
    at Object.<anonymous> (C:\..\turf\index.js:3:17)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
    at node:internal/main/run_main_module:28:49

Node.js v20.11.0

Expected / discussion

I expect that either LineString reject creating lines with less than 2 coordinates or that methods like nearset_point_on_line throws or return null.

In turf.js this is rejected when the LineString is created and there is a comment next to the line in turf_dart where it fails saying that LineString should have at least two coordinates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant