Skip to content

Commit

Permalink
Added __repr__() methods for all Renderables
Browse files Browse the repository at this point in the history
Signed-off-by: Bhavye Mathur <[email protected]>
  • Loading branch information
BhavyeMathur committed Jan 9, 2024
1 parent 2601ce4 commit 427435f
Show file tree
Hide file tree
Showing 26 changed files with 45 additions and 94 deletions.
Binary file modified binaries/lib-macos/libgoopylib.dylib
Binary file not shown.
69 changes: 33 additions & 36 deletions goopylib/objects/circle/circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,48 @@
#include "src/goopylib/objects/Circle.h"


PyObject *circle::new_(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) {
CircleObject *self;
self = (CircleObject *) type->tp_alloc(type, 0);
namespace circle {
PyObject *new_(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) {
CircleObject *self;
self = (CircleObject *) type->tp_alloc(type, 0);

if (self != nullptr) {
if (self != nullptr) {

}
return (PyObject *) self;
}
return (PyObject *) self;
}

int circle::init(CircleObject *self, PyObject *args, PyObject *Py_UNUSED(kwds)) {
GP_PY_INFO("gp.circle.Circle()");

float x1, y1;
float radius;
if (!PyArg_ParseTuple(args, "(ff)f", &x1, &y1, &radius)) {
return -1;
}
int init(CircleObject *self, PyObject *args, PyObject *Py_UNUSED(kwds)) {
GP_PY_INFO("gp.circle.Circle()");

self->circle = Ref<gp::Circle>(new gp::Circle({x1, y1}, radius));
self->base.ellipse = self->circle;
self->base.base.renderable = self->circle;
return 0;
}
float x1, y1;
float radius;
if (!PyArg_ParseTuple(args, "(ff)f", &x1, &y1, &radius)) {
return -1;
}

PyObject *circle::repr(CircleObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.circle.Circle.__repr__()");
return PyUnicode_FromString("Circle()");
}
self->circle = Ref<gp::Circle>(new gp::Circle({x1, y1}, radius));
self->base.ellipse = self->circle;
self->base.base.renderable = self->circle;
return 0;
}

int circle::traverse(CircleObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}
int traverse(CircleObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}

int circle::clear(CircleObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.circle.Circle.clear()");
return 0;
}
int clear(CircleObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.circle.Circle.clear()");
return 0;
}

void circle::dealloc(CircleObject *self) {
GP_PY_DEBUG("gp.circle.Circle.__dealloc__()");
void dealloc(CircleObject *self) {
GP_PY_DEBUG("gp.circle.Circle.__dealloc__()");

self->circle.reset();
self->circle.reset();

PyObject_GC_UnTrack(self);
clear(self);
Py_TYPE(self)->tp_free((PyObject *) self);
PyObject_GC_UnTrack(self);
clear(self);
Py_TYPE(self)->tp_free((PyObject *) self);
}
}
2 changes: 0 additions & 2 deletions goopylib/objects/circle/circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace circle {

int init(CircleObject *self, PyObject *args, PyObject *kwds);

PyObject *repr(CircleObject *self);

int traverse(CircleObject *self, visitproc visit, void *arg);

int clear(CircleObject *self);
Expand Down
2 changes: 1 addition & 1 deletion goopylib/objects/circle/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PyTypeObject CircleType = {
nullptr,
nullptr,
nullptr,
(reprfunc) circle::repr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down
5 changes: 0 additions & 5 deletions goopylib/objects/ellipse/ellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ namespace ellipse {
return 0;
}

PyObject *repr(EllipseObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.ellipse.Ellipse.__repr__()");
return PyUnicode_FromString("Ellipse()");
}

int traverse(EllipseObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions goopylib/objects/ellipse/ellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace ellipse {

int init(EllipseObject *self, PyObject *args, PyObject *kwds);

PyObject *repr(EllipseObject *self);

int traverse(EllipseObject *self, visitproc visit, void *arg);

int clear(EllipseObject *self);
Expand Down
2 changes: 1 addition & 1 deletion goopylib/objects/ellipse/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PyTypeObject EllipseType = {
nullptr,
nullptr,
nullptr,
(reprfunc) ellipse::repr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down
5 changes: 0 additions & 5 deletions goopylib/objects/image/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ namespace image {
return 0;
}

PyObject *repr(ImageObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.image.Image.__repr__()");
return PyUnicode_FromString("Image()");
}

int traverse(ImageObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions goopylib/objects/image/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace image {

int init(ImageObject *self, PyObject *args, PyObject *kwds);

PyObject *repr(ImageObject *self);

int traverse(ImageObject *self, visitproc visit, void *arg);

int clear(ImageObject *self);
Expand Down
2 changes: 1 addition & 1 deletion goopylib/objects/image/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PyTypeObject ImageType = {
nullptr,
nullptr,
nullptr,
(reprfunc) image::repr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down
5 changes: 0 additions & 5 deletions goopylib/objects/line/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ namespace line {
return 0;
}

PyObject *repr(LineObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.line.Line.__repr__()");
return PyUnicode_FromString("Line()");
}

int traverse(LineObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions goopylib/objects/line/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace line {

int init(LineObject *self, PyObject *args, PyObject *kwds);

PyObject *repr(LineObject *self);

int traverse(LineObject *self, visitproc visit, void *arg);

int clear(LineObject *self);
Expand Down
2 changes: 1 addition & 1 deletion goopylib/objects/line/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PyTypeObject LineType = {
nullptr,
nullptr,
nullptr,
(reprfunc) line::repr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down
5 changes: 0 additions & 5 deletions goopylib/objects/quad/quad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ namespace quad {
return 0;
}

PyObject *repr(QuadObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.quad.Quad.__repr__()");
return PyUnicode_FromString("Quad()");
}

int traverse(QuadObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions goopylib/objects/quad/quad.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace quad {

int init(QuadObject *self, PyObject *args, PyObject *kwds);

PyObject *repr(QuadObject *self);

int traverse(QuadObject *self, visitproc visit, void *arg);

int clear(QuadObject *self);
Expand Down
2 changes: 1 addition & 1 deletion goopylib/objects/quad/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PyTypeObject QuadType = {
nullptr,
nullptr,
nullptr,
(reprfunc) quad::repr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down
6 changes: 0 additions & 6 deletions goopylib/objects/rectangle/rectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ namespace rectangle {
return 0;
}

PyObject *repr(RectangleObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.rectangle.Rectangle.__repr__()");
// TODO object toString methods
return PyUnicode_FromString("Rectangle()");
}

int traverse(RectangleObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions goopylib/objects/rectangle/rectangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace rectangle {

int init(RectangleObject *self, PyObject *args, PyObject *kwds);

PyObject *repr(RectangleObject *self);

int traverse(RectangleObject *self, visitproc visit, void *arg);

int clear(RectangleObject *self);
Expand Down
2 changes: 1 addition & 1 deletion goopylib/objects/rectangle/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PyTypeObject RectangleType = {
nullptr,
nullptr,
nullptr,
(reprfunc) rectangle::repr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down
5 changes: 2 additions & 3 deletions goopylib/objects/renderable/renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ namespace renderable {

int init(RenderableObject *Py_UNUSED(self), PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) {
GP_PY_INFO("gp.renderable.Renderable()");

return 0;
}

PyObject *repr(RenderableObject *Py_UNUSED(self)) {
PyObject *repr(RenderableObject *self) {
GP_PY_TRACE("gp.renderable.Renderable.__repr__()");
return PyUnicode_FromString("Renderable()");
return PyUnicode_FromString(self->renderable->toString().c_str());
}

int traverse(RenderableObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
Expand Down
5 changes: 0 additions & 5 deletions goopylib/objects/triangle/triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ namespace triangle {
return 0;
}

PyObject *repr(TriangleObject *Py_UNUSED(self)) {
GP_PY_TRACE("gp.triangle.Triangle.__repr__()");
return PyUnicode_FromString("Triangle()");
}

int traverse(TriangleObject *Py_UNUSED(self), visitproc Py_UNUSED(visit), void *Py_UNUSED(arg)) {
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions goopylib/objects/triangle/triangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace triangle {

int init(TriangleObject *self, PyObject *args, PyObject *kwds);

PyObject *repr(TriangleObject *self);

int traverse(TriangleObject *self, visitproc visit, void *arg);

int clear(TriangleObject *self);
Expand Down
2 changes: 1 addition & 1 deletion goopylib/objects/triangle/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PyTypeObject TriangleType = {
nullptr,
nullptr,
nullptr,
(reprfunc) triangle::repr,
nullptr,
nullptr,
nullptr,
nullptr,
Expand Down
2 changes: 1 addition & 1 deletion src/goopylib/objects/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace gp {
}

std::string Image::toString() const {
return strformat("Image(%s, (%g, %g))", m_Path.c_str(), m_Position.x, m_Position.y);
return strformat("Image('%s', (%g, %g))", m_Path.c_str(), m_Position.x, m_Position.y);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/goopylib/objects/TexturedQuad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace gp {
}

std::string TexturedQuad::toString() const {
return strformat("TexturedQuad(%s, (%g, %g), (%g, %g), (%g, %g), (%g, %g))", m_Texture.c_str(),
return strformat("TexturedQuad('%s', (%g, %g), (%g, %g), (%g, %g), (%g, %g))", m_Texture.c_str(),
getP1().x, getP1().y, getP2().x, getP2().y, getP3().x, getP3().y, getP4().x, getP4().y);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/goopylib/objects/TexturedRectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace gp {
};

std::string TexturedRectangle::toString() const {
return strformat("TexturedQuad(%s, (%g, %g), (%g, %g))", m_Texture.c_str(),
return strformat("TexturedQuad('%s', (%g, %g), (%g, %g))", m_Texture.c_str(),
getP1().x, getP1().y, getP3().x, getP3().y);
}
}

0 comments on commit 427435f

Please sign in to comment.