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

Implementation of DateTime and PShape #46

Closed
wants to merge 15 commits into from
Closed

Implementation of DateTime and PShape #46

wants to merge 15 commits into from

Conversation

AliabbasMerchant
Copy link

This code was written by me as a prototype for my GSoC 2018 proposal.
I was not selected, but I would want you to please merge this with the main repo.
The code contains:

  1. A complete DateTime module, similar to the Processing Java Code.
  2. A basic prototype for the PShape module.
  3. A demo of Pshape (PShape_demo.py)

BOX = 41 # primitive


class PShape():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're dropping the P prefix in p5. So Processing's "PShape" becomes "Shape" in p5. We already have a Shape class and this new code should go in there.

MAX_POINT_ACCURACY = 200
POINT_ACCURACY_FACTOR = 10

OPEN, CLOSE = 1, 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a nicer way of doing this other than assigning numbers to constants?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use strings instead.
But numbers are faster to work with.
Also, the variables have been named quite appropriately.
Plus, these are the same constant names as used in the Java code, so there is a less of a learning curve/ less work while switching from Java to p5.

Copy link
Member

@abhikpal abhikpal Apr 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering of other solutions that do not necessarily use these variables. For instance, instead of defining OPEN and CLOSE we could just use keyword arguments: def end_shape(self, open=True)

We may use strings instead. But numbers are faster to work with.

Correct. But this doesn't seem to influence things that much. I looked around a bit and at least in the popular scientific computing libraries this seems to be quite common. In scipy for instance, one would often do scipy.optimize.minimize(f, x0, method='CG'). I really don't think something like self._kind == 'group' would be an issue.

Copy link

@GoToLoop GoToLoop Apr 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like if n1 attempts to convert a Java or even a Python Mode sketch into p5py is gonna know hell! :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoToLoop, ¯\_(ツ)_/¯

self._vertices = []
self.close = False

def beginShape(self, kind = None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to use context managers in p5. So instead of

foo.beginShape()
# code
foo.endShape()

we would like to have

with foo.begin_shape():
    # code

See the code for push_matrix() in p5/transforms.py for the implementation details. And the contextlib docs: https://docs.python.org/3/library/contextlib.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
That would be more pythonic.
My main aim was initially just to make it function just like the Java code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main aim was initially just to make it function just like the Java code.

We don't have to. We're just keeping the higher-level api similar, the internals can definitely change! And of course, we always try to use some of the Python features whenever possible :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll keep that in mind.
This is the same reason why I used beginShape() instead of begin_shape()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def endShape(self, mode=OPEN):
if self._kind == GROUP:
warnings.warn("Cannot end GROUP shape")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an error here makes more sense, no?

@abhikpal
Copy link
Member

This is quite nice! But a couple of general comments:


def beginShape(self, kind = None):
self._vertices = []
if type is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type is a Python built-in!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. My bad😌

@auraz
Copy link

auraz commented Feb 26, 2019

Please resolve conflicts with main branch

@arihantparsoya
Copy link
Member

The features in this pull request have been incorporated in the current version of p5py

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

Successfully merging this pull request may close these issues.

5 participants