Git Product home page Git Product logo

Comments (4)

dpmcmlxxvi avatar dpmcmlxxvi commented on May 24, 2024 1

I'll look into integrating a bench performance library into the test suite. Generally, using Date.now is discouraged since it can contain timing side-effects that have nothing to do with the code you are measuring. The performance timing API performance.now is preferable.

from de9im.

dpmcmlxxvi avatar dpmcmlxxvi commented on May 24, 2024 1

Closed with 52cf6ec.

from de9im.

tordans avatar tordans commented on May 24, 2024

That would be great.

I am reading the README and I am wondering, which method to pick when more than one would likely solve my problem. A benchmark could help with this decision.


Update:

I was curious about this and googled how to do this in a simple way. Here are my results. Would love to hear if this approach is usable (see "Full code").

Function call Time
de9im.contains(area, lineFullyWithinArea)) 97 ms
de9im.contains(area, lineInAndOutOfArea)) 106 ms
de9im.coveredby(lineFullyWithinArea, area)) 42 ms
de9im.coveredby(lineInAndOutOfArea, area)) 71 ms
de9im.crosses(area, lineFullyWithinArea)) 51 ms
de9im.crosses(area, lineInAndOutOfArea)) 80 ms
de9im.intersects(area, lineFullyWithinArea)) 154 ms
de9im.intersects(area, lineInAndOutOfArea)) 165 ms
de9im.within(lineFullyWithinArea, area)) 45 ms
de9im.within(lineInAndOutOfArea, area)) 71 ms
Full code …
const area = {
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      properties: {},
      geometry: {
        type: "Polygon",
        coordinates: [
          [
            [13.587512969970701, 52.3013410761489],
            [13.619956970214844, 52.3013410761489],
            [13.619956970214844, 52.31141727938367],
            [13.587512969970701, 52.31141727938367],
            [13.587512969970701, 52.3013410761489],
          ],
        ],
      },
    },
  ],
}

const lineFullyWithinArea = {
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      properties: {},
      geometry: {
        type: "LineString",
        coordinates: [
          [13.594036102294922, 52.30595962063293],
          [13.613433837890625, 52.30784888634275],
        ],
      },
    },
  ],
}

const lineInAndOutOfArea = {
  type: "Feature",
  properties: {},
  geometry: {
    type: "LineString",
    coordinates: [
      [13.5955810546875, 52.30889844356715],
      [13.5955810546875, 52.313935971877584],
    ],
  },
}

import de9im from "de9im"

const test = (consoleLine, callFunction) => {
  const start = Date.now()
  let runs = 10000

  while (runs) {
    callFunction()
    runs--
  }

  console.log("Finished `" + consoleLine + "` " + (Date.now() - start) + " ms.")
}

test("de9im.contains(area, lineFullyWithinArea))", () =>
  de9im.contains(area, lineFullyWithinArea))
test("de9im.contains(area, lineInAndOutOfArea))", () =>
  de9im.contains(area, lineInAndOutOfArea))
test("de9im.coveredby(lineFullyWithinArea, area))", () =>
  de9im.coveredby(lineFullyWithinArea, area))
test("de9im.coveredby(lineInAndOutOfArea, area))", () =>
  de9im.coveredby(lineInAndOutOfArea, area))
test("de9im.crosses(area, lineFullyWithinArea))", () =>
  de9im.crosses(area, lineFullyWithinArea))
test("de9im.crosses(area, lineInAndOutOfArea))", () =>
  de9im.crosses(area, lineInAndOutOfArea))
test("de9im.intersects(area, lineFullyWithinArea))", () =>
  de9im.intersects(area, lineFullyWithinArea))
test("de9im.intersects(area, lineInAndOutOfArea))", () =>
  de9im.intersects(area, lineInAndOutOfArea))
test("de9im.within(lineFullyWithinArea, area))", () =>
  de9im.within(lineFullyWithinArea, area))
test("de9im.within(lineInAndOutOfArea, area))", () =>
  de9im.within(lineInAndOutOfArea, area))

What is interesting is, that in my usecase #44 it looks like it would be faster to first check everything with coveredby (fastest) and only check all non assigned values with intersects (slowest, but the right one for my usecase).

from de9im.

dpmcmlxxvi avatar dpmcmlxxvi commented on May 24, 2024

@tordans FYI. Based on the benchmark results it seems like you're better off just running intersects directly if that is the case you are interested in for the line/polygon case. The test geometries used are fairly simple. So, if you are interested in more complex geometries, you can submit an issue for it and I can consider adding it to the bench tests.

from de9im.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.