Coder Social home page Coder Social logo

Make a line iterator about hex_math HOT 3 CLOSED

leftiness avatar leftiness commented on June 12, 2024
Make a line iterator

from hex_math.

Comments (3)

leftiness avatar leftiness commented on June 12, 2024

wip

  • Code compiles. Existing tests pass.
  • Need to write new tests for line::Iterator::next(). He also needs to be refactored into more functions?
  • Merge #84 into this issue?
  • Code is rough around the edges in general. Needs a second pass. It's too late to keep working tonight, though.

What I did:

  • Remove Predicate trait. It turns out that you can use the existing iterator API without providing boxed closures.
  • Change line::generic() into line::Iterator. He still infinitely iterates unless you filter him, but now I'm not the one handling enumeration, predicate application, etc. Stdlib does that.
  • Make denumerate() function to reverse the effect of Iterator::enumerate()
  • Alter Walls and Range predicates to be used with Iterator::scan().
  • Range now returns None if index is greater than range. Previously, it was greater-or-equal. This boolean condition changed because the finer points of the logic changed when I converted from a loop to an iterator.

from hex_math.

leftiness avatar leftiness commented on June 12, 2024

Now that I've got this iterator stuff implemented, I should look at making other iterators.

Maybe Range/flood could use the same iterator with different predicates. Not sure.

Rotate and travel could maybe be iterators. They'd probably be a lot easier to write, but it also doesn't make as much sense. I mean.. maybe. Maybe you could provide arbitrary predicates to travel. Travel until you run out of move points maybe? Idk. Don't implement those yet. If I find a good use case, then do it. Otherwise it's just added complexity. Travel is already a very simple function, and it doesn't seem like he needs predicates.

Line of sight? I guess he could be an iterator. You could take from the iterator until you run out of vision distance or something? But... wouldn't you /always/ want to see as far as you can? There's no circumstance in which you would maybe want to break that loop /before/ you've seen everything that you can... Is there?

from hex_math.

leftiness avatar leftiness commented on June 12, 2024

Merged

from hex_math.

Related Issues (20)

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.