Giter VIP home page Giter VIP logo

Comments (15)

x13machine avatar x13machine commented on August 22, 2024 1

that's caused by undefined values in the Point object, I think. The code base is absolute shit.

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024

@DozenalFTW The current version of Point.isIdeal() only calls Point.getEuclideanRadius(), which I believe will properly avoid circular calls like that. Do you know how old your version is?

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024

@DozenalFTW Did you call the Point constructor directly, passing it an options hash? It's not clear in the documentation, but this is not recommended. Use the factory methods instead:

Point.givenCoordinates(x, y)
Point.givenEuclideanPolarCoordinates(euclideanRadius, angle)
Point.givenHyperbolicPolarCoordinates(hyperbolicRadius, angle)
Point.givenIdealAngle(angle)

The constructor requires that specific combinations of attributes be present in the options hash, but doens't actually check to make sure that it has an appropriate combination. I was able to reproduce your results with new Point({ angle: 1 }).getEuclideanRadius(), or new Point({ angle: 1, hyprbolicRadius: 1 }).getEuclideanRadius() (note the spelling mistake).

I apologize for the state of the documentation. Making things like this more clear is one of the next steps.

from hyperbolic-canvas.

 avatar commented on August 22, 2024

I also used player.center.distantPoint(speed, ang);, where player.center is a Point.
I also used the variable Point.CENTER.

I don't recall using new Point...

Here's every single time I use Point:

  • var Point = window.Point || window.HyperbolicCanvas.Point;
  • this.center = Point.givenCoordinates(x, y);
  • return Line.givenTwoPoints(A, B).hyperbolicDistance(); (came up in my search for Point)
  • var mousePoint = Point.givenCoordinates(mouseCoords.x, mouseCoords.y)
  • if (player.center.equals(Point.CENTER)) return;
    • var d2c = player.center.distaceFromCenter(); (looked suspicious)
  • player.center = Point.givenHyperbolicPolarCoordinates(d2c, player.center.angle())
  • var pt = Point.givenHyperbolicPolarCoordinates(speed, ang);
  • var pt = player.center.distantPoint(speed, ang); (came up in the search)
    ** This is just too much, after here there's nothing new
  • I also use Point.CENTER a few times

I wonder if some other function is creating the loop. Let me check.

from hyperbolic-canvas.

 avatar commented on August 22, 2024

I was going to write the long post when I found the entire problem.

Point.givenCoordinates = function (x, y) {
    return new Point({ x: x, y: y });
  };

is faulty.

Here's another long post with a bunch of code.

Point.prototype.getEuclideanRadius = function () {
    if (typeof this._euclideanRadius === 'undefined') {
      if (typeof this._x === 'undefined' || this._y === 'undefined') {
        if (this.getHyperbolicRadius() === Infinity) {
          this._euclideanRadius = 1;
        } else {
          this._euclideanRadius = (Math.exp(this.getHyperbolicRadius()) - 1) /
                                  (Math.exp(this.getHyperbolicRadius()) + 1);
        }
      } else {
        this._euclideanRadius = Math.sqrt(
          Math.pow(this.getX(), 2) +
          Math.pow(this.getY(), 2)
        );
      }
      if (Math.abs(this._euclideanRadius - 1) < 1e-6) {
        this._euclideanRadius = 1;
      }
    }
    return this._euclideanRadius;
  };

So it seems to only call this.getHyperbolicRadius() if it's not initialized correctly. OK...

Point.prototype.getHyperbolicRadius = function () {
    if (typeof this._hyperbolicRadius === 'undefined') {
      if (this.isIdeal()) {
        this._hyperbolicRadius = Infinity;
      } else {
        this._hyperbolicRadius = 2 * Math.atanh(this.getEuclideanRadius());
      }
    }
    return this._hyperbolicRadius;
  };

You're calling this.isIdeal:

Point.prototype.isIdeal = function () {
    return this._euclideanRadius === 1 ||
           this._hyperbolicRadius === Infinity ||
           this.getEuclideanRadius() === 1;
  };

There have been some changes... Point.CENTER is now Point.ORIGIN and Point.prototype.distantPoint is now .hyperbolicDistantPoint.

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024

I've been renaming things a lot over the past month. It's bad practice for an API, but that's why there's no release yet. Point.CENTER was renamed to Point.ORIGIN on the 1st of April, but Point.isIdeal was not added until the 18th of April. How is it that both exist in the same version?

When you call Point.givenCoordinates(mouseCoords.x, mouseCoords.y), are the mouseCoords corrected for the width of the canvas? I don't think this could cause the problem you're having, but you should use Canvas.at to convert coordinates on the page to a Point.

If you can tell me the values on the Point that causes the recursion, I'll test in the latest version. It's probably best to update, regardless. You'll have to rewrite your code to use the updated functions, but a lot has been fixed since the 1st of April.

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024

What exactly is wrong with Point.givenCoordinates?

from hyperbolic-canvas.

 avatar commented on August 22, 2024
  1. I changed Point.CENTER to Point.ORIGIN in my actual code.
  2. mouseCoords is the Euclidean coordinates of the hyperbolic point your mouse is on. (If your mouse is in the center, mouseCoords is {x: 0, y: 0}. It's a plain object, not a Point.
  3. All I know is that they are within the plane... as your mouse and player circle move, the points change.
  4. It doesn't initialize the values of _isIdeal, _euclideanRadius, or _hyperbolicRadius. It just inits _x and _y.

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024
  1. Okay. Maybe I'll allow both.
  2. How did you calculate the correct coordinates of the mouse without using Canvas.at? A few things are happening there: the plane is flipped vertically so that positive-y corresponds to "up"; the center of the canvas, rather than the top left, is made to correspond to (0, 0); and the Euclidean radius of the canvas is made to correspond to 1. Do your mouseCoords reflect all of those changes?
  3. So the _x and _y of any Point on the plane should be less than 1 (as should _x * _x + _y * _y).
  4. That's intentional. The other values are meant to be calculated as needed. Do you see where I might have missed a check for undefined values?

from hyperbolic-canvas.

 avatar commented on August 22, 2024

(2) I'm actually using a different system for rendering. I wanted an up-close view that only shows a certain Euclidean-rectangle-slice of the disk at once. But I'm confident my code works — it was working before April...

(4) Well, somehow the isIdeal, getEuclideanRadius, and getHyperbolicRadius are linked into an infinite loop. I could send my entire code, but...
The stack of functions is so long I can't see where it's getting called on my end. Only chance is to use a bunch of try commands and catch the line it happened on.

from hyperbolic-canvas.

 avatar commented on August 22, 2024

Found out the problem is in here:

var dst = random(1, 3.9);
var ø = random(360);
var pt = Point.givenHyperbolicPolarCoordinates(dst, ø);
var radius = random(0.08, 0.3);
critters.push(new Critter(pt.x, pt.y, radius));

The Critter constructor, stripped of everything I know isn't the problem:

// The Euclidean point that is the hyperbolic center
this.center = Point.givenCoordinates(x, y);
// but a HYPERBOLIC radius.
this.radius = r;

this.circle = Circle.givenHyperbolicCenterRadius(this.center, this.radius);

x and y come directly from a real legit Point.

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024

pt.x and pt.y are undefined. Use pt.getX() and pt.getY().

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024

But why not just pass pt to the Critter constructor? It should be identical to the new one that is created, aside from floating point errors.

from hyperbolic-canvas.

 avatar commented on August 22, 2024

Fixed it, thanks!!

from hyperbolic-canvas.

ItsNickBarry avatar ItsNickBarry commented on August 22, 2024

Let me know if you create something interesting, and I'll link to it when I redo the site.

from hyperbolic-canvas.

Related Issues (12)

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.