Giter Site home page Giter Site logo

cubing / alg.js Goto Github PK

View Code? Open in Web Editor NEW
22.0 22.0 3.0 876 KB

The functionality of `alg.js` is now part of `cubing.js`. Please see: https://js.cubing.net/cubing/alg/

License: GNU General Public License v3.0

Makefile 1.09% JavaScript 3.06% TypeScript 83.59% Yacc 12.08% HTML 0.18%
cubing library

alg.js's People

Contributors

lgarron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

alg.js's Issues

Define `toString` directly on Algorithm subclasses?

Pros:

  • Nice, concise formatting by default! (node actually truncates nested values)
  • Can still convert to JSON, so inspectability is not lost.

Cons:

  • Javascript does magic type conversion, and this could cause unexpected issues. For all I know 1 + [alg representing 2R] could turn into 3.
  • Viewing the printed alg instead of the structure might hide unexpected discrepancies.

A nested sequence containing a single unit is redundant

The following prints false:

var original = new Alg.Group(
  new Alg.Sequence([
    new Alg.BlockMove("R", 1)
  ]),
  1
)
var parsed = parse(algToString(original));
console.log(structureEquals(original, parsed));

Ideally, I'd like there to be only a single representation of this alg.
One possibility is to have a nested kind of sequence that must have at least two units in it. The parser actually uses this requirement to avoid unnecessary nesting (which is why parsed is different):

: REPEATED_UNIT OPTIONAL_WHITESPACE REPEATED_UNIT

Ideas:

  1. Create a different kind of sequence for a nested alg that requires at least two members.
  • Pro: The top-level alg class could also handle the empty alg (#5).
  • Con: Nesting certain (or all) top-level algs inside another alg would not be possible without changing the top-level representation into an equivalent nested representation.
  1. Define every Algorithm with nested algs to have its own lists, e.g. a commutator has {A: Unit[], B: Unit[]}. This requires making sure to call the Sequence processing code for each of the components in every relevant Algorithm in every traversal, possibly leading to subtle bugs.
  2. Don't allow anything except a Sequence to contain a Unit, and require a Sequence layer.
  • This results in larger data structures, and an extra level of access in some cases. However, code might be more consistent, because looking inside a nested alg always requires going through a Sequence the same way.

See https://gist.github.com/lgarron/f33d88a571f4bc9536801a8a7b035a91 for more thoughts on this.

Can't keep class names using `uglifyjs-webpack-plugin` with "mode": "production"

As soon as I set module.exports.mode = "production", class names are mangled.

Some references:
https://webpack.js.org/plugins/uglifyjs-webpack-plugin/
https://github.com/webpack-contrib/uglifyjs-webpack-plugin

Absolutely nothing works to keep the class names, including this overkill config:

plugins: [
  new UglifyJSPlugin({
    sourceMap: true,
    uglifyOptions: {
      keep_classnames: true,
      "mangle": {
        keep_classnames: true
      },
      "compress": {
        keep_classnames: true
      }
    }
  })
],

Or this one:

optimization: {
  minimizer: [
    new UglifyJSPlugin({
      sourceMap: true,
      uglifyOptions: {
        keep_classnames: true,
        "mangle": {
          keep_classnames: true
        },
        "compress": {
          keep_classnames: true
        }
      }
    })
  ]
},

I know that the config is being parsed properly, because I get errors if I place keep_classnames directly in the UglifyJSPlugin config object or change keep_classnames into a typo anywhere.

Accept more characters as "PRIME" (apostrophes, accents, etc)

People from different cultures use different kinds of apostrophe or accents to denote algorithms and solve reconstructions.

I would suggest replacing the line 22 of alg_jison.jison to accept at least these 4 most common ones:

['’`´]             return "PRIME"

Empty alg

The following throws A sequence cannot be empty.:

var s = alg.parse("L L'")
alg.coalesceBaseMoves(s)

I'm currently leaning towards a special, non-nestable EmptyAlgorithm extends Algorithm class to represent the empty alg, if anything.

Restore chaining?

e.g.

parse("[F: [R, U]]').invert().expand().structureEquals(parse("F U R U' R' F'"))

Also see #7 (a special case for toString() and #9 (providing convenience for when you just want to manipulate strings.

This is also only easy to provide for built-ins, although Javascript technically supports modifying class prototypes downstream from the original definition.

Allow manipulating strings directly?

This is less performant, but super convenient:

> expand("(R U)2")
"R U R U"

Can easily be done by separating the Traversal[Down]Up.traverse() entry point from a recursive entry point, and translating the input from/to a string if it was given as a string.

The main problem I see is that the performance issue might be masked, and users might perform a lot of conversions back and forth:

structureEquals(invert(expand("(R U)2")), expand(invert("(R U)2")))

Automatically convert string locations to indices.

We're not dealing with "source code", so I imagine direct indices are more useful.

Hopefully, this won't take extra processing. If possible, we should:

  • Modify/set a parameter in jison to output string indices.
  • If this isn't possible, defer calculation or do something else clever.

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.