diff --git a/.gitmodules b/.gitmodules index 67f8fd9..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "wobbly/third_party/allow_move_optional"] - path = wobbly/third_party/allow_move_optional - url = git://github.com/smspillaz/CopyMoveConstrainedOptional diff --git a/.travis.yml b/.travis.yml index 5761898..df5b8a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,5 @@ script: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo RUN apt-get update >> Dockerfile; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo RUN apt-get install -y meson ninja-build build-essential git pkg-config libglib2.0-dev gir1.2-glib-2.0 gobject-introspection libgirepository1.0-dev >> Dockerfile; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker build -t withgit .; fi - - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run withgit /bin/sh -c "cd /root && TRAVIS=true CC=$CC CXX=$CXX meson -Db_sanitize=address,undefined -Dwerror=true builddir && ninja -C builddir && G_SLICE=always-malloc ./builddir/tests/windowfx_wobbly_test --gtest_color=yes"; fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run withgit /bin/sh -c "cd /root && TRAVIS=true CC=$CC CXX=$CXX meson -Db_sanitize=address,undefined -Dwerror=true builddir && ninja -C builddir && G_SLICE=always-malloc ./builddir/tests/animation_test --gtest_color=yes"; fi diff --git a/animation-glib/meson.build b/animation-glib/meson.build new file mode 100644 index 0000000..fb997bb --- /dev/null +++ b/animation-glib/meson.build @@ -0,0 +1,81 @@ +# /animation-glib/meson.build +# +# Build the libanimation-glib library. +# +# Copyright (C) 2017, 2018 Endless Mobile, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +api_version = '0' + +animation_glib_toplevel_headers = ['vector.h'] +animation_glib_toplevel_introspectable_sources = ['vector.cpp'] + +animation_glib_introspectable_sources = [] +animation_glib_private_sources = [] +animation_glib_headers = [] +animation_glib_headers_subdir = 'animation-glib' + +subdir('wobbly') + +animation_glib_introspectable_sources += files(animation_glib_toplevel_introspectable_sources) +animation_glib_headers += files(animation_glib_toplevel_headers) + +install_headers(animation_glib_toplevel_headers, subdir: animation_glib_headers_subdir) + +animation_glib_sources = animation_glib_introspectable_sources + animation_glib_private_sources + +glib = dependency('glib-2.0') +gobject = dependency('gobject-2.0') + +animation_glib_lib = shared_library( + 'animation-glib', + animation_glib_sources, + soversion: api_version, + install: true, + include_directories: [ animation_inc ], + dependencies: [ glib, gobject, animation_dep ] +) + +animation_glib_dep = declare_dependency( + link_with: animation_glib_lib, + include_directories: [ animation_inc ], +) + +introspection_sources = [ animation_glib_introspectable_sources, animation_glib_headers ] + +gnome = import('gnome') +gnome.generate_gir( + animation_glib_lib, + extra_args: ['--warn-all', '--warn-error'], + identifier_prefix: 'Animation', + include_directories: animation_inc, + includes: ['GLib-2.0', 'GObject-2.0'], + install: true, + namespace: 'Animation', + nsversion: api_version, + sources: introspection_sources, + symbol_prefix: 'animation' +) + +pkg = import('pkgconfig') +pkg.generate( + description: 'Library to provide 2D surface animations (GObject Binding)', + name: 'libanimation-glib', + filebase: 'libanimation-glib-' + api_version, + version: meson.project_version(), + libraries: animation_glib_lib, + install_dir: join_paths(get_option('libdir'), 'pkgconfig') +) diff --git a/wobbly-glib/vector.cpp b/animation-glib/vector.cpp similarity index 60% rename from wobbly-glib/vector.cpp rename to animation-glib/vector.cpp index 1644f03..b2f0ec6 100644 --- a/wobbly-glib/vector.cpp +++ b/animation-glib/vector.cpp @@ -1,14 +1,14 @@ /* - * wobbly-glib/vector.cpp + * animation-glib/vector.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -21,20 +21,20 @@ * type implementation. */ -#include +#include static gpointer -wobbly_vector_copy (gpointer ptr) +animation_vector_copy (gpointer ptr) { - WobblyVector *src = reinterpret_cast (ptr); - WobblyVector *dst = g_new0 (WobblyVector, 1); + AnimationVector *src = reinterpret_cast (ptr); + AnimationVector *dst = g_new0 (AnimationVector, 1); *dst = *src; return reinterpret_cast (dst); } -G_DEFINE_BOXED_TYPE (WobblyVector, - wobbly_vector, - wobbly_vector_copy, - g_free) +G_DEFINE_BOXED_TYPE (AnimationVector, + animation_vector, + animation_vector_copy, + g_free); diff --git a/animation-glib/vector.h b/animation-glib/vector.h new file mode 100644 index 0000000..62fabe4 --- /dev/null +++ b/animation-glib/vector.h @@ -0,0 +1,37 @@ +/* + * animation-glib/vector.h + * + * Copyright 2018 Endless Mobile, Inc. + * + * libanimation is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * libanimation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with eos-companion-app-service. If not, see + * . + * + * GObject Interface for "wobbly" textures, 2D vector type. + */ +#pragma once + +#include + +G_BEGIN_DECLS + +typedef struct { + double x; + double y; +} AnimationVector; + +#define ANIMATION_TYPE_VECTOR animation_vector_get_type () + +GType animation_vector_get_type (void); + +G_END_DECLS diff --git a/animation-glib/wobbly/anchor.cpp b/animation-glib/wobbly/anchor.cpp new file mode 100644 index 0000000..8aa9687 --- /dev/null +++ b/animation-glib/wobbly/anchor.cpp @@ -0,0 +1,118 @@ +/* + * animation-glib/wobbly/anchor.cpp + * + * Copyright 2018 Endless Mobile, Inc. + * + * libanimation is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * libanimation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with eos-companion-app-service. If not, see + * . + * + * GObject Interface for "wobbly" textures, Anchor + * type implementation. + */ + +#include + +#include + +#include "wobbly-anchor-private.h" + +struct _AnimationWobblyAnchor +{ + GObject parent_instance; +}; + +typedef struct _AnimationWobblyAnchorPrivate +{ + wobbly::Anchor *anchor; +} AnimationWobblyAnchorPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (AnimationWobblyAnchor, + animation_wobbly_anchor, + G_TYPE_OBJECT); + +/** + * animation_wobbly_anchor_move_by: + * @anchor: A #AnimationWobblyAnchor + * @vector: A #AnimationVector to move the anchor by + * + * Move the anchor by @vector, causing force to be exerted + * on the underlying anchor's model. + */ +void +animation_wobbly_anchor_move_by (AnimationWobblyAnchor *anchor, + AnimationVector vector) +{ + AnimationWobblyAnchorPrivate *priv = + reinterpret_cast (animation_wobbly_anchor_get_instance_private (anchor)); + + if (priv->anchor != nullptr) + priv->anchor->MoveBy (animation::Point (vector.x, vector.y)); +} + + +/** + * animation_wobbly_anchor_release: + * @anchor: A #AnimationWobblyAnchor + * + * Release the anchor, allowing the relevant control points + * to move freely and have force exerted on them. Attempting + * to move the anchor past this point is inert. + */ +void +animation_wobbly_anchor_release (AnimationWobblyAnchor *anchor) +{ + AnimationWobblyAnchorPrivate *priv = + reinterpret_cast (animation_wobbly_anchor_get_instance_private (anchor)); + + if (priv->anchor != nullptr) + { + delete priv->anchor; + priv->anchor = nullptr; + } +} + +static void +animation_wobbly_anchor_finalize (GObject *object) +{ + AnimationWobblyAnchor *anchor = ANIMATION_WOBBLY_ANCHOR (object); + + animation_wobbly_anchor_release (anchor); +} + +static void +animation_wobbly_anchor_init (AnimationWobblyAnchor *store) +{ +} + + +static void +animation_wobbly_anchor_class_init (AnimationWobblyAnchorClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = animation_wobbly_anchor_finalize; +} + +AnimationWobblyAnchor * +animation_wobbly_anchor_new_for_native_anchor_rvalue (wobbly::Anchor &&anchor) +{ + AnimationWobblyAnchor *anchor_object = + ANIMATION_WOBBLY_ANCHOR (g_object_new (ANIMATION_TYPE_WOBBLY_ANCHOR, NULL)); + AnimationWobblyAnchorPrivate *priv = + reinterpret_cast (animation_wobbly_anchor_get_instance_private (anchor_object)); + + priv->anchor = new wobbly::Anchor (std::move (anchor)); + + return anchor_object; +} diff --git a/animation-glib/wobbly/anchor.h b/animation-glib/wobbly/anchor.h new file mode 100644 index 0000000..ed8bb18 --- /dev/null +++ b/animation-glib/wobbly/anchor.h @@ -0,0 +1,43 @@ +/* + * animation-glib/wobbly/anchor.h + * + * Copyright 2018 Endless Mobile, Inc. + * + * libanimation is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * libanimation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with eos-companion-app-service. If not, see + * . + * + * GObject Interface for "wobbly" textures, Anchor type. + * + * An anchor is an object type privately holding an + * anchor. The owner can release the anchor, which happens + * implicitly when its ref-count drops to zero or when + * the release() method is called. + */ +#pragma once + +#include + +#include + +G_BEGIN_DECLS + +#define ANIMATION_TYPE_WOBBLY_ANCHOR animation_wobbly_anchor_get_type () +G_DECLARE_FINAL_TYPE (AnimationWobblyAnchor, animation_wobbly_anchor, ANIMATION, WOBBLY_ANCHOR, GObject) + +void animation_wobbly_anchor_move_by (AnimationWobblyAnchor *anchor, + AnimationVector vector); + +void animation_wobbly_anchor_release (AnimationWobblyAnchor *anchor); + +G_END_DECLS diff --git a/animation-glib/wobbly/meson.build b/animation-glib/wobbly/meson.build new file mode 100644 index 0000000..f11a5df --- /dev/null +++ b/animation-glib/wobbly/meson.build @@ -0,0 +1,21 @@ +# /animation-glib/wobbly/meson.build +# +# Build the libanimation-glib library, wobbly component. +# +# See /LICENCE.md for Copyright information. + +wobbly_introspectable_sources = [ + 'anchor.cpp', + 'model.cpp' +] +wobbly_private_sources = ['wobbly-anchor-private.h'] +wobbly_headers = [ + 'anchor.h', + 'model.h' +] + +animation_glib_introspectable_sources += files(wobbly_introspectable_sources) +animation_glib_private_sources += files(wobbly_private_sources) +animation_glib_headers += files(wobbly_headers) + +install_headers(wobbly_headers, subdir: join_paths(animation_glib_headers_subdir, 'wobbly')) diff --git a/animation-glib/wobbly/model.cpp b/animation-glib/wobbly/model.cpp new file mode 100644 index 0000000..cc74a97 --- /dev/null +++ b/animation-glib/wobbly/model.cpp @@ -0,0 +1,461 @@ +/* + * animation-glib/wobbly/wobbly.cpp + * + * Copyright 2018 Endless Mobile, Inc. + * + * libanimation is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * libanimation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with eos-companion-app-service. If not, see + * . + * + * GObject Interface for "wobbly" textures. + */ + +#include +#include +#include + +#include + +#include "wobbly-anchor-private.h" + +struct _AnimationWobblyModel +{ + GObject parent_instance; +}; + +typedef struct _AnimationWobblyModelPrivate +{ + wobbly::Model::Settings settings; + wobbly::Model *model; + + /* We need to keep track of these during + * construction while model isn't set */ + AnimationVector prop_position; + AnimationVector prop_size; +} AnimationWobblyModelPrivate; + +G_DEFINE_TYPE_WITH_PRIVATE (AnimationWobblyModel, + animation_wobbly_model, + G_TYPE_OBJECT) + +enum { + PROP_0, + PROP_SPRING_K, + PROP_FRICTION, + PROP_MAXIMUM_RANGE, + PROP_POSITION, + PROP_SIZE, + NPROPS +}; + +static GParamSpec *animation_wobbly_model_props [NPROPS] = { NULL, }; + +namespace agd = animation::geometry::dimension; + +/** + * animation_wobbly_model_grab_anchor: + * @model: A #AnimationWobblyModel + * @position: A #AnimationVector specifying the position in absolute space + * where the closest object in the mesh should be grabbed. + * + * Grab the closest control point in the mesh to @position and + * return it as a #AnimationWobblyAnchor. The control point will not have spring + * force exerted upon it, though other control points will have forces + * exerted on them by the anchored control point. + * + * The control point remains grabbed until animation_wobbly_anchor_release() is + * called on the anchor, or the anchor is destroyed. + * + * Returns: (transfer full): A #AnimationWobblyAnchor controlling the closest control + * point to @position. + */ +AnimationWobblyAnchor * +animation_wobbly_model_grab_anchor (AnimationWobblyModel *model, + AnimationVector position) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + wobbly::Anchor anchor (priv->model->GrabAnchor (animation::Point (position.x, + position.y))); + + return animation_wobbly_anchor_new_for_native_anchor_rvalue (std::move (anchor)); +} + +/** + * animation_wobbly_model_insert_anchor: + * @model: A #AnimationWobblyModel + * @position: A #AnimationVector specifying the position in absolute space + * where the anchoring control point should be inserted + * + * Insert a new control point into the mesh at @position and split the + * closest spring to it in half, with both halves attaching to the + * inserted control point. The control point will not have spring + * force exerted upon it, though other control points will have forces + * exerted on them by the anchored control point. + * + * The control point remains in place until animation_wobbly_anchor_release() is + * called on the anchor, or the anchor is destroyed. + * + * Returns: (transfer full): A #AnimationWobblyAnchor controlling the inserted control + * at @position. + */ +AnimationWobblyAnchor * +animation_wobbly_model_insert_anchor (AnimationWobblyModel *model, + AnimationVector position) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + wobbly::Anchor anchor (priv->model->InsertAnchor (animation::Point (position.x, + position.y))); + + return animation_wobbly_anchor_new_for_native_anchor_rvalue (std::move (anchor)); +} + +/** + * animation_wobbly_model_step: + * @model: A #AnimationWobblyModel + * @ms: Time period to integrate over. + * + * Compute all the instantaneous forces exerted by springs in the + * mesh and integrate over @ms to determine the velocities and + * changes in model control point positions. + * + * Returns: %TRUE if further integration is required, %FALSE otherwise. + */ +gboolean +animation_wobbly_model_step (AnimationWobblyModel *model, + unsigned int ms) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + return priv->model->Step (ms); +} + +/** + * animation_wobbly_model_deform_texcoords: + * @model: A #AnimationWobblyModel + * @uv: A #AnimationVector specifying the unit coordinates relative to + * the top right corner of a square to be deformed. + * @deformed: (out caller-allocates): A #AnimationVector specifying the + * absolute position in space that the unit co-ordinate would + * be deformed to. + * + * Deform texture-coordinates into real space according to the model. + */ +void +animation_wobbly_model_deform_texcoords (AnimationWobblyModel *model, + AnimationVector uv, + AnimationVector *deformed) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + g_return_if_fail (deformed != NULL); + + animation::Point deformed_point (priv->model->DeformTexcoords (animation::Point (uv.x, uv.y))); + *deformed = { + animation::geometry::dimension::get <0> (deformed_point), + animation::geometry::dimension::get <1> (deformed_point) + }; +} + +/** + * animation_wobbly_model_deform_query_extremes: + * @model: A #AnimationWobblyModel + * @uv: A #AnimationVector specifying the unit coordinates relative to + * the top right corner of a square to be deformed. + * @top_left: (out caller-allocates): The top left extreme. + * @top_right: (out caller-allocates): The top right extreme. + * @bottom_left: (out caller-allocates): The bottom left extreme. + * @bottom_right: (out caller-allocates): The bottom right extreme. + * + * Query the bounding 4-vertex polygon around the model. + */ +void +animation_wobbly_model_query_extremes (AnimationWobblyModel *model, + AnimationVector *top_left, + AnimationVector *top_right, + AnimationVector *bottom_left, + AnimationVector *bottom_right) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + std::array extremes (priv->model->Extremes ()); + + if (top_left != nullptr) + *top_left = { agd::get <0> (extremes[0]), agd::get <1> (extremes[0]) }; + + if (top_right != nullptr) + *top_right = { agd::get <0> (extremes[1]), agd::get <1> (extremes[1]) }; + + if (bottom_left != nullptr) + *bottom_left = { agd::get <0> (extremes[2]), agd::get <1> (extremes[2]) }; + + if (bottom_right != nullptr) + *bottom_right = { agd::get <0> (extremes[3]), agd::get <1> (extremes[3]) }; +} + +/** + * animation_wobbly_model_move_to: + * @model: A #AnimationWobblyModel + * @position: A #AnimationVector to move the top right corner to. + * + * Move the entire model to have its top right corner at @position + * without causing any deformation. + */ +void +animation_wobbly_model_move_to (AnimationWobblyModel *model, + AnimationVector position) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + priv->prop_position = position; + + if (priv->model != nullptr) + priv->model->MoveModelTo (animation::Point (position.x, position.y)); +} + +/** + * animation_wobbly_model_move_by: + * @model: A #AnimationWobblyModel + * @delta: A #AnimationVector to move the top right corner by. + * + * Move the entire model by @position without causing any deformation. + */ +void +animation_wobbly_model_move_by (AnimationWobblyModel *model, + AnimationVector delta) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + priv->prop_position.x += delta.x; + priv->prop_position.y += delta.y; + + if (priv->model != nullptr) + priv->model->MoveModelBy (animation::Point (delta.x, delta.y)); +} + +/** + * animation_wobbly_model_resize: + * @model: A #AnimationWobblyModel + * @size: A #AnimationVector specifying the size in each dimension. + * + * Resize the model according to @size. + */ +void +animation_wobbly_model_resize (AnimationWobblyModel *model, + AnimationVector size) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + priv->prop_size = size; + + if (priv->model != nullptr) + priv->model->ResizeModel (size.x, size.y); +} + +void +animation_wobbly_model_set_spring_k (AnimationWobblyModel *model, + double spring_constant) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + priv->settings.springConstant = spring_constant; +} + +void +animation_wobbly_model_set_friction (AnimationWobblyModel *model, + double friction) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + priv->settings.friction = friction; +} + +void +animation_wobbly_model_set_maximum_range (AnimationWobblyModel *model, + double range) +{ + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + priv->settings.maximumRange = range; +} + +static void +animation_wobbly_model_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + AnimationWobblyModel *model = ANIMATION_WOBBLY_MODEL (object); + + switch (prop_id) + { + case PROP_SPRING_K: + animation_wobbly_model_set_spring_k (model, g_value_get_double (value)); + break; + case PROP_FRICTION: + animation_wobbly_model_set_friction (model, g_value_get_double (value)); + break; + case PROP_MAXIMUM_RANGE: + animation_wobbly_model_set_maximum_range (model, g_value_get_double (value)); + break; + case PROP_POSITION: + animation_wobbly_model_move_to (model, *(reinterpret_cast (g_value_get_boxed (value)))); + break; + case PROP_SIZE: + animation_wobbly_model_resize (model, *(reinterpret_cast (g_value_get_boxed (value)))); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +animation_wobbly_model_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + AnimationWobblyModel *model = ANIMATION_WOBBLY_MODEL (object); + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + switch (prop_id) + { + case PROP_SPRING_K: + g_value_set_double (value, priv->settings.springConstant); + break; + case PROP_FRICTION: + g_value_set_double (value, priv->settings.friction); + break; + case PROP_MAXIMUM_RANGE: + g_value_set_double (value, priv->settings.maximumRange); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +animation_wobbly_model_finalize (GObject *object) +{ + AnimationWobblyModel *model = ANIMATION_WOBBLY_MODEL (object); + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + delete priv->model; + priv->model = nullptr; + + G_OBJECT_CLASS (animation_wobbly_model_parent_class)->finalize (object); +} + +static void +animation_wobbly_model_constructed (GObject *object) +{ + AnimationWobblyModel *model = ANIMATION_WOBBLY_MODEL (object); + AnimationWobblyModelPrivate *priv = + reinterpret_cast (animation_wobbly_model_get_instance_private (model)); + + priv->model = new wobbly::Model (animation::Point (priv->prop_position.x, + priv->prop_position.y), + priv->prop_size.x, + priv->prop_size.y, + priv->settings); +} + +static void +animation_wobbly_model_init (AnimationWobblyModel *model) +{ +} + + +static void +animation_wobbly_model_class_init (AnimationWobblyModelClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = animation_wobbly_model_constructed; + object_class->get_property = animation_wobbly_model_get_property; + object_class->set_property = animation_wobbly_model_set_property; + object_class->finalize = animation_wobbly_model_finalize; + + animation_wobbly_model_props[PROP_SPRING_K] = + g_param_spec_double ("spring-k", + "Spring Constant", + "Multiplier for force exerted by springs", + 0.1, + 10.0, + wobbly::Model::DefaultSpringConstant, + static_cast (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + animation_wobbly_model_props[PROP_FRICTION] = + g_param_spec_double ("friction", + "Friction Constant", + "Multiplier for friction exerted by springs", + 0.1, + 10.0, + wobbly::Model::Friction, + static_cast (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + animation_wobbly_model_props[PROP_MAXIMUM_RANGE] = + g_param_spec_double ("movement-range", + "Object Movement Range", + "How far away connected points can be from their rest point", + 10.0, + 1000.0, + wobbly::Model::DefaultObjectRange, + static_cast (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + + animation_wobbly_model_props[PROP_POSITION] = + g_param_spec_boxed ("position", + "Model position", + "Where the model is in absolute 2D space", + ANIMATION_TYPE_VECTOR, + static_cast (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); + + animation_wobbly_model_props[PROP_SIZE] = + g_param_spec_boxed ("size", + "Model size", + "Where how big the model is in 2D space", + ANIMATION_TYPE_VECTOR, + static_cast (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); + + g_object_class_install_properties (object_class, + NPROPS, + animation_wobbly_model_props); +} + +AnimationWobblyModel * +animation_wobbly_model_new (AnimationVector position, + AnimationVector size, + double spring_constant, + double friction, + double maximum_range) +{ + return ANIMATION_WOBBLY_MODEL (g_object_new (ANIMATION_WOBBLY_TYPE_MODEL, + "spring-k", spring_constant, + "friction", friction, + "movement-range", maximum_range, + "position", &position, + "size", &size, + nullptr)); +} diff --git a/animation-glib/wobbly/model.h b/animation-glib/wobbly/model.h new file mode 100644 index 0000000..be1d8c6 --- /dev/null +++ b/animation-glib/wobbly/model.h @@ -0,0 +1,73 @@ +/* + * animation-glib/wobbly/model.h + * + * Copyright 2018 Endless Mobile, Inc. + * + * libanimation is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * libanimation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with eos-companion-app-service. If not, see + * . + * + * GObject Interface for "wobbly" textures. + */ +#pragma once + +#include + +#include +#include + +G_BEGIN_DECLS + +#define ANIMATION_WOBBLY_TYPE_MODEL animation_wobbly_model_get_type () +G_DECLARE_FINAL_TYPE (AnimationWobblyModel, animation_wobbly_model, ANIMATION, WOBBLY_MODEL, GObject) + +AnimationWobblyModel * animation_wobbly_model_new (AnimationVector position, + AnimationVector size, + double spring_constant, + double friction, + double maximum_range); + +AnimationWobblyAnchor * animation_wobbly_model_grab_anchor (AnimationWobblyModel *model, + AnimationVector position); + +AnimationWobblyAnchor * animation_wobbly_model_insert_anchor (AnimationWobblyModel *model, + AnimationVector position); + +gboolean animation_wobbly_model_step (AnimationWobblyModel *model, + unsigned int ms); + +void animation_wobbly_model_deform_texcoords (AnimationWobblyModel *model, + AnimationVector uv, + AnimationVector *deformed); + +void animation_wobbly_model_query_extremes (AnimationWobblyModel *model, + AnimationVector *top_left, + AnimationVector *top_right, + AnimationVector *bottom_left, + AnimationVector *bottom_right); + +void animation_wobbly_model_move_to (AnimationWobblyModel *model, + AnimationVector position); +void animation_wobbly_model_move_by (AnimationWobblyModel *model, + AnimationVector delta); + +void animation_wobbly_model_resize (AnimationWobblyModel *model, + AnimationVector size); + +void animation_wobbly_model_set_spring_k (AnimationWobblyModel *model, double spring_constant); + +void animation_wobbly_model_set_friction (AnimationWobblyModel *model, double friction); + +void animation_wobbly_model_set_maximum_range (AnimationWobblyModel *model, double range); + +G_END_DECLS diff --git a/animation-glib/wobbly/wobbly-anchor-private.h b/animation-glib/wobbly/wobbly-anchor-private.h new file mode 100644 index 0000000..86abda2 --- /dev/null +++ b/animation-glib/wobbly/wobbly-anchor-private.h @@ -0,0 +1,32 @@ +/* + * animation-glib/wobbly/wobbly-anchor-private.h + * + * Copyright 2018 Endless Mobile, Inc. + * + * libanimation is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * libanimation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with eos-companion-app-service. If not, see + * . + * + * GObject Interface for "wobbly" textures, Anchor type. + * + * An anchor is an object type privately holding an + * anchor. The owner can release the anchor, which happens + * implicitly when its ref-count drops to zero or when + * the release() method is called. + */ + +#pragma once + +#include + +AnimationWobblyAnchor * animation_wobbly_anchor_new_for_native_anchor_rvalue (wobbly::Anchor &&anchor); diff --git a/wobbly/geometry.h b/animation/geometry.h similarity index 86% rename from wobbly/geometry.h rename to animation/geometry.h index 6e1ca33..51413d8 100644 --- a/wobbly/geometry.h +++ b/animation/geometry.h @@ -1,14 +1,14 @@ /* - * wobbly/geometry.h + * animation/wobbly/geometry.h * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -20,12 +20,11 @@ * Provides geometric types and trait overloads * for 2D points and boxes. */ -#ifndef WOBBLY_GEOMETRY_H -#define WOBBLY_GEOMETRY_H +#pragma once -#include +#include -namespace wobbly +namespace animation { namespace geometry { @@ -71,7 +70,7 @@ namespace wobbly * at the same time. * * PointView implements the Dimension trait, meaning that it - * can be used with functions in the wobbly::geometry::dimension + * can be used with functions in the animation::geometry::dimension * namespace. */ template @@ -186,7 +185,7 @@ namespace wobbly namespace dimension { - /* Overloads for wobbly::PointView */ + /* Overloads for animation::PointView */ template struct Dimension > { @@ -217,7 +216,7 @@ namespace wobbly * type T. This is a structure of two values. * * PointModel implements the Dimension trait, meaning that it - * can be used with functions in the wobbly::geometry::dimension + * can be used with functions in the animation::geometry::dimension * namespace. */ template @@ -264,7 +263,7 @@ namespace wobbly namespace dimension { template - struct Dimension > + struct Dimension > { typedef T data_type; static const size_t dimensions = 2; @@ -316,9 +315,9 @@ namespace wobbly { public: - Box (T const &tr, T const &bl) : - tr (tr), - bl (bl) + Box (T const &tl, T const &br) : + tl (tl), + br (br) { } @@ -328,8 +327,8 @@ namespace wobbly template void apply_visitor (V &&visitor) const { - visitor (tr); - visitor (bl); + visitor (tl); + visitor (br); } template @@ -338,20 +337,30 @@ namespace wobbly (const_cast (*this))->apply_visitor (visitor); } + T const & topLeft () const + { + return tl; + } + + T const & bottomRight () const + { + return br; + } + private: - T tr; - T bl; + T tl; + T br; }; template template bool Box ::contains (U const &p) const { - auto const x1 = dimension::get <0> (tr); - auto const x2 = dimension::get <0> (bl); - auto const y1 = dimension::get <1> (tr); - auto const y2 = dimension::get <1> (bl); + auto const x1 = dimension::get <0> (tl); + auto const x2 = dimension::get <0> (br); + auto const y1 = dimension::get <1> (tl); + auto const y2 = dimension::get <1> (br); return (dimension::get <0> (p) >= x1 && dimension::get <0> (p) <= x2 && @@ -359,6 +368,18 @@ namespace wobbly dimension::get <1> (p) <= y2); } } -} -#endif + /* Import animation::geometry::Point types into + * animation namespace for compatibility. */ + typedef animation::geometry::Point Point; + typedef animation::geometry::Vector Vector; + + template + using PointView = animation::geometry::PointView ; + + template + using PointModel = animation::geometry::PointModel ; + + template + using Box = animation::geometry::Box ; +} diff --git a/wobbly/geometry_traits.h b/animation/geometry_traits.h similarity index 98% rename from wobbly/geometry_traits.h rename to animation/geometry_traits.h index 5effbed..5791657 100644 --- a/wobbly/geometry_traits.h +++ b/animation/geometry_traits.h @@ -1,14 +1,14 @@ /* - * wobbly/geometry_traits.h + * animation/wobbly/geometry_traits.h * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -19,12 +19,11 @@ * * Provides geometric trait mutation functions */ -#ifndef WOBBLY_GEOMETRY_TRAITS_H -#define WOBBLY_GEOMETRY_TRAITS_H +#pragma once #include -namespace wobbly +namespace animation { namespace geometry { @@ -380,5 +379,3 @@ namespace wobbly } } - -#endif diff --git a/wobbly/meson.build b/animation/meson.build similarity index 60% rename from wobbly/meson.build rename to animation/meson.build index bbb4bbe..0a7d758 100644 --- a/wobbly/meson.build +++ b/animation/meson.build @@ -1,4 +1,4 @@ -# /wobbly/meson.build +# /animation/meson.build # # Copyright (C) 2017, 2018 Endless Mobile, Inc. # @@ -16,42 +16,35 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Build the libwobbly library. +# Build the libanimation library. -api_version = '0.3' +api_version = '0' -wobbly_sources = [ - 'wobbly_internal.h', - 'wobbly.cpp' -] +animation_sources = [] +animation_headers = [] +animation_headers_subdir = 'animation' -wobbly_headers = [ - 'geometry.h', - 'geometry_traits.h', - 'wobbly.h' -] +subdir('wobbly') -wobbly_lib = shared_library( - 'windowfx_wobbly', - wobbly_sources, +animation_lib = shared_library( + 'animation', + animation_sources, soversion: api_version, install: true, - include_directories: [ wobbly_inc ] + include_directories: [ animation_inc ] ) -install_headers(wobbly_headers, subdir: 'wobbly') - -wobbly_dep = declare_dependency( - link_with: wobbly_lib, - include_directories: [ wobbly_inc ], +animation_dep = declare_dependency( + link_with: animation_lib, + include_directories: [ animation_inc ], ) pkg = import('pkgconfig') pkg.generate( - description: 'Library to provide a spring-controlled bezier mesh', - name: 'libwindowfx_wobbly', - filebase: 'libwindowfx_wobbly-' + api_version, + description: 'Library to provide 2D surface animations', + name: 'libanimation', + filebase: 'libanimation-' + api_version, version: meson.project_version(), - libraries: wobbly_lib, + libraries: animation_lib, install_dir: join_paths(get_option('libdir'), 'pkgconfig') ) diff --git a/wobbly/emscripten.cpp b/animation/wobbly/emscripten.cpp similarity index 91% rename from wobbly/emscripten.cpp rename to animation/wobbly/emscripten.cpp index 047b67e..1c67013 100644 --- a/wobbly/emscripten.cpp +++ b/animation/wobbly/emscripten.cpp @@ -1,14 +1,14 @@ /* - * src/emscripten.cpp + * animation/wobbly/emscripten.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -21,7 +21,7 @@ */ #include -#include +#include namespace em = emscripten; diff --git a/animation/wobbly/meson.build b/animation/wobbly/meson.build new file mode 100644 index 0000000..fe7fdca --- /dev/null +++ b/animation/wobbly/meson.build @@ -0,0 +1,19 @@ +# /animation/wobbly/meson.build +# +# Build the libanimation library (wobbly windows component). +# +# See /LICENCE.md for Copyright information. + +wobbly_sources = [ + 'wobbly_internal.h', + 'wobbly.cpp' +] + +wobbly_headers = [ + 'wobbly.h' +] + +animation_sources += files(wobbly_sources) +animation_headers += files(wobbly_headers) + +install_headers(wobbly_headers, subdir: join_paths(animation_headers_subdir, 'wobbly')) diff --git a/wobbly/wobbly.cpp b/animation/wobbly/wobbly.cpp similarity index 86% rename from wobbly/wobbly.cpp rename to animation/wobbly/wobbly.cpp index 20fa6c5..9d52c3e 100644 --- a/wobbly/wobbly.cpp +++ b/animation/wobbly/wobbly.cpp @@ -1,14 +1,14 @@ /* - * wobbly/wobbly.cpp + * animation/wobbly/wobbly.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -82,14 +82,13 @@ #include // for optional -#include // for PointView, PointModel, etc -#include // for assign, scale, etc -#include // for Model, etc +#include // for PointView, PointModel, etc +#include // for assign, scale, etc +#include // for Model, etc #include "wobbly_internal.h" // for Spring, MeshArray, etc -namespace wg = ::wobbly::geometry; -namespace wgd = ::wobbly::geometry::dimension; +namespace agd = ::animation::geometry::dimension; void wobbly::Anchor::MovableAnchorDeleter::operator () (MovableAnchor *anchor) @@ -106,7 +105,7 @@ wobbly::Anchor::~Anchor () } void -wobbly::Anchor::MoveBy (wobbly::Vector const &delta) noexcept +wobbly::Anchor::MoveBy (animation::Vector const &delta) noexcept { priv->MoveBy (delta); } @@ -232,21 +231,21 @@ wobbly::Spring::~Spring () void wobbly::Spring::ScaleLength (Vector scaleFactor) { - wgd::pointwise_scale (desiredDistance, scaleFactor); + agd::pointwise_scale (desiredDistance, scaleFactor); } namespace { std::vector - GenerateBaseSpringMesh (wobbly::MeshArray &points, - wobbly::MeshArray &forces, - wobbly::Vector const &springDimensions) + GenerateBaseSpringMesh (wobbly::MeshArray &points, + wobbly::MeshArray &forces, + animation::Vector const &springDimensions) { using namespace wobbly; std::vector springs; - double const springWidth = wgd::get <0> (springDimensions); - double const springHeight = wgd::get <1> (springDimensions); + double const springWidth = agd::get <0> (springDimensions); + double const springHeight = agd::get <1> (springDimensions); size_t const nSprings = SpringCountForGridSize (config::Width, config::Height); @@ -310,7 +309,7 @@ wobbly::SpringMesh::Scale (Vector const &scaleFactor) namespace { wobbly::Spring const & - FindSpringToSplit (wobbly::Point const &install, + FindSpringToSplit (animation::Point const &install, wobbly::SpringMesh::SpringVector const &vector) { using namespace wobbly; @@ -321,7 +320,7 @@ namespace vector.Each ([&](Spring const &spring) { double currentSpringPrimaryDistance = - wgd::distance (spring.FirstPosition (), install); + agd::distance (spring.FirstPosition (), install); if (currentSpringPrimaryDistance < primaryDistance) { primaryDistance = currentSpringPrimaryDistance; @@ -334,7 +333,7 @@ namespace if (currentSpringPrimaryDistance == primaryDistance) { double currentSpringSecondaryDistance = - wgd::distance (spring.SecondPosition (), install); + agd::distance (spring.SecondPosition (), install); if (currentSpringSecondaryDistance < secondaryDistance) { found = &spring; @@ -362,8 +361,8 @@ wobbly::SpringMesh::InstallAnchorSprings (Point const &install, std::unique_ptr data (new double[4]); std::fill_n (data.get (), 4, 0); - wobbly::PointView anchorView (data.get (), 0); - wgd::assign (anchorView, install); + animation::PointView anchorView (data.get (), 0); + agd::assign (anchorView, install); /* We always want the spring to *read* the first and second * positions, although the positions for the purpose of @@ -379,16 +378,16 @@ wobbly::SpringMesh::InstallAnchorSprings (Point const &install, PointView secondDesired (secondPref (found)); auto const insertSpring = - [this, &data](wobbly::PointView meshPoint, - wobbly::PointView desiredPoint, - wobbly::PointView meshForce) { + [this, &data](animation::PointView meshPoint, + animation::PointView desiredPoint, + animation::PointView meshForce) { PointView anchorPoint (data.get (), 0); PointView updatable (data.get (), 0); PointView anchorForce (data.get (), 1); Vector delta; - wgd::assign (delta, desiredPoint); - wgd::pointwise_subtract (delta, anchorPoint); + agd::assign (delta, desiredPoint); + agd::pointwise_subtract (delta, anchorPoint); return mSprings.EmplaceAndTrack (std::move (anchorForce), std::move (meshForce), @@ -437,17 +436,17 @@ namespace wobbly double height, Settings const &settings); - std::array const + std::array const Extremes () const; template - wobbly::Point + animation::Point TargetPositionByFullIntegration (Args&& ...additionalSteps) const; - wobbly::Point + animation::Point TargetPosition () const; - wobbly::Vector + animation::Vector TileSize () const; double mWidth, mHeight; @@ -605,29 +604,29 @@ namespace } template - wobbly::Point TopLeftPositionInSettledMesh (AnchorPoint const &anchor, - size_t const index, - wobbly::Vector const &tileSize) + animation::Point TopLeftPositionInSettledMesh (AnchorPoint const &anchor, + size_t const index, + animation::Vector const &tileSize) { - wobbly::Point start; - wgd::assign (start, anchor); + animation::Point start; + agd::assign (start, anchor); size_t const row = index % wobbly::config::Width; size_t const column = index / wobbly::config::Width; - wobbly::Point deltaToTopLeft (wgd::get <0> (tileSize) * row, - wgd::get <1> (tileSize) * column); - wgd::pointwise_subtract (start, deltaToTopLeft); + animation::Point deltaToTopLeft (agd::get <0> (tileSize) * row, + agd::get <1> (tileSize) * column); + agd::pointwise_subtract (start, deltaToTopLeft); return start; } } template -wobbly::Point +animation::Point wobbly::Model::Private::TargetPositionByFullIntegration (Args&& ...additionalSteps) const { - wobbly::Vector const tileSize (TileSize ()); + animation::Vector const tileSize (TileSize ()); auto points (mPositions.PointArray ()); auto &anchors (mAnchors); @@ -648,20 +647,20 @@ wobbly::Model::Private::TargetPositionByFullIntegration (Args&& ...additionalSte std::forward (additionalSteps)...)); /* Model will be settled, return the top left point */ - wobbly::Point result; - wgd::assign (result, wobbly::PointView (points, 0)); + animation::Point result; + agd::assign (result, animation::PointView (points, 0)); return result; } -wobbly::Point +animation::Point wobbly::Model::Private::TargetPosition () const { /* If we have at least one anchor, we can take a short-cut and determine * the target position by reference to it */ auto early = mTargets.PerformIfActive ([](MeshArray const &targets) { - wobbly::Point constructed; - wgd::assign (constructed, wobbly::PointView (targets, 0)); + animation::Point constructed; + agd::assign (constructed, animation::PointView (targets, 0)); return std::make_tuple (true, constructed); }); @@ -673,11 +672,11 @@ wobbly::Model::Private::TargetPosition () const return TargetPositionByFullIntegration (constrainment); } -wobbly::Vector +animation::Vector wobbly::Model::Private::TileSize () const { - return wobbly::Vector (mWidth / (config::Width - 1), - mHeight / (config::Height - 1)); + return animation::Vector (mWidth / (config::Width - 1), + mHeight / (config::Height - 1)); } namespace @@ -729,10 +728,10 @@ namespace return *this; } - void MoveBy (wobbly::Point const &delta) noexcept + void MoveBy (animation::Point const &delta) noexcept { - wobbly::PointView pv (data.get (), 0); - wgd::pointwise_add (pv, delta); + animation::PointView pv (data.get (), 0); + agd::pointwise_add (pv, delta); } private: @@ -749,7 +748,7 @@ namespace wobbly::Anchor InsertPointStrategy (wobbly::TargetMesh::Hnd &&handle, - wobbly::Point const &install, + animation::Point const &install, wobbly::MeshArray const &points, wobbly::TargetMesh const &targets, wobbly::SpringStep &spring) @@ -779,7 +778,7 @@ namespace /* We can't return a PointView direclty since it isn't * default-constructible, but we can return a tuple * with its arguments */ - if (wgd::equals ((spring.*fetch) (), position)) + if (agd::equals ((spring.*fetch) (), position)) return std::make_tuple (targets.data (), i); } @@ -812,7 +811,7 @@ namespace return active ? PP ([fetch, &getTarget](Spring const &spring) { // cppcheck-suppress unreachableCode auto args = getTarget (spring, fetch); - typedef wobbly::PointView + typedef animation::PointView CDPV; return CDPV (std::get <0> (args), std::get <1> (args)); @@ -849,9 +848,9 @@ namespace { public: - GrabAnchor (wobbly::PointView &&position, - wobbly::AnchorArray &array, - size_t index) : + GrabAnchor (animation::PointView &&position, + wobbly::AnchorArray &array, + size_t index) : position (std::move (position)), array (array), index (index) @@ -864,9 +863,9 @@ namespace array.Unlock (index); } - void MoveBy (wobbly::Point const &delta) noexcept + void MoveBy (animation::Point const &delta) noexcept { - wgd::pointwise_add (position, delta); + agd::pointwise_add (position, delta); } private: @@ -874,16 +873,16 @@ namespace GrabAnchor (GrabAnchor const &) = delete; GrabAnchor & operator= (GrabAnchor const &) = delete; - wobbly::PointView position; - wobbly::AnchorArray &array; - size_t index; + animation::PointView position; + wobbly::AnchorArray &array; + size_t index; }; wobbly::Anchor - GrabAnchorStrategy (wobbly::TargetMesh::Hnd &&handle, - wobbly::PointView &&point, - wobbly::AnchorArray &anchors, - size_t index) + GrabAnchorStrategy (wobbly::TargetMesh::Hnd &&handle, + animation::PointView &&point, + wobbly::AnchorArray &anchors, + size_t index) { typedef GrabAnchor GA; @@ -910,8 +909,8 @@ wobbly::Model::GrabAnchor (Point const &position) noexcept (false) auto activation (priv->mTargets.Activate ()); return Anchor (GrabAnchorStrategy (std::move (activation), - wobbly::PointView (points, - index), + animation::PointView (points, + index), priv->mAnchors, index)); } @@ -944,8 +943,8 @@ wobbly::Model::MoveModelBy (Point const &delta) { PointView pointView (points, i); PointView targetView (estimated, i); - wgd::pointwise_add (pointView, delta); - wgd::pointwise_add (targetView, delta); + agd::pointwise_add (pointView, delta); + agd::pointwise_add (targetView, delta); } /* Also move any inserted springs */ @@ -963,7 +962,7 @@ wobbly::Model::MoveModelTo (Point const &point) auto const &target (priv->TargetPosition ()); Vector delta (point); - wgd::pointwise_subtract (delta, target); + agd::pointwise_subtract (delta, target); MoveModelBy (delta); } @@ -976,10 +975,10 @@ wobbly::Model::ResizeModel (double width, double height) assert (height > 0.0f); /* Second, work out the scale factors */ - wobbly::Vector const scaleFactor (width / priv->mWidth, - height / priv->mHeight); + animation::Vector const scaleFactor (width / priv->mWidth, + height / priv->mHeight); - if (wgd::equals (scaleFactor, wobbly::Vector (1.0, 1.0))) + if (agd::equals (scaleFactor, animation::Vector (1.0, 1.0))) return; /* Then on each point, implement a transformation @@ -988,18 +987,18 @@ wobbly::Model::ResizeModel (double width, double height) auto &points (priv->mPositions.PointArray ()); auto &targets (priv->mTargets.PointArray ()); - wobbly::Point const positionsOrigin (priv->TargetPosition ()); - wobbly::Point const targetsOrigin = [&targets]() { - wobbly::Point target; - wgd::assign (target, wobbly::PointView (targets, 0)); + animation::Point const positionsOrigin (priv->TargetPosition ()); + animation::Point const targetsOrigin = [&targets]() { + animation::Point target; + agd::assign (target, animation::PointView (targets, 0)); return target; } (); auto const rescale = [&scaleFactor](Point const &origin, PointView &&p) { - wgd::pointwise_subtract (p, origin); - wgd::pointwise_scale (p, scaleFactor); - wgd::pointwise_add (p, origin); + agd::pointwise_subtract (p, origin); + agd::pointwise_scale (p, scaleFactor); + agd::pointwise_add (p, origin); }; /* Rescale all points and targets */ @@ -1039,33 +1038,33 @@ wobbly::ConstrainmentStep::operator () (MeshArray &points, for (size_t i = 0; i < config::TotalIndices; ++i) { - wobbly::PointView target (targets, i); + animation::PointView target (targets, i); /* In each position in the main position array we'll work out the * pythagorean delta between the ideal positon and current one. * If it is outside the maximum range, then we'll shrink the delta * and reapply it */ double const maximumRange = threshold; - wobbly::PointView point (points, i); - double range = wgd::distance (target, point); + animation::PointView point (points, i); + double range = agd::distance (target, point); if (range < maximumRange) continue; ret |= true; - auto sin = (wgd::get <1> (target) - wgd::get <1> (point)) / range; - auto cos = (wgd::get <0> (target) - wgd::get <0> (point)) / range; + auto sin = (agd::get <1> (target) - agd::get <1> (point)) / range; + auto cos = (agd::get <0> (target) - agd::get <0> (point)) / range; /* Now we want to vectorize range and * find our new x and y offsets */ double const newRange = std::min (maximumRange, range); - wobbly::Point newDelta (newRange * cos, - newRange * sin); + animation::Point newDelta (newRange * cos, + newRange * sin); /* Offset from the "target" position */ - wgd::assign (point, target); - wgd::pointwise_subtract (point, newDelta); + agd::assign (point, target); + agd::pointwise_subtract (point, newDelta); } return ret; @@ -1113,13 +1112,13 @@ wobbly::Model::Step (unsigned int time) return priv->mCurrentlyUnequal; } -wobbly::Point +animation::Point wobbly::Model::DeformTexcoords (Point const &normalized) const { return priv->mPositions.DeformUnitCoordsToMeshSpace (normalized); } -std::array const +std::array const wobbly::Model::Extremes () const { return priv->mPositions.Extremes (); @@ -1146,7 +1145,7 @@ wobbly::TargetMesh::Activate () noexcept (true) for (size_t i = 0; i < config::TotalIndices; ++i) { PointView pv (mPoints, i); - wgd::pointwise_add (pv, delta); + agd::pointwise_add (pv, delta); } } }; @@ -1175,7 +1174,7 @@ namespace template void PointRound (Point &point) { - wgd::for_each_coordinate (point, [](auto const &c) { + agd::for_each_coordinate (point, [](auto const &c) { return std::round (c); }); } @@ -1187,14 +1186,14 @@ namespace }; template - void SetToExtreme (wobbly::Point &p, + void SetToExtreme (animation::Point &p, Numeric x, typename NumericTraits ::Chooser xFinder, Numeric y, typename NumericTraits ::Chooser yFinder) { - wgd::set <0> (p, xFinder (wgd::get <0> (p), x)); - wgd::set <1> (p, yFinder (wgd::get <1> (p), y)); + agd::set <0> (p, xFinder (agd::get <0> (p), x)); + agd::set <1> (p, yFinder (agd::get <1> (p), y)); /* Round to next integer */ PointRound (p); @@ -1208,26 +1207,26 @@ namespace } } -std::array const +std::array const wobbly::BezierMesh::Extremes () const { double const maximum = std::numeric_limits ::max (); double const minimum = std::numeric_limits ::lowest (); - std::array extremes = + std::array extremes = { { - wobbly::Point (maximum, maximum), - wobbly::Point (minimum, maximum), - wobbly::Point (maximum, minimum), - wobbly::Point (minimum, minimum) + animation::Point (maximum, maximum), + animation::Point (minimum, maximum), + animation::Point (maximum, minimum), + animation::Point (minimum, minimum) } }; - wobbly::Point &topLeft (extremes[0]); - wobbly::Point &topRight (extremes[1]); - wobbly::Point &bottomLeft (extremes[2]); - wobbly::Point &bottomRight (extremes[3]); + animation::Point &topLeft (extremes[0]); + animation::Point &topRight (extremes[1]); + animation::Point &bottomLeft (extremes[2]); + animation::Point &bottomRight (extremes[3]); auto min = [](double lhs, double rhs) -> double { double result = std::min (lhs, rhs); @@ -1253,10 +1252,9 @@ wobbly::BezierMesh::Extremes () const return extremes; } -wobbly::PointView +animation::PointView wobbly::BezierMesh::PointForIndex (size_t x, size_t y) { - return wobbly::PointView (mPoints, - CoordIndex (x, y, - config::Width)); + return animation::PointView (mPoints, + CoordIndex (x, y, config::Width)); } diff --git a/wobbly/wobbly.h b/animation/wobbly/wobbly.h similarity index 92% rename from wobbly/wobbly.h rename to animation/wobbly/wobbly.h index 8734555..fb5a14a 100644 --- a/wobbly/wobbly.h +++ b/animation/wobbly/wobbly.h @@ -1,14 +1,14 @@ /* - * wobbly/wobbly.h + * animation/wobbly/wobbly.h * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -22,8 +22,7 @@ * Implicitly depends on: * - std::array */ -#ifndef WOBBLY_H -#define WOBBLY_H +#pragma once #include @@ -33,8 +32,8 @@ #include #include -#include -#include +#include +#include /* std::swap is explicitly specialized for numerous other types we don't care * about */ @@ -59,17 +58,17 @@ namespace wobbly { /* Import wobbly::geometry::Point types into * wobbly namespace for compatibility. */ - typedef wobbly::geometry::Point Point; - typedef wobbly::geometry::Vector Vector; + typedef animation::geometry::Point Point; + typedef animation::geometry::Vector Vector; template - using PointView = wobbly::geometry::PointView ; + using PointView = animation::geometry::PointView ; template - using PointModel = wobbly::geometry::PointModel ; + using PointModel = animation::geometry::PointModel ; template - using Box = wobbly::geometry::Box ; + using Box = animation::geometry::Box ; class Anchor { @@ -187,4 +186,3 @@ namespace wobbly std::unique_ptr priv; }; } -#endif diff --git a/wobbly/wobbly_concept_assert.h b/animation/wobbly/wobbly_concept_assert.h similarity index 84% rename from wobbly/wobbly_concept_assert.h rename to animation/wobbly/wobbly_concept_assert.h index f702538..c73e60f 100644 --- a/wobbly/wobbly_concept_assert.h +++ b/animation/wobbly/wobbly_concept_assert.h @@ -1,14 +1,14 @@ /* - * include/wobbly_concept_assert.h + * animation/wobbly/wobbly_concept_assert.h * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -22,8 +22,7 @@ * Implicitly depends on: * - boost::concept */ -#ifndef WOBBLY_CONCEPT_ASSERT_H -#define WOBBLY_CONCEPT_ASSERT_H +#pragma once /* Work around compiler warnings when using BOOST_CONCEPT_ASSERT - reimplement * BOOST_CONCEPT_ASSERT ourselves and add __attribute__ (unused) to specify @@ -36,5 +35,3 @@ #define WOBBLY_CONCEPT_ASSERT(ModelInParens) \ WOBBLY_CONCEPT_ASSERT_FN(void(*)ModelInParens) - -#endif diff --git a/wobbly/wobbly_internal.h b/animation/wobbly/wobbly_internal.h similarity index 86% rename from wobbly/wobbly_internal.h rename to animation/wobbly/wobbly_internal.h index f7864be..77d847a 100644 --- a/wobbly/wobbly_internal.h +++ b/animation/wobbly/wobbly_internal.h @@ -1,14 +1,14 @@ /* - * include/wobbly_internal.h + * animation/wobbly/wobbly_internal.h * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -25,8 +25,7 @@ * - std::function * - std::array */ -#ifndef WOBBLY_INTERNAL_H -#define WOBBLY_INTERNAL_H +#pragma once #include // for remove_if, find_if, etc #include // for array @@ -44,9 +43,9 @@ #include // for fabs #include // for size_t -#include // for PointView, PointModel, etc -#include // for assign, scale, etc -#include // for PointView, Vector, Point, etc +#include // for PointView, PointModel, etc +#include // for assign, scale, etc +#include // for PointView, Vector, Point, etc namespace wobbly { @@ -73,21 +72,21 @@ namespace wobbly namespace geometry { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; namespace detail { template inline void CoordinateOperation (P &p, F const &f) { - wobbly::geometry::dimension::for_each_coordinate (p, f); + animation::geometry::dimension::for_each_coordinate (p, f); } } template inline void ResetIfCloseToZero (Point &p, double t) { - wgd::for_each_coordinate (p, + agd::for_each_coordinate (p, [t](auto const &c) -> decltype(auto) { return std::fabs (c) < t ? 0.0 : c; }); @@ -96,7 +95,7 @@ namespace wobbly template inline void MakeAbsolute (Point &p) { - wgd::for_each_coordinate (p, + agd::for_each_coordinate (p, [](auto const &c) -> decltype(auto) { return std::fabs (c); }); @@ -106,7 +105,7 @@ namespace wobbly inline Point Absolute (Point &p) { Point ret; - wgd::assign (ret, p); + agd::assign (ret, p); MakeAbsolute (ret); return ret; } @@ -125,12 +124,12 @@ namespace wobbly namespace mesh { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; inline void - CalculatePositionArray (wobbly::Point const &initialPosition, - wobbly::MeshArray &array, - wobbly::Vector const &tileSize) + CalculatePositionArray (animation::Point const &initialPosition, + wobbly::MeshArray &array, + animation::Vector const &tileSize) { assert (array.size () == wobbly::config::ArraySize); @@ -139,17 +138,17 @@ namespace wobbly size_t const row = i / wobbly::config::Width; size_t const column = i % wobbly::config::Width; - wobbly::PointView position (array, i); - wgd::assign (position, initialPosition); - wgd::pointwise_add (position, - wobbly::Point (column * wgd::get <0> (tileSize), - row * wgd::get <1> (tileSize))); + animation::PointView position (array, i); + agd::assign (position, initialPosition); + agd::pointwise_add (position, + animation::Point (column * agd::get <0> (tileSize), + row * agd::get <1> (tileSize))); } } inline size_t - ClosestIndexToPosition (wobbly::MeshArray &points, - wobbly::Point const &pos) + ClosestIndexToPosition (wobbly::MeshArray &points, + animation::Point const &pos) { std::experimental::optional nearestIndex; double distance = std::numeric_limits ::max (); @@ -158,8 +157,8 @@ namespace wobbly for (size_t i = 0; i < wobbly::config::TotalIndices; ++i) { - wobbly::PointView view (points, i); - double objectDistance = wgd::distance (pos, view); + animation::PointView view (points, i); + double objectDistance = agd::distance (pos, view); if (objectDistance < distance) { nearestIndex = i; @@ -568,7 +567,7 @@ namespace wobbly public: typedef std::function OriginRecalcStrategy; - typedef std::function Move; + typedef std::function Move; TargetMesh (OriginRecalcStrategy const &recalc); @@ -765,12 +764,12 @@ namespace wobbly }; bool - EulerIntegrate (double time, - double friction, - double mass, - wobbly::PointView &&inposition, - wobbly::PointView &&invelocity, - wobbly::PointView &&inforce); + EulerIntegrate (double time, + double friction, + double mass, + animation::PointView &&inposition, + animation::PointView &&invelocity, + animation::PointView &&inforce); class EulerIntegration { @@ -959,22 +958,22 @@ namespace wobbly return tmp; } - void MoveBy (wobbly::Vector const &delta) + void MoveBy (animation::Vector const &delta) { for (auto &p : mPoints) - wobbly::geometry::dimension::pointwise_add (p.point, delta); + animation::geometry::dimension::pointwise_add (p.point, delta); } - void Scale (wobbly::Point const &origin, - wobbly::Vector const &scaleFactor) + void Scale (animation::Point const &origin, + animation::Vector const &scaleFactor) { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; for (auto &p : mPoints) { - wgd::pointwise_subtract (p.point, origin); - wgd::pointwise_scale (p.point, scaleFactor); - wgd::pointwise_add (p.point, origin); + agd::pointwise_subtract (p.point, origin); + agd::pointwise_scale (p.point, scaleFactor); + agd::pointwise_add (p.point, origin); } } @@ -1007,13 +1006,13 @@ namespace wobbly PosPreference const &firstPref, PosPreference const &secondPref); - void MoveInsertedAnchorsBy (wobbly::Vector const &delta) + void MoveInsertedAnchorsBy (animation::Vector const &delta) { mInserted.MoveBy (delta); } - void ScaleInsertedAnchors (wobbly::Point const &origin, - wobbly::Vector const &scaleFactor) + void ScaleInsertedAnchors (animation::Point const &origin, + animation::Vector const &scaleFactor) { mInserted.Scale (origin, scaleFactor); } @@ -1033,11 +1032,11 @@ namespace wobbly { public: - SpringStep (IntegrationStrategy &strategy, - MeshArray &array, - double const &constant, - double const &friction, - wobbly::Vector const &tileSize) : + SpringStep (IntegrationStrategy &strategy, + MeshArray &array, + double const &constant, + double const &friction, + animation::Vector const &tileSize) : constant (constant), friction (friction), integrator (strategy), @@ -1060,7 +1059,7 @@ namespace wobbly return mesh.InstallAnchorSprings (install, first, second); } - void MoveInsertedAnchorsBy (wobbly::Vector const &delta) + void MoveInsertedAnchorsBy (animation::Vector const &delta) { mesh.MoveInsertedAnchorsBy (delta); } @@ -1100,46 +1099,46 @@ namespace wobbly double mass, double time) { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; - wobbly::Vector acceleration; - wgd::assign (acceleration, force); - wgd::scale (acceleration, 1.0 / mass); + animation::Vector acceleration; + agd::assign (acceleration, force); + agd::scale (acceleration, 1.0 / mass); /* v[t] = v[t - 1] + at */ - wobbly::Vector additionalVelocity (acceleration); - wgd::scale (additionalVelocity, time); - wgd::pointwise_add (velocity, additionalVelocity); + animation::Vector additionalVelocity (acceleration); + agd::scale (additionalVelocity, time); + agd::pointwise_add (velocity, additionalVelocity); } } } inline bool -wobbly::EulerIntegrate (double time, - double friction, - double mass, - wobbly::PointView &&inposition, - wobbly::PointView &&invelocity, - wobbly::PointView &&inforce) +wobbly::EulerIntegrate (double time, + double friction, + double mass, + animation::PointView &&inposition, + animation::PointView &&invelocity, + animation::PointView &&inforce) { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; assert (mass > 0.0f); - wobbly::PointView position (std::move (inposition)); - wobbly::PointView force (std::move (inforce)); - wobbly::PointView velocity (std::move (invelocity)); + animation::PointView position (std::move (inposition)); + animation::PointView force (std::move (inforce)); + animation::PointView velocity (std::move (invelocity)); /* Apply friction, which is exponentially * proportional to both velocity and time */ - wobbly::Vector totalForce; - wgd::assign (totalForce, force); + animation::Vector totalForce; + agd::assign (totalForce, force); - wobbly::Vector frictionForce; - wgd::pointwise_add (frictionForce, velocity); - wgd::scale (frictionForce, friction); + animation::Vector frictionForce; + agd::pointwise_add (frictionForce, velocity); + agd::scale (frictionForce, friction); - wgd::pointwise_subtract (totalForce, frictionForce); + agd::pointwise_subtract (totalForce, frictionForce); /* First apply velocity change for force * exerted over time */ @@ -1152,15 +1151,15 @@ wobbly::EulerIntegrate (double time, * * d[t] = ((v[t - 1] + v[t]) / 2) * t */ - wobbly::Vector positionDelta; - wgd::assign (positionDelta, velocity); - wgd::scale (positionDelta, time / 2); + animation::Vector positionDelta; + agd::assign (positionDelta, velocity); + agd::scale (positionDelta, time / 2); - wgd::pointwise_add (position, positionDelta); + agd::pointwise_add (position, positionDelta); /* Return true if we still have velocity remaining */ - bool result = std::fabs (wgd::get <0> (velocity)) > 0.00 || - std::fabs (wgd::get <1> (velocity)) > 0.00; + bool result = std::fabs (agd::get <0> (velocity)) > 0.00 || + std::fabs (agd::get <1> (velocity)) > 0.00; return result; } @@ -1185,8 +1184,8 @@ wobbly::EulerIntegration::Step (size_t index, inline void wobbly::EulerIntegration::Reset (size_t index) { - wobbly::PointView velocity (velocities, index); - wobbly::geometry::dimension::assign_value (velocity, 0.0); + animation::PointView velocity (velocities, index); + animation::geometry::dimension::assign_value (velocity, 0.0); } namespace wobbly @@ -1194,19 +1193,19 @@ namespace wobbly namespace springs { template - inline wobbly::Vector - DeltaFromDesired (P1 const &a, - P2 const &b, - wobbly::Vector const &desired) + inline animation::Vector + DeltaFromDesired (P1 const &a, + P2 const &b, + animation::Vector const &desired) { - namespace wgd = wobbly::geometry::dimension; - - wobbly::Vector delta (0.5 * (wgd::get <0> (b) - - wgd::get <0> (a) + - wgd::get <0> (desired)), - 0.5 * (wgd::get <1> (b) - - wgd::get <1> (a) + - wgd::get <1> (desired))); + namespace agd = animation::geometry::dimension; + + animation::Vector delta (0.5 * (agd::get <0> (b) - + agd::get <0> (a) + + agd::get <0> (desired)), + 0.5 * (agd::get <1> (b) - + agd::get <1> (a) + + agd::get <1> (desired))); return delta; } } @@ -1215,10 +1214,10 @@ namespace wobbly inline bool wobbly::Spring::ApplyForces (double springConstant) const { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; Vector desiredNegative (desiredDistance); - wgd::scale (desiredNegative, -1); + agd::scale (desiredNegative, -1); Vector deltaA (springs::DeltaFromDesired (posA, posB, @@ -1233,18 +1232,18 @@ wobbly::Spring::ApplyForces (double springConstant) const Vector springForceA (deltaA); Vector springForceB (deltaB); - wgd::scale (springForceA, springConstant); - wgd::scale (springForceB, springConstant); + agd::scale (springForceA, springConstant); + agd::scale (springForceB, springConstant); - wgd::pointwise_add (forceA, springForceA); - wgd::pointwise_add (forceB, springForceB); + agd::pointwise_add (forceA, springForceA); + agd::pointwise_add (forceB, springForceB); /* Return true if a delta was applied at any point */ Vector delta (geometry::Absolute (deltaA)); - wgd::pointwise_add (delta, geometry::Absolute (deltaB)); + agd::pointwise_add (delta, geometry::Absolute (deltaB)); - bool result = wgd::get <0> (delta) > 0.00 || - wgd::get <1> (delta) > 0.00; + bool result = agd::get <0> (delta) > 0.00 || + agd::get <1> (delta) > 0.00; return result; } @@ -1269,13 +1268,13 @@ wobbly::SpringMesh::CalculateForces (double springConstant) const }; } -inline wobbly::Point +inline animation::Point wobbly::BezierMesh::DeformUnitCoordsToMeshSpace (Point const &normalized) const { - namespace wgd = ::wobbly::geometry::dimension; + namespace agd = ::animation::geometry::dimension; - double const u = wgd::get <0> (normalized); - double const v = wgd::get <1> (normalized); + double const u = agd::get <0> (normalized); + double const v = agd::get <1> (normalized); /* Create a vector of coefficients like * | (1 - u)^3 | @@ -1333,5 +1332,3 @@ wobbly::BezierMesh::DeformUnitCoordsToMeshSpace (Point const &normalized) const Point absolutePosition (x, y); return absolutePosition; } - -#endif diff --git a/debian/changelog b/debian/changelog index 5f4856f..70d18bd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,55 +1,6 @@ -libwobbly (0.3.2) eos; urgency=medium +libanimation (0.0.0) eos; urgency=medium - * debian/control: - - Rename gir1.2-wobbly-glib0 to gir1.2-wobbly-glib-0.3 - * libwobbly-dev: - - Install the unversioned library - * libwobbly0: - - Install the soversioned library - * libwobbly-glib-dev - - Install the unversioned library - * libwobbly-glib0: - - Install the so versioned library - - -- Sam Spilsbury Tue, 10 Jul 2018 23:30:51 +0800 - -libwobbly (0.3.1) eos; urgency=medium - - * wobbly-glib: Add wobbly-glib library * debian/control - - Add packaging for wobbly-glib0, wobbly-glib-dev, gir1.2-wobbly-glib - - -- Sam Spilsbury Sat, 07 Jul 2018 02:26:53 +0800 - -libwobbly (0.3.0) eos; urgency=medium - - * build: Port to Meson - * wobbly: Remove dependency on boost - * debian/control: - - Remove dependency on boost - - -- Sam Spilsbury Wed, 04 Jul 2018 08:24:25 +0800 - -libwobbly (0.2.1) eos; urgency=medium - - * cmake: Add SOVERSION to library (credit: Robert McQueen) - - -- Sam Spilsbury Wed, 14 Jun 2017 03:08:29 +0800 - -libwobbly (0.2) eos; urgency=medium - - * Update cmake modules, move to 3.0(native) - - -- Sam Spilsbury Thu, 04 Aug 2016 13:45:24 +0800 - -libwobbly (0.1-1endless1) unstable; urgency=low - - * Fixed distortion on maximize - - -- Sam Spilsbury Wed, 15 Oct 2014 04:14:11 +0800 - -libwobbly (0.1-1) unstable; urgency=low - - * Initial release + - Rename package to libanimation, add transitional rules - -- Sam Spilsbury Tue, 04 Feb 2014 10:02:19 -0200 + -- Sam Spilsbury Thu, 09 Aug 2018 02:26:53 +0800 diff --git a/debian/control b/debian/control index 43df27d..f862686 100644 --- a/debian/control +++ b/debian/control @@ -1,4 +1,4 @@ -Source: libwobbly +Source: libanimation Priority: extra Maintainer: Sam Spilsbury Build-Depends: debhelper (>= 8.0.0), @@ -13,47 +13,50 @@ Build-Depends: debhelper (>= 8.0.0), meson Standards-Version: 3.9.4 Section: libs -Vcs-Git: git://github.com/smspillaz/libwobbly.git +Vcs-Git: git://github.com/endless/libanimation.git -Package: libwobbly-dev +Package: libanimation-dev Section: libdevel Architecture: any -Depends: libwobbly0 (= ${binary:Version}), -Description: Wobbly Mesh Library (C++ API) headers - Wobbly Mesh (C++ API) headers +Depends: libanimation0 (= ${binary:Version}), +Description: 2D Surfaces Animations (C++ API) headers + 2D Surfaces Animations (C++ API) headers +Replaces: libwobbly-dev (<= 0.3.2) -Package: libwobbly0 +Package: libanimation0 Section: libs Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} -Description: Wobbly Mesh library (C++ API) - Wobbly Mesh +Description: 2D Surfaces Animations library (C++ API) + 2D Surfaces Animations library +Replaces: libwobbly0 (<= 0.3.2) -Package: libwobbly-glib0 +Package: libanimation-glib0 Section: libs Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, - libwobbly0 (= ${binary:Version}) -Description: Wobbly Mesh library (GLib API) - Wobbly Mesh (GLib API) + libanimation0 (= ${binary:Version}) +Description: 2D Surfaces Animations library (GLib API) + 2D Surfaces Animations library +Replaces: libwobbly-glib0 (<= 0.3.2) -Package: libwobbly-glib-dev -Section: libdevel +Package: libanimation-glib-dev +Section: libs Architecture: any -Depends: ${misc:Depends}, - libwobbly-glib0 (= ${binary:Version}), - gir1.2-libwobbly-glib-0.3 (= ${binary:Version}) -Description: Wobbly Mesh library (GLib API) headers - Wobbly Mesh library (GLib API) headers +Depends: libanimation0 (= ${binary:Version}), +Description: 2D Surfaces Animations (GLib API) headers + 2D Surfaces Animations (GLib API) headers +Replaces: libwobbly-glib-dev (<= 0.3.2) -Package: gir1.2-libwobbly-glib-0.3 -Section: libs +Package: gir1.2-libanimation-glib0 +Section: non-free/libs Architecture: any Depends: ${gir:Depends}, ${misc:Depends}, ${shlibs:Depends}, - libwobbly-glib0 (= ${binary:Version}) -Description: Wobbly Mesh library (GObject Introspection) files - Wobbly Mesh library (GObject Introspection) files + libanimation-glib0 (= ${binary:Version}) +Description: 2D Surfaces Animations library (GObject Introspection) files + 2D Surfaces Animations library (GObject Introspection) files +Replaces: gir1.2-libwobbly-glib0 (<= 0.3.2) diff --git a/debian/gir1.2-libanimation-glib0.install b/debian/gir1.2-libanimation-glib0.install new file mode 100644 index 0000000..5826909 --- /dev/null +++ b/debian/gir1.2-libanimation-glib0.install @@ -0,0 +1 @@ +usr/lib/*/girepository-1.0/Animation-0.typelib diff --git a/debian/gir1.2-libwobbly-glib-0.3.install b/debian/gir1.2-libwobbly-glib-0.3.install deleted file mode 100644 index 41ed301..0000000 --- a/debian/gir1.2-libwobbly-glib-0.3.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/*/girepository-1.0/Wobbly-0.3.typelib diff --git a/debian/libwobbly-dev.dirs b/debian/libanimation-dev.dirs similarity index 100% rename from debian/libwobbly-dev.dirs rename to debian/libanimation-dev.dirs diff --git a/debian/libanimation-dev.install b/debian/libanimation-dev.install new file mode 100644 index 0000000..9c6de95 --- /dev/null +++ b/debian/libanimation-dev.install @@ -0,0 +1,3 @@ +usr/include/animation/* +usr/lib/*/libanimation.so +usr/lib/*/pkgconfig/libanimation-0.pc diff --git a/debian/libanimation-glib-dev.install b/debian/libanimation-glib-dev.install new file mode 100644 index 0000000..2899266 --- /dev/null +++ b/debian/libanimation-glib-dev.install @@ -0,0 +1,4 @@ +usr/include/animation-glib/* +usr/lib/*/libanimation-glib.so +usr/lib/*/pkgconfig/libanimation-glib-0.pc +usr/share/gir-1.0/Animation-0.gir diff --git a/debian/libanimation-glib0.install b/debian/libanimation-glib0.install new file mode 100644 index 0000000..00446ae --- /dev/null +++ b/debian/libanimation-glib0.install @@ -0,0 +1 @@ +usr/lib/*/libanimation-glib.so.0 diff --git a/debian/libwobbly0.dirs b/debian/libanimation0.dirs similarity index 100% rename from debian/libwobbly0.dirs rename to debian/libanimation0.dirs diff --git a/debian/libanimation0.install b/debian/libanimation0.install new file mode 100644 index 0000000..ab6e3df --- /dev/null +++ b/debian/libanimation0.install @@ -0,0 +1 @@ +usr/lib/*/libanimation.so.0 diff --git a/debian/libwobbly-dev.install b/debian/libwobbly-dev.install deleted file mode 100644 index 4a2064d..0000000 --- a/debian/libwobbly-dev.install +++ /dev/null @@ -1,3 +0,0 @@ -usr/include/wobbly/* -usr/lib/*/libwindowfx_wobbly.so -usr/lib/*/pkgconfig/libwindowfx_wobbly-0.3.pc diff --git a/debian/libwobbly-glib-dev.install b/debian/libwobbly-glib-dev.install deleted file mode 100644 index 1abafc7..0000000 --- a/debian/libwobbly-glib-dev.install +++ /dev/null @@ -1,4 +0,0 @@ -usr/include/wobbly-glib/* -usr/lib/*/libwindowfx_wobbly_glib.so -usr/lib/*/pkgconfig/libwindowfx_wobbly_glib-0.3.pc -usr/share/gir-1.0/Wobbly-0.3.gir diff --git a/debian/libwobbly-glib0.install b/debian/libwobbly-glib0.install deleted file mode 100644 index c3aa1fd..0000000 --- a/debian/libwobbly-glib0.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/*/libwindowfx_wobbly_glib.so.0.3 diff --git a/debian/libwobbly0.install b/debian/libwobbly0.install deleted file mode 100644 index 4fd14f2..0000000 --- a/debian/libwobbly0.install +++ /dev/null @@ -1 +0,0 @@ -usr/lib/*/libwindowfx_wobbly.so.0.3 diff --git a/matchers/mathematical_model_matcher.cpp b/matchers/mathematical_model_matcher.cpp index bc94ac5..761c519 100644 --- a/matchers/mathematical_model_matcher.cpp +++ b/matchers/mathematical_model_matcher.cpp @@ -3,12 +3,12 @@ * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. diff --git a/matchers/mathematical_model_matcher.h b/matchers/mathematical_model_matcher.h index cc71e87..f3f74e1 100644 --- a/matchers/mathematical_model_matcher.h +++ b/matchers/mathematical_model_matcher.h @@ -3,12 +3,12 @@ * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -29,8 +29,7 @@ * - std::function * - std::vector */ -#ifndef WOBBLY_MATHEMATICAL_MODEL_MATCHER_H -#define WOBBLY_MATHEMATICAL_MODEL_MATCHER_H +#pragma once #include // for assert #include // for log, pow, M_E @@ -43,11 +42,11 @@ #include // for enable_if, is_same #include // for vector -#include +#include #include // IWYU pragma: keep -namespace wobbly +namespace animation { namespace models { @@ -78,7 +77,7 @@ namespace wobbly typedef std::unique_ptr Unique; - typedef wobbly::PointModel Point; + typedef animation::PointModel Point; typedef std::function Generator; typedef std::function Factory; @@ -91,7 +90,7 @@ namespace wobbly namespace exponential { - namespace wgd = ::wobbly::geometry::dimension; + namespace agd = ::animation::geometry::dimension; /* Given a function which generates values from x = 0 -> y = c * two data points on that line, and the value c, @@ -120,8 +119,8 @@ namespace wobbly SolveForECoeff (typename DataModel ::Point const &xZeroPoint, N constant) { - N x = wgd::get <0> (xZeroPoint); - N y = wgd::get <1> (xZeroPoint); + N x = agd::get <0> (xZeroPoint); + N y = agd::get <1> (xZeroPoint); assert (x == 0.0); @@ -444,7 +443,7 @@ namespace wobbly namespace matchers { namespace t = ::testing; - namespace wgd = ::wobbly::geometry::dimension; + namespace agd = ::animation::geometry::dimension; template class GeometricallyEqualMatcher : @@ -479,20 +478,20 @@ namespace wobbly RHS const &rhs) { const float epsilon = 10e-7; - typedef typename wgd::Dimension ::data_type LT; + typedef typename agd::Dimension ::data_type LT; bool result = false; /* If we are comparing to zero, then use * check_is_small as opposed to check_is_close */ - if (wgd::get (rhs) == 0.0) - result = wobbly::testing::is_small (wgd::get (lhs), - epsilon); + if (agd::get (rhs) == 0.0) + result = animation::testing::is_small (agd::get (lhs), + epsilon); else { - result = wobbly::testing::close_at_tolerance (wgd::get (lhs), - wgd::get (rhs), - epsilon); + result = animation::testing::close_at_tolerance (agd::get (lhs), + agd::get (rhs), + epsilon); } return result && @@ -512,7 +511,7 @@ namespace wobbly template static inline bool compare (LHS const &lhs, RHS const &rhs) { - typedef wgd::Dimension DimLHS; + typedef agd::Dimension DimLHS; typedef Equal Comparator; return Comparator::apply (lhs, rhs); @@ -521,7 +520,7 @@ namespace wobbly Compare geometry; }; - /* We want to be able to pass any compatible wobbly::dimension to this + /* We want to be able to pass any compatible animation::dimension to this * matcher so it needs to be a template class with a template * conversion operator to Matcher (eg, to signify that it is * T that is being matched, but Geometry that is being compared) */ @@ -579,7 +578,7 @@ namespace wobbly struct Geo { static constexpr bool value = - !(std::is_same ::data_type, void>::value); + !(std::is_same ::data_type, void>::value); }; template @@ -710,9 +709,9 @@ namespace wobbly << std::endl; /* Close to specified tolerance */ - if (!wobbly::testing::close_at_tolerance (modelPrediction, - actual, - mTolerance)) + if (!animation::testing::close_at_tolerance (modelPrediction, + actual, + mTolerance)) { if (os) *os << " (exceeding tolerance: " @@ -811,6 +810,3 @@ namespace wobbly } } } - - -#endif diff --git a/matchers/meson.build b/matchers/meson.build index 6fc7f9f..c56e09a 100644 --- a/matchers/meson.build +++ b/matchers/meson.build @@ -31,7 +31,7 @@ mathematical_model_matcher_lib = static_library( dependencies: [ gtest_dep, gmock_dep, - wobbly_dep + animation_dep ], install: false ) @@ -52,7 +52,7 @@ within_geometry_matcher_lib = static_library( dependencies: [ gtest_dep, gmock_dep, - wobbly_dep + animation_dep ], install: false ) diff --git a/matchers/within_geometry_matcher.cpp b/matchers/within_geometry_matcher.cpp index 8e1e8d2..fa42490 100644 --- a/matchers/within_geometry_matcher.cpp +++ b/matchers/within_geometry_matcher.cpp @@ -3,12 +3,12 @@ * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. diff --git a/matchers/within_geometry_matcher.h b/matchers/within_geometry_matcher.h index f1a94d1..4b2e6cc 100644 --- a/matchers/within_geometry_matcher.h +++ b/matchers/within_geometry_matcher.h @@ -3,12 +3,12 @@ * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -21,23 +21,21 @@ * Dimension trait to ensure they are within * a PointBox. */ - -#ifndef WOBBLY_WITHIN_GEOMETRY_MATCHER_H -#define WOBBLY_WITHIN_GEOMETRY_MATCHER_H +#pragma once #include // for operator<<, setprecision #include // for ostream, operator<<, etc -#include +#include #include // IWYU pragma: keep -namespace wobbly +namespace animation { namespace matchers { namespace t = ::testing; - namespace wgd = ::wobbly::geometry::dimension; + namespace agd = ::animation::geometry::dimension; template class WithinGeometryMatcher @@ -73,7 +71,7 @@ namespace wobbly void Describe (std::ostream &os) const { os << " within :" << std::endl; - wgd::for_each_point (parent, [&os](auto const &p) { + agd::for_each_point (parent, [&os](auto const &p) { os << " - " << p << std::endl; }); } @@ -90,5 +88,3 @@ namespace wobbly } } } - -#endif diff --git a/meson.build b/meson.build index a2a29c1..aeb4227 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,25 @@ # /meson.build # -# Toplevel meson build file for libwobbly. +# Toplevel meson build file for libanimation. # -# See /LICENCE.md for Copyright information. +# Copyright (C) 2017, 2018 Endless Mobile, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -project('libwobbly', 'cpp', - version: '0.3.2', +project('libanimation', 'cpp', + version: '0.0.0', default_options : ['cpp_std=c++17'], license: 'LGPL2+', meson_version: '>= 0.40.0') @@ -21,9 +35,10 @@ if not gtest_dep.found() or not gtest_main_dep.found() or not gmock_dep.found() gmock_dep = gtest_project.get_variable('gmock_dep') endif -wobbly_inc = include_directories('.') +animation_inc = include_directories('.') +tests_inc = include_directories('tests') -subdir('wobbly') -subdir('wobbly-glib') +subdir('animation') +subdir('animation-glib') subdir('matchers') subdir('tests') diff --git a/tests/glib_api_test.cpp b/tests/glib_api_test.cpp deleted file mode 100644 index 277c133..0000000 --- a/tests/glib_api_test.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/* - * tests/glib_api_test.cpp - * - * Copyright 2018 Endless Mobile, Inc. - * - * libwobbly is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * libwobbly is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with eos-companion-app-service. If not, see - * . - * - * Tests for the "wobbly" spring model, GObject API. - */ - -#include // for operator<<, setprecision -#include // for ostream -#include // for basic_ostream, char_traits, etc - -#include -#include -#include - -#include // for Eq, EqDispatchHelper, etc -#include // for operator<<, etc -#include // for WithinGeometry, etc - -#include // for AtLeast -#include // for FunctionMocker, etc -#include // for AnythingMatcher, etc -#include // for EXPECT_CALL, etc -#include // for TEST_F, Test, Types, etc - -using ::testing::ElementsAreArray; -using ::testing::Eq; -using ::testing::Matcher; -using ::testing::Not; -using ::testing::Test; - -using ::wobbly::matchers::WithinGeometry; - -bool operator== (WobblyVector const &lhs, - WobblyVector const &rhs) -{ - return lhs.x == rhs.x && lhs.y == rhs.y; -} - -inline std::ostream & -operator<< (std::ostream &lhs, WobblyVector const &v) -{ - return lhs << std::setprecision (10) - << "x: " - << v.x - << " y: " - << v.y; -} - -namespace wobbly -{ - namespace geometry - { - namespace dimension - { - template <> - struct Dimension - { - typedef double data_type; - static const size_t dimensions = 2; - }; - - template <> - struct DimensionAccess - { - static inline double get (WobblyVector const &p) - { - return p.x; - } - - static inline void - set (WobblyVector &p, double const &value) - { - p.x = value; - } - }; - - template <> - struct DimensionAccess - { - static inline double get (WobblyVector const &p) - { - return p.y; - } - - static inline void - set (WobblyVector &p, double const &value) - { - p.y = value; - } - }; - } - } -} - -namespace -{ - namespace detail - { - template - struct ArrayMapInto - { - static void apply (std::array &dst, - std::array const &src, - Visitor &&visitor) - { - dst[I] = visitor (src[I]); - ArrayMapInto ::apply (dst, - src, - std::forward (visitor)); - } - }; - - template - struct ArrayMapInto - { - static void apply (std::array &dst, - std::array const &src, - Visitor &&visitor) - { - dst[0] = visitor (src[0]); - } - }; - } - - template - void array_map_into (std::array &dst, - std::array const &src, - Visitor &&visitor) - { - detail::ArrayMapInto ::apply (dst, - src, - std::forward (visitor)); - } - - typedef wobbly::Box PointBox; - - TEST (WobblyGLibAPI, ConstructModel) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - } - - TEST (WobblyGLibAPI, MoveModelChangesExtremes) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - - std::array extremes; - - wobbly_model_move_to (model, { 1.0, 1.0 }); - wobbly_model_query_extremes (model, - &extremes[0], - &extremes[1], - &extremes[2], - &extremes[3]); - - std::array expected = { - { - { 1.0, 1.0 }, - { 101.0, 1.0 }, - { 1.0, 101.0 }, - { 101.0, 101.0 } - } - }; - std::array , 4> textureEdges; - array_map_into (textureEdges, - expected, - [](auto const &vector) -> decltype(auto) { - return Eq (vector); - }); - - EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); - } - - TEST (WobblyGLibAPI, ResizeModelChangesExtremes) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - - std::array extremes; - - wobbly_model_resize (model, { 200.0, 200.0 }); - wobbly_model_query_extremes (model, - &extremes[0], - &extremes[1], - &extremes[2], - &extremes[3]); - - std::array expected = { - { - { 0.0, 0.0 }, - { 200.0, 0.0 }, - { 0.0, 200.0 }, - { 200.0, 200.0 } - } - }; - std::array , 4> textureEdges; - array_map_into (textureEdges, - expected, - [](auto const &vector) -> decltype(auto) { - return Eq (vector); - }); - - EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); - } - - TEST (WobblyGLibAPI, GrabCorrectIndex) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - g_autoptr(WobblyAnchor) anchor = wobbly_model_grab_anchor (model, { 100.0, 0.0 }); - - wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); - - WobblyVector topRightExtreme; - WobblyVector expectedTopRightExtreme = { 110.0, 0.0 }; - - wobbly_model_query_extremes (model, - nullptr, - &topRightExtreme, - nullptr, - nullptr); - - EXPECT_THAT (topRightExtreme, Eq (expectedTopRightExtreme)); - } - - TEST (WobblyGLibAPI, ModelSettlesAfterMovingAnchor) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - g_autoptr(WobblyAnchor) anchor = wobbly_model_grab_anchor (model, { 100.0, 0.0 }); - - /* Move anchor and settle */ - wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); - while (wobbly_model_step (model, 1)); - - std::array extremes; - wobbly_model_query_extremes (model, - &extremes[0], - &extremes[1], - &extremes[2], - &extremes[3]); - - std::array expected = { - { - { 10.0, 10.0 }, - { 110.0, 10.0 }, - { 10.0, 110.0 }, - { 110.0, 110.0 } - } - }; - std::array , 4> textureEdges; - array_map_into (textureEdges, - expected, - [](auto const &vector) -> decltype(auto) { - return Eq (vector); - }); - - EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); - } - - TEST (WobblyGLibAPI, DeformedWithGrabbedAnchor) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - g_autoptr(WobblyAnchor) anchor = wobbly_model_grab_anchor (model, { 100.0, 0.0 }); - WobblyVector deformed; - WobblyVector center = { 50.0, 50.0 }; - - wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); - wobbly_model_deform_texcoords (model, { 0.5, 0.5 }, &deformed); - - EXPECT_THAT (deformed, Not (Eq (center))); - } - - TEST (WobblyGLibAPI, DeformedWithInsertAnchor) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - g_autoptr(WobblyAnchor) anchor = wobbly_model_insert_anchor (model, { 70.0, 0.0 }); - WobblyVector deformed; - WobblyVector center = { 50.0, 50.0 }; - - wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); - wobbly_model_step (model, 1); - wobbly_model_deform_texcoords (model, { 0.5, 0.5 }, &deformed); - - EXPECT_THAT (deformed, Not (Eq (center))); - } - - TEST (WobblyGLibAPI, NoDeformationNoAnchorMove) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - g_autoptr(WobblyAnchor) anchor = wobbly_model_grab_anchor (model, { 100.0, 0.0 }); - WobblyVector deformed; - WobblyVector center = { 50.0, 50.0 }; - - wobbly_model_deform_texcoords (model, { 0.5, 0.5 }, &deformed); - - EXPECT_THAT (deformed, Eq (center)); - } - - TEST (WobblyGLibAPI, ReleaseAnchorOnModel) - { - g_autoptr(WobblyModel) model = wobbly_model_new ({ 0.0, 0.0 }, - { 100.0, 100.0 }, - 8.0, - 5.0, - 500.0); - g_autoptr(WobblyAnchor) anchor = wobbly_model_grab_anchor (model, { 100.0, 0.0 }); - - /* Temporarily grab another anchor and move the first one */ - { - g_autoptr(WobblyAnchor) otherAnchor = wobbly_model_grab_anchor (model, { 0.0, 0.0 }); - wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); - } - - /* Anchor is now released. Settle model */ - while (wobbly_model_step (model, 1)); - - std::array extremes; - wobbly_model_query_extremes (model, - &extremes[0], - &extremes[1], - &extremes[2], - &extremes[3]); - - std::array expected = { - { - { 10.0, 10.0 }, - { 110.0, 10.0 }, - { 10.0, 110.0 }, - { 110.0, 110.0 } - } - }; - std::array , 4> textureEdges; - array_map_into (textureEdges, - expected, - [](auto const &vector) -> decltype(auto) { - return WithinGeometry (PointBox (wobbly::Point (vector.x - 3.0, - vector.y - 3.0), - wobbly::Point (vector.x + 3.0, - vector.y + 3.0))); - }); - - EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); - } -} diff --git a/tests/meson.build b/tests/meson.build index 9127510..9d59aa9 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -16,26 +16,26 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # -# Build the libwobbly unit tests. +# Build the libanimation unit tests. -wobbly_test_sources = [ - 'anchor_test.cpp', - 'constrainment_test.cpp', - 'euler_integration_test.cpp', - 'glib_api_test.cpp', - 'mesh_interpolation_test.cpp', - 'model_test.cpp', +animation_test_sources = [ 'ostream_point_operator.h', - 'point_test.cpp', - 'spring_test.cpp' + 'wobbly/anchor_test.cpp', + 'wobbly/constrainment_test.cpp', + 'wobbly/euler_integration_test.cpp', + 'wobbly/glib_api_test.cpp', + 'wobbly/mesh_interpolation_test.cpp', + 'wobbly/model_test.cpp', + 'wobbly/point_test.cpp', + 'wobbly/spring_test.cpp' ] glib = dependency('glib-2.0') gobject = dependency('gobject-2.0') -wobbly_test_executable = executable( - 'windowfx_wobbly_test', - wobbly_test_sources, +animation_test_executable = executable( + 'animation_test', + animation_test_sources, dependencies: [ gtest_dep, gtest_main_dep, @@ -44,9 +44,10 @@ wobbly_test_executable = executable( gobject, mathematical_model_matcher_dep, within_geometry_matcher_dep, - wobbly_dep, - wobbly_glib_dep - ] + animation_dep, + animation_glib_dep + ], + include_directories: [ tests_inc ] ) -test('windowfx_wobbly_test', wobbly_test_executable) +test('animation_test', animation_test_executable) diff --git a/tests/ostream_point_operator.h b/tests/ostream_point_operator.h index 006f1ca..a2cac5b 100644 --- a/tests/ostream_point_operator.h +++ b/tests/ostream_point_operator.h @@ -3,12 +3,12 @@ * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -17,44 +17,42 @@ * License along with eos-companion-app-service. If not, see * . * - * A simple helper to output the contents of wobbly::Point and - * wobbly::PointView when tests fail. + * A simple helper to output the contents of animation::Point and + * animation::PointView when tests fail. */ -#ifndef WOBBLY_TESTS_OSTREAM_POINT_OPERATOR_H -#define WOBBLY_TESTS_OSTREAM_POINT_OPERATOR_H +#pragma once -#include // for Point +#include // for Point #include // for operator<<, setprecision #include // for ostream #include // for basic_ostream, char_traits, etc -namespace wobbly +namespace animation { namespace geometry { inline std::ostream & operator<< (std::ostream &lhs, Point const &p) { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; return lhs << std::setprecision (10) << "x: " - << wgd::get <0> (p) + << agd::get <0> (p) << " y: " - << wgd::get <1> (p); + << agd::get <1> (p); } template inline std::ostream & operator<< (std::ostream &lhs, - wobbly::geometry::PointView const &p) + animation::geometry::PointView const &p) { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; Point point; - wgd::assign (point, p); + agd::assign (point, p); return lhs << point; } } } -#endif diff --git a/tests/anchor_test.cpp b/tests/wobbly/anchor_test.cpp similarity index 93% rename from tests/anchor_test.cpp rename to tests/wobbly/anchor_test.cpp index 414989c..8e80da7 100644 --- a/tests/anchor_test.cpp +++ b/tests/wobbly/anchor_test.cpp @@ -1,14 +1,14 @@ /* - * tests/wobbly_test.cpp + * tests/wobbly/anchor_test.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -28,7 +28,7 @@ #include // for EXPECT_CALL, etc #include // for TEST_F, Test, Types, etc -#include // for TrackedAnchors +#include // for TrackedAnchors using ::testing::_; using ::testing::AtLeast; diff --git a/tests/constrainment_test.cpp b/tests/wobbly/constrainment_test.cpp similarity index 72% rename from tests/constrainment_test.cpp rename to tests/wobbly/constrainment_test.cpp index bf84812..e79d471 100644 --- a/tests/constrainment_test.cpp +++ b/tests/wobbly/constrainment_test.cpp @@ -1,14 +1,14 @@ /* - * tests/wobbly_test.cpp + * tests/wobbly/constrainment_test.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -32,8 +32,8 @@ #include // for Values, Combine, ValuesIn, etc #include // for AssertHelper, TEST_F, etc -#include // for Point, PointView -#include // for TargetMesh, etc +#include // for Point, PointView +#include // for TargetMesh, etc #include // for EqDispatchHelper, Eq, etc #include // for operator<< @@ -45,11 +45,11 @@ using ::testing::Test; using ::testing::ValuesIn; using ::testing::WithParamInterface; -using ::wobbly::matchers::Eq; +using ::animation::matchers::Eq; namespace { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; double TileWidth (double width) { @@ -75,19 +75,19 @@ namespace { for (unsigned int j = 0; j < meshWidth; ++j) { - wobbly::PointView pv (positions, - i * meshWidth + j); - wgd::assign (pv, - wobbly::Point (tileWidth * j, - tileHeight * i)); + animation::PointView pv (positions, + i * meshWidth + j); + agd::assign (pv, + animation::Point (tileWidth * j, + tileHeight * i)); } } } constexpr double TextureWidth = 50.0f; constexpr double TextureHeight = 100.0f; - wobbly::Point const TextureCenter = wobbly::Point (TextureWidth / 2, - TextureHeight / 2); + animation::Point const TextureCenter = animation::Point (TextureWidth / 2, + TextureHeight / 2); class ConstrainmentStep : public Test @@ -138,8 +138,8 @@ namespace TEST_F (ConstrainmentStep, ReturnsTrueWhereConstrainmentTookPlace) { auto handleOwner (targets.Activate ()); - wobbly::PointView pv (positions, 1); - wgd::pointwise_add (pv, wobbly::Point (range * 2, range * 2)); + animation::PointView pv (positions, 1); + agd::pointwise_add (pv, animation::Point (range * 2, range * 2)); EXPECT_TRUE (constrainment (positions, anchors)); } @@ -147,17 +147,17 @@ namespace TEST_F (ConstrainmentStep, ReturnsFalseWhereNoConstrainmentTookPlace) { auto handleOwner (targets.Activate ()); - wobbly::PointView pv (positions, 1); + animation::PointView pv (positions, 1); /* Not enough to cause constrainment */ - wgd::pointwise_add (pv, wobbly::Point (range / 2, 0)); + agd::pointwise_add (pv, animation::Point (range / 2, 0)); EXPECT_FALSE (constrainment (positions, anchors)); } TEST_F (ConstrainmentStep, ConstrainedToPointsOnTargetMesh) { - wobbly::Point const movement (range * 2, 0); + animation::Point const movement (range * 2, 0); auto handleOwner (targets.Activate ()); wobbly::MoveOnly &handleWrap (handleOwner); wobbly::TargetMesh::Move const &moveBy (handleWrap); @@ -177,8 +177,8 @@ namespace /* Add range.x to each point */ for (size_t i = 0; i < positions.size () / 2; ++i) { - wobbly::PointView pv (expectedPositions, i); - wgd::pointwise_add (pv, wobbly::Point (range, 0)); + animation::PointView pv (expectedPositions, i); + agd::pointwise_add (pv, animation::Point (range, 0)); } std::vector > matchers; @@ -219,15 +219,15 @@ namespace double const sign = ratio / (absratio + (absratio == 0.0)); double const radiusInRange = range - (range / 2); - wobbly::PointView pv (positions, index); - wobbly::Point expected; + animation::PointView pv (positions, index); + animation::Point expected; - wgd::pointwise_add (pv, - wobbly::Point (radiusInRange * ratio, - radiusInRange * (1 - absratio) * sign)); + agd::pointwise_add (pv, + animation::Point (radiusInRange * ratio, + radiusInRange * (1 - absratio) * sign)); /* Expected point is the modified point here, before constrainment */ - wgd::pointwise_add (expected, pv); + agd::pointwise_add (expected, pv); constrainment (positions, anchors); @@ -242,53 +242,53 @@ namespace double const sign = ratio / (absratio + (absratio == 0.0)); double const radiusOutOfRange = range * range; - wobbly::Point outOfRange (radiusOutOfRange * ratio, - radiusOutOfRange * (1 - absratio) * sign); - wobbly::Point inRange (range * ratio, - range * (1 - absratio) * sign); + animation::Point outOfRange (radiusOutOfRange * ratio, + radiusOutOfRange * (1 - absratio) * sign); + animation::Point inRange (range * ratio, + range * (1 - absratio) * sign); - wobbly::PointView pv (positions, index); - wobbly::Point expected; + animation::PointView pv (positions, index); + animation::Point expected; /* Expected point is the actual grid point, but at its maximum range */ - wgd::assign (expected, pv); - wgd::pointwise_add (expected, inRange); + agd::assign (expected, pv); + agd::pointwise_add (expected, inRange); - wgd::pointwise_add (pv, outOfRange); + agd::pointwise_add (pv, outOfRange); constrainment (positions, anchors); EXPECT_THAT (pv, Eq (expected)); } - void ScalePositionMesh (wobbly::MeshArray &array, - wobbly::Point const &origin, - wobbly::Vector const &scaleFactor) + void ScalePositionMesh (wobbly::MeshArray &array, + animation::Point const &origin, + animation::Vector const &scaleFactor) { for (size_t i = 0; i < wobbly::config::TotalIndices; ++i) { - wobbly::PointView p (array, i); - wgd::pointwise_subtract (p, origin); - wgd::pointwise_scale (p, scaleFactor); - wgd::pointwise_add (p, origin); + animation::PointView p (array, i); + agd::pointwise_subtract (p, origin); + agd::pointwise_scale (p, scaleFactor); + agd::pointwise_add (p, origin); } } TEST_P (ConstrainmentStepPositions, NotAffectedWhereBothMeshesResizeEvenly) { - wobbly::Vector scaleFactor (range * 4, range * 4); + animation::Vector scaleFactor (range * 4, range * 4); ScalePositionMesh (positions, - wobbly::Point (positions[0], positions[1]), + animation::Point (positions[0], positions[1]), scaleFactor); ScalePositionMesh (targets.PointArray (), - wobbly::Point (targets.PointArray ()[0], - targets.PointArray ()[1]), + animation::Point (targets.PointArray ()[0], + targets.PointArray ()[1]), scaleFactor); - wobbly::PointView pv (positions, index); - wobbly::Point expected; + animation::PointView pv (positions, index); + animation::Point expected; /* Expected point is the same point here, before constrainment */ - wgd::assign (expected, pv); + agd::assign (expected, pv); constrainment (positions, anchors); @@ -297,17 +297,17 @@ namespace TEST_P (ConstrainmentStepPositions, AffectedWhereBothMeshesResizeUnevenly) { - wobbly::Vector scaleFactor (range * 4, range * 4); + animation::Vector scaleFactor (range * 4, range * 4); ScalePositionMesh (positions, - wobbly::Point (wobbly::config::Width / 2, - wobbly::config::Height / 2), + animation::Point (wobbly::config::Width / 2, + wobbly::config::Height / 2), scaleFactor); - wobbly::PointView pv (positions, index); - wobbly::Point expected; + animation::PointView pv (positions, index); + animation::Point expected; /* Not expecting the same point before constrainment */ - wgd::assign (expected, pv); + agd::assign (expected, pv); constrainment (positions, anchors); diff --git a/tests/euler_integration_test.cpp b/tests/wobbly/euler_integration_test.cpp similarity index 75% rename from tests/euler_integration_test.cpp rename to tests/wobbly/euler_integration_test.cpp index d1ad0b4..b6a223b 100644 --- a/tests/euler_integration_test.cpp +++ b/tests/wobbly/euler_integration_test.cpp @@ -1,14 +1,14 @@ /* - * tests/wobbly_test.cpp + * tests/wobbly/euler_integration_test.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -31,24 +31,24 @@ #include // IWYU pragma: keep #include // for AssertHelper, TEST_F, etc -#include // for PointView, Point, Vector -#include // for EulerIntegrate +#include // for PointView, Point, Vector +#include // for EulerIntegrate #include // for SatisfiesModel, Linear, etc using ::testing::Test; -using ::wobbly::matchers::Eq; -using ::wobbly::matchers::SatisfiesModel; -using ::wobbly::matchers::WithSamples; -using ::wobbly::matchers::WithTolerance; +using ::animation::matchers::Eq; +using ::animation::matchers::SatisfiesModel; +using ::animation::matchers::WithSamples; +using ::animation::matchers::WithTolerance; -using ::wobbly::models::Linear; -using ::wobbly::models::Parabolic; +using ::animation::models::Linear; +using ::animation::models::Parabolic; namespace { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; class SingleObjectStorage { @@ -59,19 +59,19 @@ namespace storage.fill (0); } - wobbly::PointView Position () + animation::PointView Position () { - return wobbly::PointView (storage, 0); + return animation::PointView (storage, 0); } - wobbly::PointView Velocity () + animation::PointView Velocity () { - return wobbly::PointView (storage, 1); + return animation::PointView (storage, 1); } - wobbly::PointView Force () + animation::PointView Force () { - return wobbly::PointView (storage, 2); + return animation::PointView (storage, 2); } private: @@ -90,9 +90,9 @@ namespace { } - wobbly::PointView position; - wobbly::PointView velocity; - wobbly::PointView force; + animation::PointView position; + animation::PointView velocity; + animation::PointView force; }; class EulerIntegration : @@ -105,7 +105,7 @@ namespace { } - typedef wobbly::PointView DCPV; + typedef animation::PointView DCPV; SingleObjectStorage storage; SingleObjectStorageView view; @@ -113,7 +113,7 @@ namespace TEST_F (EulerIntegration, ContinueStepWhenObjectsHaveVelocity) { - wgd::set <0> (view.velocity, 1.0); + agd::set <0> (view.velocity, 1.0); /* Integrate without any friction */ EXPECT_TRUE (wobbly::EulerIntegrate (1, @@ -126,7 +126,7 @@ namespace TEST_F (EulerIntegration, NoFurtherStepWhenObjectsHaveNoVelocity) { - wgd::set <0> (view.velocity, 0.0); + agd::set <0> (view.velocity, 0.0); /* Integrate without any friction */ EXPECT_FALSE (wobbly::EulerIntegrate (1, @@ -141,8 +141,8 @@ namespace { std::function horizontalVelocityFunction = [this](int timestep) -> double { - wgd::assign (view.position, wobbly::Point (1, 1)); - wgd::assign (view.velocity, wobbly::Point (1, 0)); + agd::assign (view.position, animation::Point (1, 1)); + agd::assign (view.velocity, animation::Point (1, 0)); wobbly::EulerIntegrate (timestep, 1, @@ -151,7 +151,7 @@ namespace std::move (view.velocity), DCPV (view.force)); - return wgd::get <0> (view.velocity); + return agd::get <0> (view.velocity); }; EXPECT_THAT (horizontalVelocityFunction, @@ -163,8 +163,8 @@ namespace std::function frictionlessHorizontalVelocityFunction = [this](int timestep) -> double { /* Reset velocity and force */ - wgd::assign (view.velocity, wobbly::Vector (0, 0)); - wgd::assign (view.force, wobbly::Vector (1.0f, 0)); + agd::assign (view.velocity, animation::Vector (0, 0)); + agd::assign (view.force, animation::Vector (1.0f, 0)); wobbly::EulerIntegrate (timestep, 0, @@ -173,7 +173,7 @@ namespace std::move (view.velocity), DCPV (view.force)); - return wgd::get <0> (view.velocity); + return agd::get <0> (view.velocity); }; EXPECT_THAT (frictionlessHorizontalVelocityFunction, @@ -188,9 +188,9 @@ namespace std::function frictionToVelocityFunction = [this, range](int frictionAmount) -> double { /* Reset velocity and force */ - wgd::assign (view.position, wobbly::Point (0, 0)); - wgd::assign (view.velocity, wobbly::Vector (0, 0)); - wgd::assign (view.force, wobbly::Vector (1.0f, 0)); + agd::assign (view.position, animation::Point (0, 0)); + agd::assign (view.velocity, animation::Vector (0, 0)); + agd::assign (view.force, animation::Vector (1.0f, 0)); double frictionProportion = frictionAmount / static_cast (range); @@ -206,7 +206,7 @@ namespace std::move (view.velocity), DCPV (view.force)); - return wgd::get <0> (view.velocity); + return agd::get <0> (view.velocity); }; EXPECT_THAT (frictionToVelocityFunction, diff --git a/tests/wobbly/glib_api_test.cpp b/tests/wobbly/glib_api_test.cpp new file mode 100644 index 0000000..6db1a40 --- /dev/null +++ b/tests/wobbly/glib_api_test.cpp @@ -0,0 +1,389 @@ +/* + * tests/wobbly/glib_api_test.cpp + * + * Copyright 2018 Endless Mobile, Inc. + * + * libanimation is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 2.1 of the + * License, or (at your option) any later version. + * + * libanimation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with eos-companion-app-service. If not, see + * . + * + * Tests for the "wobbly" spring model, GObject API. + */ + +#include // for operator<<, setprecision +#include // for ostream +#include // for basic_ostream, char_traits, etc + +#include +#include +#include + +#include // for Eq, EqDispatchHelper, etc +#include // for operator<<, etc +#include // for WithinGeometry, etc + +#include // for AtLeast +#include // for FunctionMocker, etc +#include // for AnythingMatcher, etc +#include // for EXPECT_CALL, etc +#include // for TEST_F, Test, Types, etc + +using ::testing::ElementsAreArray; +using ::testing::Eq; +using ::testing::Matcher; +using ::testing::Not; +using ::testing::Test; + +using ::animation::matchers::WithinGeometry; + +bool operator== (AnimationVector const &lhs, + AnimationVector const &rhs) +{ + return lhs.x == rhs.x && lhs.y == rhs.y; +} + +inline std::ostream & +operator<< (std::ostream &lhs, AnimationVector const &v) +{ + return lhs << std::setprecision (10) + << "x: " + << v.x + << " y: " + << v.y; +} + +namespace animation +{ + namespace geometry + { + namespace dimension + { + template <> + struct Dimension + { + typedef double data_type; + static const size_t dimensions = 2; + }; + + template <> + struct DimensionAccess + { + static inline double get (AnimationVector const &p) + { + return p.x; + } + + static inline void + set (AnimationVector &p, double const &value) + { + p.x = value; + } + }; + + template <> + struct DimensionAccess + { + static inline double get (AnimationVector const &p) + { + return p.y; + } + + static inline void + set (AnimationVector &p, double const &value) + { + p.y = value; + } + }; + } + } +} + +namespace +{ + namespace detail + { + template + struct ArrayMapInto + { + static void apply (std::array &dst, + std::array const &src, + Visitor &&visitor) + { + dst[I] = visitor (src[I]); + ArrayMapInto ::apply (dst, + src, + std::forward (visitor)); + } + }; + + template + struct ArrayMapInto + { + static void apply (std::array &dst, + std::array const &src, + Visitor &&visitor) + { + dst[0] = visitor (src[0]); + } + }; + } + + template + void array_map_into (std::array &dst, + std::array const &src, + Visitor &&visitor) + { + detail::ArrayMapInto ::apply (dst, + src, + std::forward (visitor)); + } + + typedef animation::Box PointBox; + + TEST (WobblyGLibAPI, ConstructModel) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + } + + TEST (WobblyGLibAPI, MoveModelChangesExtremes) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + + std::array extremes; + + animation_wobbly_model_move_to (model, { 1.0, 1.0 }); + animation_wobbly_model_query_extremes (model, + &extremes[0], + &extremes[1], + &extremes[2], + &extremes[3]); + + std::array expected = { + { + { 1.0, 1.0 }, + { 101.0, 1.0 }, + { 1.0, 101.0 }, + { 101.0, 101.0 } + } + }; + std::array , 4> textureEdges; + array_map_into (textureEdges, + expected, + [](auto const &vector) -> decltype(auto) { + return Eq (vector); + }); + + EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); + } + + TEST (WobblyGLibAPI, ResizeModelChangesExtremes) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + + std::array extremes; + + animation_wobbly_model_resize (model, { 200.0, 200.0 }); + animation_wobbly_model_query_extremes (model, + &extremes[0], + &extremes[1], + &extremes[2], + &extremes[3]); + + std::array expected = { + { + { 0.0, 0.0 }, + { 200.0, 0.0 }, + { 0.0, 200.0 }, + { 200.0, 200.0 } + } + }; + std::array , 4> textureEdges; + array_map_into (textureEdges, + expected, + [](auto const &vector) -> decltype(auto) { + return Eq (vector); + }); + + EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); + } + + TEST (WobblyGLibAPI, GrabCorrectIndex) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + g_autoptr(AnimationWobblyAnchor) anchor = animation_wobbly_model_grab_anchor (model, { 100.0, 0.0 }); + + animation_wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); + + AnimationVector topRightExtreme; + AnimationVector expectedTopRightExtreme = { 110.0, 0.0 }; + + animation_wobbly_model_query_extremes (model, + nullptr, + &topRightExtreme, + nullptr, + nullptr); + + EXPECT_THAT (topRightExtreme, Eq (expectedTopRightExtreme)); + } + + TEST (WobblyGLibAPI, ModelSettlesAfterMovingAnchor) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + g_autoptr(AnimationWobblyAnchor) anchor = animation_wobbly_model_grab_anchor (model, { 100.0, 0.0 }); + + /* Move anchor and settle */ + animation_wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); + while (animation_wobbly_model_step (model, 1)); + + std::array extremes; + animation_wobbly_model_query_extremes (model, + &extremes[0], + &extremes[1], + &extremes[2], + &extremes[3]); + + std::array expected = { + { + { 10.0, 10.0 }, + { 110.0, 10.0 }, + { 10.0, 110.0 }, + { 110.0, 110.0 } + } + }; + std::array , 4> textureEdges; + array_map_into (textureEdges, + expected, + [](auto const &vector) -> decltype(auto) { + return Eq (vector); + }); + + EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); + } + + TEST (WobblyGLibAPI, DeformedWithGrabbedAnchor) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + g_autoptr(AnimationWobblyAnchor) anchor = animation_wobbly_model_grab_anchor (model, { 100.0, 0.0 }); + AnimationVector deformed; + AnimationVector center = { 50.0, 50.0 }; + + animation_wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); + animation_wobbly_model_deform_texcoords (model, { 0.5, 0.5 }, &deformed); + + EXPECT_THAT (deformed, Not (Eq (center))); + } + + TEST (WobblyGLibAPI, DeformedWithInsertAnchor) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + g_autoptr(AnimationWobblyAnchor) anchor = animation_wobbly_model_insert_anchor (model, { 70.0, 0.0 }); + AnimationVector deformed; + AnimationVector center = { 50.0, 50.0 }; + + animation_wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); + animation_wobbly_model_step (model, 1); + animation_wobbly_model_deform_texcoords (model, { 0.5, 0.5 }, &deformed); + + EXPECT_THAT (deformed, Not (Eq (center))); + } + + TEST (WobblyGLibAPI, NoDeformationNoAnchorMove) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + g_autoptr(AnimationWobblyAnchor) anchor = animation_wobbly_model_grab_anchor (model, { 100.0, 0.0 }); + AnimationVector deformed; + AnimationVector center = { 50.0, 50.0 }; + + animation_wobbly_model_deform_texcoords (model, { 0.5, 0.5 }, &deformed); + + EXPECT_THAT (deformed, Eq (center)); + } + + TEST (WobblyGLibAPI, ReleaseAnchorOnModel) + { + g_autoptr(AnimationWobblyModel) model = animation_wobbly_model_new ({ 0.0, 0.0 }, + { 100.0, 100.0 }, + 8.0, + 5.0, + 500.0); + g_autoptr(AnimationWobblyAnchor) anchor = animation_wobbly_model_grab_anchor (model, { 100.0, 0.0 }); + + /* Temporarily grab another anchor and move the first one */ + { + g_autoptr(AnimationWobblyAnchor) otherAnchor = animation_wobbly_model_grab_anchor (model, { 0.0, 0.0 }); + animation_wobbly_anchor_move_by (anchor, { 10.0, 10.0 }); + } + + /* Anchor is now released. Settle model */ + while (animation_wobbly_model_step (model, 1)); + + std::array extremes; + animation_wobbly_model_query_extremes (model, + &extremes[0], + &extremes[1], + &extremes[2], + &extremes[3]); + + std::array expected = { + { + { 10.0, 10.0 }, + { 110.0, 10.0 }, + { 10.0, 110.0 }, + { 110.0, 110.0 } + } + }; + std::array , 4> textureEdges; + array_map_into (textureEdges, + expected, + [](auto const &vector) -> decltype(auto) { + return WithinGeometry (PointBox (animation::Point (vector.x - 3.0, + vector.y - 3.0), + animation::Point (vector.x + 3.0, + vector.y + 3.0))); + }); + + EXPECT_THAT (extremes, ElementsAreArray(textureEdges)); + } +} diff --git a/tests/mesh_interpolation_test.cpp b/tests/wobbly/mesh_interpolation_test.cpp similarity index 69% rename from tests/mesh_interpolation_test.cpp rename to tests/wobbly/mesh_interpolation_test.cpp index f7ee8bc..f839e20 100644 --- a/tests/mesh_interpolation_test.cpp +++ b/tests/wobbly/mesh_interpolation_test.cpp @@ -1,14 +1,14 @@ /* - * tests/wobbly_test.cpp + * tests/wobbly/mesh_interpolation_test.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -33,8 +33,8 @@ #include // for Values, Combine, ValuesIn, etc #include // for AssertHelper, TEST_F, Test, etc -#include // for Point, PointView -#include // for BezierMesh, Height, Width, etc +#include // for Point, PointView +#include // for BezierMesh, Height, Width, etc #include // for Eq, EqDispatchHelper, etc #include // for operator<< @@ -46,21 +46,21 @@ using ::testing::Test; using ::testing::ValuesIn; using ::testing::WithParamInterface; -using ::wobbly::matchers::Eq; -using ::wobbly::matchers::SatisfiesModel; -using ::wobbly::matchers::WithSamples; -using ::wobbly::matchers::WithTolerance; +using ::animation::matchers::Eq; +using ::animation::matchers::SatisfiesModel; +using ::animation::matchers::WithSamples; +using ::animation::matchers::WithTolerance; -using ::wobbly::models::Linear; +using ::animation::models::Linear; namespace { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; constexpr double TextureWidth = 50.0f; constexpr double TextureHeight = 100.0f; - wobbly::Point const TextureCenter = wobbly::Point (TextureWidth / 2, - TextureHeight / 2); + animation::Point const TextureCenter = animation::Point (TextureWidth / 2, + TextureHeight / 2); double TileWidth (double width) { @@ -86,10 +86,10 @@ namespace { for (unsigned int j = 0; j < meshWidth; ++j) { - wobbly::PointView pv (positions, - i * meshWidth + j); - wgd::assign (pv, wobbly::Point (tileWidth * j, - tileHeight * i)); + animation::PointView pv (positions, + i * meshWidth + j); + agd::assign (pv, animation::Point (tileWidth * j, + tileHeight * i)); } } } @@ -103,9 +103,9 @@ namespace protected: - typedef wobbly::Point Point; + typedef animation::Point Point; - typedef std::function &, + typedef std::function &, size_t, size_t)> MeshTransform; typedef std::function ResultFactory; @@ -152,8 +152,8 @@ namespace double const unitLookupValue = lookupValue / static_cast (pow (2, nSamples)); - auto const lookup (wobbly::Point (unitLookupValue, - unitLookupValue)); + auto const lookup (animation::Point (unitLookupValue, + unitLookupValue)); auto p (mesh.DeformUnitCoordsToMeshSpace (lookup)); return result (p); @@ -166,14 +166,14 @@ namespace { using namespace std::placeholders; - ApplyTransformation (std::bind ([](wobbly::PointView &pv) { - wgd::scale (pv, 2); + ApplyTransformation (std::bind ([](animation::PointView &pv) { + agd::scale (pv, 2); }, _1)); unsigned int const nSamples = 10; std::function horizontalDeformation = - UnitDeformationFunction ([](wobbly::Point const &p) -> double { - return wgd::get <0> (p); + UnitDeformationFunction ([](animation::Point const &p) -> double { + return agd::get <0> (p); }, mesh, nSamples); @@ -188,14 +188,14 @@ namespace { using namespace std::placeholders; - ApplyTransformation (std::bind ([](wobbly::PointView &pv) { - wgd::scale (pv, 2); + ApplyTransformation (std::bind ([](animation::PointView &pv) { + agd::scale (pv, 2); }, _1)); unsigned int const nSamples = 10; std::function verticalDeformation = - UnitDeformationFunction ([](wobbly::Point const &p) -> double { - return wgd::get <1> (p); + UnitDeformationFunction ([](animation::Point const &p) -> double { + return agd::get <1> (p); }, mesh, nSamples); @@ -214,16 +214,16 @@ namespace { using namespace std::placeholders; - typedef wobbly::PointView DoublePointView; + typedef animation::PointView DoublePointView; ApplyTransformation ([](DoublePointView &pv, size_t x, size_t y) { - wgd::pointwise_scale (pv, wobbly::Point (x, y)); + agd::pointwise_scale (pv, animation::Point (x, y)); }); unsigned int const nSamples = 10; std::function horizontalDeformation = - UnitDeformationFunction ([](wobbly::Point const &p) -> double { - return wgd::get <0> (p); + UnitDeformationFunction ([](animation::Point const &p) -> double { + return agd::get <0> (p); }, mesh, nSamples); @@ -236,13 +236,13 @@ namespace TEST_F (BezierMesh, ExtremesAreTextureEdges) { - std::array const extremes = mesh.Extremes (); - Matcher const textureEdges[] = + std::array const extremes = mesh.Extremes (); + Matcher const textureEdges[] = { - Eq (wobbly::Point (0, 0)), - Eq (wobbly::Point (TextureWidth, 0)), - Eq (wobbly::Point (0, TextureHeight)), - Eq (wobbly::Point (TextureWidth, TextureHeight)) + Eq (animation::Point (0, 0)), + Eq (animation::Point (TextureWidth, 0)), + Eq (animation::Point (0, TextureHeight)), + Eq (animation::Point (TextureWidth, TextureHeight)) }; EXPECT_THAT (extremes, ElementsAreArray (textureEdges)); @@ -251,32 +251,32 @@ namespace template void PointCeiling (Point &p) { - wgd::for_each_coordinate (p, [](auto const &coord) -> decltype(auto) { + agd::for_each_coordinate (p, [](auto const &coord) -> decltype(auto) { return std::ceil (coord); }); } class BezierMeshPoints : public BezierMesh, - public WithParamInterface + public WithParamInterface { }; - wobbly::Point TexturePrediction (wobbly::Point const &unit) + animation::Point TexturePrediction (animation::Point const &unit) { - wobbly::Point textureRelative (wgd::get <1> (unit), - wgd::get <0> (unit)); - wgd::pointwise_scale (textureRelative, - wobbly::Point (TextureWidth, - TextureHeight)); + animation::Point textureRelative (agd::get <1> (unit), + agd::get <0> (unit)); + agd::pointwise_scale (textureRelative, + animation::Point (TextureWidth, + TextureHeight)); PointCeiling (textureRelative); return textureRelative; } - wobbly::Point MeshInterpolation (wobbly::BezierMesh const &mesh, - wobbly::Point const &unit) + animation::Point MeshInterpolation (wobbly::BezierMesh const &mesh, + animation::Point const &unit) { - wobbly::Point meshRelative (mesh.DeformUnitCoordsToMeshSpace (unit)); + animation::Point meshRelative (mesh.DeformUnitCoordsToMeshSpace (unit)); PointCeiling (meshRelative); return meshRelative; } @@ -290,12 +290,12 @@ namespace EXPECT_THAT (interpolated, Eq (prediction)); } - wobbly::Point const unitMeshExtremes[] = + animation::Point const unitMeshExtremes[] = { - wobbly::Point (0.0, 0.0), - wobbly::Point (0.0, 1.0), - wobbly::Point (1.0, 0.0), - wobbly::Point (1.0, 1.0) + animation::Point (0.0, 0.0), + animation::Point (0.0, 1.0), + animation::Point (1.0, 0.0), + animation::Point (1.0, 1.0) }; INSTANTIATE_TEST_CASE_P (UnitExtremes, diff --git a/tests/model_test.cpp b/tests/wobbly/model_test.cpp similarity index 71% rename from tests/model_test.cpp rename to tests/wobbly/model_test.cpp index b83f9cf..0a35b20 100644 --- a/tests/model_test.cpp +++ b/tests/wobbly/model_test.cpp @@ -1,14 +1,14 @@ /* - * tests/wobbly_test.cpp + * tests/wobbly/model_test.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -40,8 +40,8 @@ #include // for TYPED_TEST, etc #include // for AssertHelper, etc -#include // for Point, PointView, Vector, etc -#include // for MeshArray, SpringMesh, etc +#include // for Point, PointView, Vector, etc +#include // for MeshArray, SpringMesh, etc #include // for Eq, EqDispatchHelper, etc #include // for operator<< @@ -62,15 +62,15 @@ using ::testing::Types; using ::testing::ValuesIn; using ::testing::WithParamInterface; -using ::wobbly::matchers::Eq; -using ::wobbly::matchers::SatisfiesModel; -using ::wobbly::matchers::WithinGeometry; +using ::animation::matchers::Eq; +using ::animation::matchers::SatisfiesModel; +using ::animation::matchers::WithinGeometry; -using ::wobbly::models::Parabolic; +using ::animation::models::Parabolic; namespace { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; class SingleObjectStorage { @@ -81,19 +81,19 @@ namespace storage.fill (0); } - wobbly::PointView Position () + animation::PointView Position () { - return wobbly::PointView (storage, 0); + return animation::PointView (storage, 0); } - wobbly::PointView Velocity () + animation::PointView Velocity () { - return wobbly::PointView (storage, 1); + return animation::PointView (storage, 1); } - wobbly::PointView Force () + animation::PointView Force () { - return wobbly::PointView (storage, 2); + return animation::PointView (storage, 2); } private: @@ -112,9 +112,9 @@ namespace { } - wobbly::PointView position; - wobbly::PointView velocity; - wobbly::PointView force; + animation::PointView position; + animation::PointView velocity; + animation::PointView force; }; constexpr double SpringConstant = 0.5f; @@ -145,9 +145,9 @@ namespace { wobbly::MeshArray mesh; - wobbly::Vector size (TileWidth (EvenSize), - TileHeight (EvenSize)); - wobbly::mesh::CalculatePositionArray (wobbly::Point (0, 0), + animation::Vector size (TileWidth (EvenSize), + TileHeight (EvenSize)); + wobbly::mesh::CalculatePositionArray (animation::Point (0, 0), mesh, size); @@ -159,8 +159,8 @@ namespace struct ClosestIndexToPositionParam { - wobbly::Point point; - size_t expectedIndex; + animation::Point point; + size_t expectedIndex; }; class ClosestIndexToPosition : @@ -171,37 +171,37 @@ namespace static std::vector NoTransform () { - return GetParams ([](wobbly::Point const &p) { + return GetParams ([](animation::Point const &p) { }); } static std::vector Expanded () { - wobbly::Vector translation (EvenSize / 2, EvenSize / 2); + animation::Vector translation (EvenSize / 2, EvenSize / 2); - return GetParams ([&translation](wobbly::Point &point) { + return GetParams ([&translation](animation::Point &point) { /* Scale on center */ - wgd::pointwise_subtract (point, translation); + agd::pointwise_subtract (point, translation); /* Older versions of cppcheck have trouble seeing through * the lambda */ // cppcheck-suppress unreachableCode - wgd::scale (point, 1.1); - wgd::pointwise_add (point, translation); + agd::scale (point, 1.1); + agd::pointwise_add (point, translation); }); } static std::vector Shrinked () { - wobbly::Vector translation (EvenSize / 2, EvenSize / 2); + animation::Vector translation (EvenSize / 2, EvenSize / 2); - return GetParams ([&translation](wobbly::Point &point) { + return GetParams ([&translation](animation::Point &point) { /* Scale on center */ - wgd::pointwise_subtract (point, translation); + agd::pointwise_subtract (point, translation); /* Older versions of cppcheck have trouble seeing through * the lambda */ // cppcheck-suppress unreachableCode - wgd::scale (point, 1.0 / 1.1); - wgd::pointwise_add (point, translation); + agd::scale (point, 1.0 / 1.1); + agd::pointwise_add (point, translation); }); } @@ -217,10 +217,10 @@ namespace for (size_t i = 0; i < total; ++i) { - wobbly::PointView pv (array, i); + animation::PointView pv (array, i); ParamType param; - wgd::assign (param.point, pv); + agd::assign (param.point, pv); param.expectedIndex = i; trans (param.point); @@ -264,16 +264,16 @@ namespace return spring.SecondPosition (); }), springMesh (mesh, - wobbly::Vector (TileWidth (EvenSize), - TileHeight (EvenSize))) + animation::Vector (TileWidth (EvenSize), + TileHeight (EvenSize))) { } - static void ApplyMovement (std::unique_ptr &ptr, - wobbly::Vector const &movement) + static void ApplyMovement (std::unique_ptr &ptr, + animation::Vector const &movement) { - wobbly::PointView pv (ptr.get (), 0); - wgd::pointwise_add (pv, movement); + animation::PointView pv (ptr.get (), 0); + agd::pointwise_add (pv, movement); } wobbly::SpringMesh::PosPreference firstPreference; @@ -302,14 +302,14 @@ namespace * by the two components is the same as tan(theta) formed by the * component distance from candidate to origin */ - wobbly::Vector delta; - wgd::assign (delta, candidate); - wgd::pointwise_subtract (delta, origin); + animation::Vector delta; + agd::assign (delta, candidate); + agd::pointwise_subtract (delta, origin); - auto vecTanTheta = (wgd::get <1> (vec) / - wgd::get <0> (vec)); - auto distTanTheta = (wgd::get <1> (delta) / - wgd::get <0> (delta)); + auto vecTanTheta = (agd::get <1> (vec) / + agd::get <0> (vec)); + auto distTanTheta = (agd::get <1> (delta) / + agd::get <0> (delta)); if (listener) *listener << "vector (" << vec << ")'s tan(theta) is " @@ -318,7 +318,7 @@ namespace << candidate << ")" << " with delta (" << delta << ") is " << distTanTheta; - return wobbly::testing::close_at_tolerance (vecTanTheta, distTanTheta, 10e-7); + return animation::testing::close_at_tolerance (vecTanTheta, distTanTheta, 10e-7); } void DescribeTo (::std::ostream *os) const @@ -358,8 +358,8 @@ namespace TEST_F (SpringMesh, ForceOnPointsTowardsTemporaryAnchor) { /* Insert a temporary anchor between points (1) and (2) on the grid */ - wobbly::Point const install (EvenSize / 2, 0); - wobbly::Point const movement (25, -50); + animation::Point const install (EvenSize / 2, 0); + animation::Point const movement (25, -50); auto handle (springMesh.InstallAnchorSprings (install, firstPreference, secondPreference)); @@ -367,24 +367,24 @@ namespace auto result = springMesh.CalculateForces (SpringConstant); - wobbly::Point anchorPosition (install); - wgd::pointwise_add (anchorPosition, movement); + animation::Point anchorPosition (install); + agd::pointwise_add (anchorPosition, movement); - wobbly::Vector const leftOffset (-TileWidth (EvenSize) / 2, 0); - wobbly::Vector const rightOffset (TileWidth (EvenSize) / 2, 0); + animation::Vector const leftOffset (-TileWidth (EvenSize) / 2, 0); + animation::Vector const rightOffset (TileWidth (EvenSize) / 2, 0); - wobbly::Point anchorLeftPoint (anchorPosition); - wgd::pointwise_add (anchorLeftPoint, leftOffset); + animation::Point anchorLeftPoint (anchorPosition); + agd::pointwise_add (anchorLeftPoint, leftOffset); - wobbly::Point anchorRightPoint (anchorPosition); - wgd::pointwise_add (anchorRightPoint, rightOffset); + animation::Point anchorRightPoint (anchorPosition); + agd::pointwise_add (anchorRightPoint, rightOffset); - wobbly::PointView firstPoint (mesh, 1); - wobbly::PointView secondPoint (mesh, 2); + animation::PointView firstPoint (mesh, 1); + animation::PointView secondPoint (mesh, 2); - EXPECT_THAT (wobbly::PointView (result.forces, 1), + EXPECT_THAT (animation::PointView (result.forces, 1), PointsInSameDirection (firstPoint, anchorLeftPoint)); - EXPECT_THAT (wobbly::PointView (result.forces, 2), + EXPECT_THAT (animation::PointView (result.forces, 2), PointsInSameDirection (secondPoint, anchorRightPoint)); } @@ -398,30 +398,30 @@ namespace { /* Insert first temporary anchor between points (1) and (2) on * the grid. */ - wobbly::Point const firstInstall (EvenSize / 2, 0); + animation::Point const firstInstall (EvenSize / 2, 0); auto firstHandle (springMesh.InstallAnchorSprings (firstInstall, firstPreference, secondPreference)); /* Insert second temporary anchor between the first temporary * spring's anchor and base point (2) */ - wobbly::Point const secondInstall (EvenSize / 2 + - (TileWidth (EvenSize) / 4), - 0); + animation::Point const secondInstall (EvenSize / 2 + + (TileWidth (EvenSize) / 4), + 0); auto secondHandle (springMesh.InstallAnchorSprings (secondInstall, firstPreference, secondPreference)); /* Move first handle to point above point (1) and second anchor * to point above point (2) */ - wobbly::Vector const firstMovement (-25, -50); - wobbly::Vector const secondMovement (25, -50); + animation::Vector const firstMovement (-25, -50); + animation::Vector const secondMovement (25, -50); - wobbly::Point firstAnchorPoint (firstInstall); - wgd::pointwise_add (firstAnchorPoint, firstMovement); + animation::Point firstAnchorPoint (firstInstall); + agd::pointwise_add (firstAnchorPoint, firstMovement); ApplyMovement (firstHandle.data, firstMovement); - wobbly::Point secondAnchorPoint (secondInstall); - wgd::pointwise_add (secondAnchorPoint, secondMovement); + animation::Point secondAnchorPoint (secondInstall); + agd::pointwise_add (secondAnchorPoint, secondMovement); ApplyMovement (secondHandle.data, secondMovement); /* Calculate forces */ @@ -429,21 +429,21 @@ namespace /* The desired delta between the first point and its base neighbour is * TileWidth / 2, 0 */ - wobbly::Point leftOfFirstAnchor (-TileWidth (EvenSize) / 2, 0); - wgd::pointwise_add (leftOfFirstAnchor, firstAnchorPoint); + animation::Point leftOfFirstAnchor (-TileWidth (EvenSize) / 2, 0); + agd::pointwise_add (leftOfFirstAnchor, firstAnchorPoint); /* For the second point, because we inserted it between the first * spring and the second base point, the desired delta will be half * of the first spring length, eg, TileWidth (EvenSize) / 4, 0 */ - wobbly::Point rightOfSecondAnchor (TileWidth (EvenSize) / 4, 0); - wgd::pointwise_add (rightOfSecondAnchor, secondAnchorPoint); + animation::Point rightOfSecondAnchor (TileWidth (EvenSize) / 4, 0); + agd::pointwise_add (rightOfSecondAnchor, secondAnchorPoint); - wobbly::PointView firstPoint (mesh, 1); - wobbly::PointView secondPoint (mesh, 2); + animation::PointView firstPoint (mesh, 1); + animation::PointView secondPoint (mesh, 2); - EXPECT_THAT (wobbly::PointView (result.forces, 1), + EXPECT_THAT (animation::PointView (result.forces, 1), PointsInSameDirection (firstPoint, leftOfFirstAnchor)); - EXPECT_THAT (wobbly::PointView (result.forces, 2), + EXPECT_THAT (animation::PointView (result.forces, 2), PointsInSameDirection (secondPoint, rightOfSecondAnchor)); } @@ -460,14 +460,14 @@ namespace /* Insert first temporary anchor between points (1) and (2) on * the grid. */ - wobbly::Point const firstInstall (EvenSize / 2, 0); + animation::Point const firstInstall (EvenSize / 2, 0); Handle first (new IR (springMesh.InstallAnchorSprings (firstInstall, fp, sp))); /* Insert second temporary anchor between the first temporary * spring's anchor and base point (2) */ - wobbly::Point const secondInstall (EvenSize / 2 + + animation::Point const secondInstall (EvenSize / 2 + (TileWidth (EvenSize) / 4), 0); Handle second (new IR (springMesh.InstallAnchorSprings (secondInstall, @@ -476,15 +476,15 @@ namespace /* Move first handle to point above point (1) and second anchor * to point above point (2) */ - wobbly::Vector const firstMovement (-25, -50); - wobbly::Vector const secondMovement (25, -50); + animation::Vector const firstMovement (-25, -50); + animation::Vector const secondMovement (25, -50); - wobbly::Point firstAnchorPoint (firstInstall); - wgd::pointwise_add (firstAnchorPoint, firstMovement); + animation::Point firstAnchorPoint (firstInstall); + agd::pointwise_add (firstAnchorPoint, firstMovement); ApplyMovement (first->data, firstMovement); - wobbly::Point secondAnchorPoint (secondInstall); - wgd::pointwise_add (secondAnchorPoint, secondMovement); + animation::Point secondAnchorPoint (secondInstall); + agd::pointwise_add (secondAnchorPoint, secondMovement); ApplyMovement (second->data, secondMovement); /* Now that both handles have been moved, make the second one expire */ @@ -493,31 +493,31 @@ namespace /* Calculate forces */ auto result = springMesh.CalculateForces (SpringConstant); - wobbly::Point anchorPosition (firstInstall); - wgd::pointwise_add (anchorPosition, firstMovement); + animation::Point anchorPosition (firstInstall); + agd::pointwise_add (anchorPosition, firstMovement); - wobbly::Vector const leftOffset (-TileWidth (EvenSize) / 2, 0); - wobbly::Vector const rightOffset (TileWidth (EvenSize) / 2, 0); + animation::Vector const leftOffset (-TileWidth (EvenSize) / 2, 0); + animation::Vector const rightOffset (TileWidth (EvenSize) / 2, 0); - wobbly::Point anchorLeftPoint (firstAnchorPoint); - wgd::pointwise_add (anchorLeftPoint, leftOffset); + animation::Point anchorLeftPoint (firstAnchorPoint); + agd::pointwise_add (anchorLeftPoint, leftOffset); - wobbly::Point anchorRightPoint (firstAnchorPoint); - wgd::pointwise_add (anchorRightPoint, rightOffset); + animation::Point anchorRightPoint (firstAnchorPoint); + agd::pointwise_add (anchorRightPoint, rightOffset); - wobbly::PointView firstPoint (mesh, 1); - wobbly::PointView secondPoint (mesh, 2); + animation::PointView firstPoint (mesh, 1); + animation::PointView secondPoint (mesh, 2); - EXPECT_THAT (wobbly::PointView (result.forces, 1), + EXPECT_THAT (animation::PointView (result.forces, 1), PointsInSameDirection (firstPoint, anchorLeftPoint)); - EXPECT_THAT (wobbly::PointView (result.forces, 2), + EXPECT_THAT (animation::PointView (result.forces, 2), PointsInSameDirection (secondPoint, anchorRightPoint)); } TEST_F (SpringMesh, HandlesCanExpireInNonReverseOrder) { EXPECT_EXIT ({ - wobbly::Point const install (EvenSize / 2, 0); + animation::Point const install (EvenSize / 2, 0); typedef wobbly::SpringMesh::InstallResult IR; typedef std::unique_ptr Handle; @@ -547,31 +547,31 @@ namespace /* Insert first temporary anchor between points (1) and (2) on * the grid. */ - wobbly::Point const firstInstall (EvenSize / 2, 0); + animation::Point const firstInstall (EvenSize / 2, 0); Handle first (new IR (springMesh.InstallAnchorSprings (firstInstall, fp, sp))); /* Insert second temporary anchor between the first temporary * spring's anchor and base point (2) */ - wobbly::Point const secondInst (EvenSize / 2 + - (TileWidth (EvenSize) / 4), - 0); + animation::Point const secondInst (EvenSize / 2 + + (TileWidth (EvenSize) / 4), + 0); Handle second (new IR (springMesh.InstallAnchorSprings (secondInst, fp, sp))); /* Move first handle to point above point (1) and second anchor * to point above point (2) */ - wobbly::Vector const firstMovement (-25, -50); - wobbly::Vector const secondMovement (25, -50); + animation::Vector const firstMovement (-25, -50); + animation::Vector const secondMovement (25, -50); - wobbly::Point firstAnchorPoint (firstInstall); - wgd::pointwise_add (firstAnchorPoint, firstMovement); + animation::Point firstAnchorPoint (firstInstall); + agd::pointwise_add (firstAnchorPoint, firstMovement); ApplyMovement (first->data, firstMovement); - wobbly::Point secondAnchorPoint (secondInst); - wgd::pointwise_add (secondAnchorPoint, secondMovement); + animation::Point secondAnchorPoint (secondInst); + agd::pointwise_add (secondAnchorPoint, secondMovement); ApplyMovement (second->data, secondMovement); /* Kill the first handle before the second */ @@ -582,10 +582,10 @@ namespace /* Calculate forces */ auto result = springMesh.CalculateForces (SpringConstant); - EXPECT_THAT (wobbly::PointView (result.forces, 1), - Eq (wobbly::Point (0, 0))); - EXPECT_THAT (wobbly::PointView (result.forces, 2), - Eq (wobbly::Point (0, 0))); + EXPECT_THAT (animation::PointView (result.forces, 1), + Eq (animation::Point (0, 0))); + EXPECT_THAT (animation::PointView (result.forces, 2), + Eq (animation::Point (0, 0))); } /* This tests that if we pass in a different preference for a @@ -594,24 +594,24 @@ namespace TEST_F (SpringMesh, DesiredDistanceCanBeDifferentToSpringPositionAtGrab) { /* Insert a temporary anchor between points (1) and (2) on the grid */ - wobbly::Point const install (EvenSize / 2, 0); - wobbly::Point const movement (25, -50); - wobbly::Vector const desiredOffset (25, 0); + animation::Point const install (EvenSize / 2, 0); + animation::Point const movement (25, -50); + animation::Vector const desiredOffset (25, 0); std::array points; - typedef wobbly::PointView DCPV; + typedef animation::PointView DCPV; typedef DCPV const & (wobbly::Spring::*Get) () const; auto const prefOffset = [this, &desiredOffset, &points](wobbly::Spring const &spring, Get get, size_t offset) { - wobbly::PointView pv (points, offset); - wgd::assign (pv, (spring.*get) ()); - wgd::pointwise_add (pv, desiredOffset); + animation::PointView pv (points, offset); + agd::assign (pv, (spring.*get) ()); + agd::pointwise_add (pv, desiredOffset); - return wobbly::PointView (points, offset); + return animation::PointView (points, offset); }; using namespace std::placeholders; @@ -630,19 +630,19 @@ namespace auto result = springMesh.CalculateForces (SpringConstant); - wobbly::Point anchorPosition (install); - wgd::pointwise_add (anchorPosition, movement); + animation::Point anchorPosition (install); + agd::pointwise_add (anchorPosition, movement); - wobbly::Vector const leftOffset (-TileWidth (EvenSize) / 2, 0); - wobbly::Vector const rightOffset (TileWidth (EvenSize) / 2, 0); + animation::Vector const leftOffset (-TileWidth (EvenSize) / 2, 0); + animation::Vector const rightOffset (TileWidth (EvenSize) / 2, 0); - wobbly::Point anchorLeftPoint (anchorPosition); - wgd::pointwise_add (anchorLeftPoint, leftOffset); - wgd::pointwise_add (anchorLeftPoint, desiredOffset); + animation::Point anchorLeftPoint (anchorPosition); + agd::pointwise_add (anchorLeftPoint, leftOffset); + agd::pointwise_add (anchorLeftPoint, desiredOffset); - wobbly::Point anchorRightPoint (anchorPosition); - wgd::pointwise_add (anchorRightPoint, rightOffset); - wgd::pointwise_add (anchorRightPoint, desiredOffset); + animation::Point anchorRightPoint (anchorPosition); + agd::pointwise_add (anchorRightPoint, rightOffset); + agd::pointwise_add (anchorRightPoint, desiredOffset); /* We don't add anything to firstPoint and secondPoint here * because there will be an offset of desiredOffset from @@ -652,19 +652,19 @@ namespace * * If we add delta to these points (eg, oldPosition) then * this will not model the equation correctly */ - wobbly::PointView firstPoint (mesh, 1); - wobbly::PointView secondPoint (mesh, 2); + animation::PointView firstPoint (mesh, 1); + animation::PointView secondPoint (mesh, 2); - EXPECT_THAT (wobbly::PointView (result.forces, 1), + EXPECT_THAT (animation::PointView (result.forces, 1), PointsInSameDirection (firstPoint, anchorLeftPoint)); - EXPECT_THAT (wobbly::PointView (result.forces, 2), + EXPECT_THAT (animation::PointView (result.forces, 2), PointsInSameDirection (secondPoint, anchorRightPoint)); } constexpr double TextureWidth = 50.0f; constexpr double TextureHeight = 100.0f; - wobbly::Point const TextureCenter = wobbly::Point (TextureWidth / 2, - TextureHeight / 2); + animation::Point const TextureCenter = animation::Point (TextureWidth / 2, + TextureHeight / 2); class SpringBezierModel : @@ -673,7 +673,7 @@ namespace public: SpringBezierModel () : - model (wobbly::Vector (0, 0), + model (animation::Vector (0, 0), TextureWidth, TextureHeight) { @@ -687,20 +687,20 @@ namespace template void PointCeiling (Point &p) { - wgd::for_each_coordinate (p, [](auto const &coord) -> decltype(auto) { + agd::for_each_coordinate (p, [](auto const &coord) -> decltype(auto) { return std::ceil (coord); }); } void MoveModelASmallAmount (wobbly::Model &model) { - model.MoveModelTo (wobbly::Vector (1, 1)); + model.MoveModelTo (animation::Vector (1, 1)); model.Step (1); } - wobbly::Point GetTruncatedDeformedCenter (wobbly::Model const &model) + animation::Point GetTruncatedDeformedCenter (wobbly::Model const &model) { - auto center (wobbly::Point (0.5, 0.5)); + auto center (animation::Point (0.5, 0.5)); auto point (model.DeformTexcoords (center)); /* Not quite accurate, but truncate the returned point @@ -715,7 +715,7 @@ namespace auto point (GetTruncatedDeformedCenter (model)); auto TextureCenterOffsetByOne (TextureCenter); - wgd::pointwise_add (TextureCenterOffsetByOne, wobbly::Vector (1, 1)); + agd::pointwise_add (TextureCenterOffsetByOne, animation::Vector (1, 1)); EXPECT_THAT (point, Eq (TextureCenterOffsetByOne)); @@ -725,13 +725,13 @@ namespace { /* Anchor implicitly released at end of scope */ { - model.GrabAnchor (wobbly::Point (TextureWidth / 2, 0)); + model.GrabAnchor (animation::Point (TextureWidth / 2, 0)); } MoveModelASmallAmount (model); auto point (GetTruncatedDeformedCenter (model)); auto TextureCenterOffsetByOne (TextureCenter); - wgd::pointwise_add (TextureCenterOffsetByOne, wobbly::Vector (1, 1)); + agd::pointwise_add (TextureCenterOffsetByOne, animation::Vector (1, 1)); EXPECT_THAT (point, @@ -740,12 +740,12 @@ namespace TEST_F (SpringBezierModel, MovingEntireModelCausesNoDeformationWithAnchor) { - auto anchor (model.GrabAnchor (wobbly::Point (TextureWidth / 2, 0))); + auto anchor (model.GrabAnchor (animation::Point (TextureWidth / 2, 0))); MoveModelASmallAmount (model); auto point (GetTruncatedDeformedCenter (model)); auto TextureCenterOffsetByOne (TextureCenter); - wgd::pointwise_add (TextureCenterOffsetByOne, wobbly::Vector (1, 1)); + agd::pointwise_add (TextureCenterOffsetByOne, animation::Vector (1, 1)); EXPECT_THAT (point, @@ -759,15 +759,15 @@ namespace unsigned int const x2 = TextureWidth + x1; unsigned int const y2 = TextureHeight + y1; - model.MoveModelTo (wobbly::Point (x1, y1)); + model.MoveModelTo (animation::Point (x1, y1)); - std::array const extremes = model.Extremes (); - Matcher const textureEdges[] = + std::array const extremes = model.Extremes (); + Matcher const textureEdges[] = { - Eq (wobbly::Point (x1, y1)), - Eq (wobbly::Point (x2, y1)), - Eq (wobbly::Point (x1, y2)), - Eq (wobbly::Point (x2, y2)) + Eq (animation::Point (x1, y1)), + Eq (animation::Point (x2, y1)), + Eq (animation::Point (x1, y2)), + Eq (animation::Point (x2, y2)) }; EXPECT_THAT (extremes, ElementsAreArray (textureEdges)); @@ -775,9 +775,9 @@ namespace TEST_F (SpringBezierModel, MovingAnchorCausesDeformation) { - auto anchor (model.GrabAnchor (wobbly::Point (TextureWidth / 2, 0))); + auto anchor (model.GrabAnchor (animation::Point (TextureWidth / 2, 0))); - anchor.MoveBy (wobbly::Vector (1, 1)); + anchor.MoveBy (animation::Vector (1, 1)); auto point (GetTruncatedDeformedCenter (model)); EXPECT_THAT (point, @@ -786,11 +786,11 @@ namespace TEST_F (SpringBezierModel, MovingAnchorWithSecondGrabCausesDeformation) { - auto anchor (model.GrabAnchor (wobbly::Point (TextureWidth / 2, 0))); + auto anchor (model.GrabAnchor (animation::Point (TextureWidth / 2, 0))); { - auto secondAnchor (model.GrabAnchor (wobbly::Point (TextureWidth, 0))); - anchor.MoveBy (wobbly::Vector (1, 1)); + auto secondAnchor (model.GrabAnchor (animation::Point (TextureWidth, 0))); + anchor.MoveBy (animation::Vector (1, 1)); } auto point (GetTruncatedDeformedCenter (model)); @@ -799,7 +799,7 @@ namespace Not (Eq (TextureCenter))); } - typedef std::tuple SpringGrabParams; + typedef std::tuple SpringGrabParams; class SpringBezierModelGrabPositions : public SpringBezierModel, @@ -815,13 +815,13 @@ namespace { } - wobbly::Point const &grabPosition; - wobbly::Point const &oppositeGrabPosition; - wobbly::Point const &movement; + animation::Point const &grabPosition; + animation::Point const &oppositeGrabPosition; + animation::Point const &movement; size_t extremeIndex; }; - typedef wobbly::Box PointBox; + typedef animation::Box PointBox; /* Only tests the GrabIndex strategy */ TEST_P (SpringBezierModelGrabPositions, GrabsCorrectIndex) @@ -829,8 +829,8 @@ namespace wobbly::Anchor grab (model.GrabAnchor (grabPosition)); grab.MoveBy (movement); - wobbly::Point transformed (grabPosition); - wgd::pointwise_add (transformed, movement); + animation::Point transformed (grabPosition); + agd::pointwise_add (transformed, movement); EXPECT_THAT (model.Extremes ()[extremeIndex], Eq (transformed)); @@ -845,13 +845,13 @@ namespace * While exact positioning isn't possible without anchors grabbed, * it is almost always desired in this case */ wobbly::Anchor grab (model.GrabAnchor (grabPosition)); - grab.MoveBy (wobbly::Vector (100, 100)); + grab.MoveBy (animation::Vector (100, 100)); /* Wait for model to settle */ while (model.Step (1)); EXPECT_THAT (model.Extremes ()[0], - Eq (wobbly::Point (100, 100))); + Eq (animation::Point (100, 100))); } TEST_P (SpringBezierModelGrabPositions, SettlesAfterReleasingSecond) @@ -867,7 +867,7 @@ namespace { wobbly::Anchor secondGrab (model.GrabAnchor (oppositeGrabPosition)); - grab.MoveBy (wobbly::Vector (100, 100)); + grab.MoveBy (animation::Vector (100, 100)); } /* Wait for model to settle */ @@ -876,27 +876,27 @@ namespace /* We can't be exact here, since a full integration is required to * compute the target position. */ EXPECT_THAT (model.Extremes ()[0], - WithinGeometry (PointBox (wobbly::Point (97.0, 97.0), - wobbly::Point (103.0, 103.0)))); + WithinGeometry (PointBox (animation::Point (97.0, 97.0), + animation::Point (103.0, 103.0)))); } SpringGrabParams const springGrabParams[] = { - SpringGrabParams (wobbly::Point (0.0, 0.0), - wobbly::Point (TextureWidth, TextureHeight), - wobbly::Point (-1.0, -1.0), + SpringGrabParams (animation::Point (0.0, 0.0), + animation::Point (TextureWidth, TextureHeight), + animation::Point (-1.0, -1.0), 0), - SpringGrabParams (wobbly::Point (TextureWidth, 0.0), - wobbly::Point (0.0, TextureHeight), - wobbly::Point (1.0, -1.0), + SpringGrabParams (animation::Point (TextureWidth, 0.0), + animation::Point (0.0, TextureHeight), + animation::Point (1.0, -1.0), 1), - SpringGrabParams (wobbly::Point (0.0, TextureHeight), - wobbly::Point (TextureWidth, 0.0), - wobbly::Point (-1.0, 1.0), + SpringGrabParams (animation::Point (0.0, TextureHeight), + animation::Point (TextureWidth, 0.0), + animation::Point (-1.0, 1.0), 2), - SpringGrabParams (wobbly::Point (TextureWidth, TextureHeight), - wobbly::Point (0.0, 0.0), - wobbly::Point (1.0, 1.0), + SpringGrabParams (animation::Point (TextureWidth, TextureHeight), + animation::Point (0.0, 0.0), + animation::Point (1.0, 1.0), 3) }; @@ -910,19 +910,19 @@ namespace double const TextureWidthAfterResize = ModelScaleFactorX * TextureWidth; double const TextureHeightAfterResize = ModelScaleFactorY * TextureHeight; - typedef Matcher PointMatcher; + typedef Matcher PointMatcher; TEST_F (SpringBezierModel, PositionsScaledAfterResize) { - wobbly::Vector const scaleFactor (ModelScaleFactorX, - ModelScaleFactorY); + animation::Vector const scaleFactor (ModelScaleFactorX, + ModelScaleFactorY); - std::array const extremes = model.Extremes (); + std::array const extremes = model.Extremes (); /* Older versions of gmock don't support matching against a vector */ auto scaledPointMatcher = - [&scaleFactor](wobbly::Point p) -> PointMatcher { - wgd::pointwise_scale (p, scaleFactor); + [&scaleFactor](animation::Point p) -> PointMatcher { + agd::pointwise_scale (p, scaleFactor); return Eq (p); }; @@ -942,18 +942,18 @@ namespace TEST_F (SpringBezierModel, PositionsScaledRelativeToModelOrigin) { - wobbly::Vector const scaleFactor (ModelScaleFactorX, - ModelScaleFactorY); - wobbly::Vector const movement (10.0f, 10.0f); + animation::Vector const scaleFactor (ModelScaleFactorX, + ModelScaleFactorY); + animation::Vector const movement (10.0f, 10.0f); model.MoveModelTo (movement); - std::array const extremes = model.Extremes (); + std::array const extremes = model.Extremes (); auto scaledPointMatcher = - [&scaleFactor, &movement](wobbly::Point p) -> PointMatcher { - wgd::pointwise_subtract (p, movement); - wgd::pointwise_scale (p, scaleFactor); - wgd::pointwise_add (p, movement); + [&scaleFactor, &movement](animation::Point p) -> PointMatcher { + agd::pointwise_subtract (p, movement); + agd::pointwise_scale (p, scaleFactor); + agd::pointwise_add (p, movement); return Eq (p); }; @@ -996,7 +996,7 @@ namespace * get constrained to the old model size' constraint extents after * resizing while grabbed */ wobbly::Anchor grab (model.GrabAnchor (model.Extremes ()[0])); - wobbly::Vector translation (1000, 1000); + animation::Vector translation (1000, 1000); model.MoveModelBy (translation); /* Just moving the model, not the anchor - all points and targets @@ -1006,7 +1006,7 @@ namespace TEST_F (SpringBezierModel, PositionIsTopLeftCornerAtSettled) { - wobbly::Vector const position (100, 100); + animation::Vector const position (100, 100); model.MoveModelBy (position); /* We can assume that Extremes ()[0] is the top-left position as @@ -1027,8 +1027,8 @@ namespace /* GrabAnchorStrategy grab a single point on the mesh and move it */ struct GrabAnchorStrategyFactory { - wobbly::Anchor operator () (wobbly::Model &model, - wobbly::Point const &grabPoint) + wobbly::Anchor operator () (wobbly::Model &model, + animation::Point const &grabPoint) { return model.GrabAnchor (grabPoint); } @@ -1037,8 +1037,8 @@ namespace /* InstallAnchorStrategy installs a new anchor on the mesh */ struct InstallAnchorStrategyFactory { - wobbly::Anchor operator () (wobbly::Model &model, - wobbly::Point const &grabPoint) + wobbly::Anchor operator () (wobbly::Model &model, + animation::Point const &grabPoint) { return model.InsertAnchor (grabPoint); } @@ -1054,8 +1054,8 @@ namespace * and the anchors should have moved along with the model */ TYPED_TEST (SpringBezierModelAnchorStrategy, AnchorMovedAfterMeshResize) { - wobbly::Vector const grabPoint (TextureWidth, - TextureHeight); + animation::Vector const grabPoint (TextureWidth, + TextureHeight); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); this->model.ResizeModel (TextureWidthAfterResize, @@ -1066,11 +1066,11 @@ namespace TYPED_TEST (SpringBezierModelAnchorStrategy, AnchorMovedAfterMeshMove) { - wobbly::Vector const grabPoint (TextureWidth, - TextureHeight); + animation::Vector const grabPoint (TextureWidth, + TextureHeight); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); - this->model.MoveModelBy (wobbly::Vector (100, 100)); + this->model.MoveModelBy (animation::Vector (100, 100)); EXPECT_FALSE (this->model.Step (1)); } @@ -1090,9 +1090,9 @@ namespace * to get the model to settle. We'll apply n - 1 integrations to the * second and then test it. */ - wobbly::Vector const grabPoint (TextureWidth / 2, TextureHeight / 2); + animation::Vector const grabPoint (TextureWidth / 2, TextureHeight / 2); - wobbly::Model referenceModel (wobbly::Vector (0, 0), + wobbly::Model referenceModel (animation::Vector (0, 0), TextureWidth, TextureHeight); @@ -1107,12 +1107,12 @@ namespace float const positive = 1; float const negative = static_cast (positive) * -1.0; - grab.MoveBy (wobbly::Vector (positive, positive)); - this->model.MoveModelBy (wobbly::Vector (negative, negative)); + grab.MoveBy (animation::Vector (positive, positive)); + this->model.MoveModelBy (animation::Vector (negative, negative)); while (this->model.Step (1)); - referenceGrab.MoveBy (wobbly::Vector (positive, positive)); - referenceModel.MoveModelBy (wobbly::Vector (negative, negative)); + referenceGrab.MoveBy (animation::Vector (positive, positive)); + referenceModel.MoveModelBy (animation::Vector (negative, negative)); while (referenceModel.Step (1)); } @@ -1129,8 +1129,8 @@ namespace /* Slightly higher range */ EXPECT_THAT (this->model.Extremes ()[0], - WithinGeometry (PointBox (wobbly::Point (-2.0, -2.0), - wobbly::Point (2.0, 2.0)))); + WithinGeometry (PointBox (animation::Point (-2.0, -2.0), + animation::Point (2.0, 2.0)))); } /* The only way we can test this is to perform operations dependent @@ -1143,18 +1143,18 @@ namespace * will end up back at 0, 0. We can't observe the target positions * so we need to do it this way */ - wobbly::Vector const grabPoint (0, 0); + animation::Vector const grabPoint (0, 0); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); - grab.MoveBy (wobbly::Point (100, 100)); - this->model.MoveModelTo (wobbly::Point (0, 0)); + grab.MoveBy (animation::Point (100, 100)); + this->model.MoveModelTo (animation::Point (0, 0)); /* Wait until the model has completely settled */ while (this->model.Step (1)); EXPECT_THAT (this->model.Extremes ()[0], - WithinGeometry (PointBox (wobbly::Point (-1.5, -1.5), - wobbly::Point (1.5, 1.5)))); + WithinGeometry (PointBox (animation::Point (-1.5, -1.5), + animation::Point (1.5, 1.5)))); } TYPED_TEST (SpringBezierModelAnchorStrategy, ConsistentMovementManyGrabs) @@ -1165,21 +1165,21 @@ namespace * so we need to do it this way */ for (size_t i = 0; i < 5; ++i) { - this->model.MoveModelTo (wobbly::Point (0, 0)); - wobbly::Vector const grabPoint (0, 0); + this->model.MoveModelTo (animation::Point (0, 0)); + animation::Vector const grabPoint (0, 0); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); - grab.MoveBy (wobbly::Point (100, 100)); - this->model.MoveModelTo (wobbly::Point (0, 0)); + grab.MoveBy (animation::Point (100, 100)); + this->model.MoveModelTo (animation::Point (0, 0)); /* Wait until the model has completely settled */ while (this->model.Step (1)); } EXPECT_THAT (this->model.Extremes ()[0], - WithinGeometry (PointBox (wobbly::Point (-1.5, -1.5), - wobbly::Point (1.5, 1.5)))); + WithinGeometry (PointBox (animation::Point (-1.5, -1.5), + animation::Point (1.5, 1.5)))); } /* The only way we can test this is to perform operations dependent @@ -1193,24 +1193,24 @@ namespace * grabs */ { - wobbly::Vector const grabPoint (0, 0); + animation::Vector const grabPoint (0, 0); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); } - wobbly::Vector const grabPoint (TextureWidth, 0); + animation::Vector const grabPoint (TextureWidth, 0); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); - grab.MoveBy (wobbly::Point (100, 100)); - this->model.MoveModelTo (wobbly::Point (0, 0)); + grab.MoveBy (animation::Point (100, 100)); + this->model.MoveModelTo (animation::Point (0, 0)); /* Wait until the model has completely settled */ while (this->model.Step (1)); EXPECT_THAT (this->model.Extremes ()[0], - WithinGeometry (PointBox (wobbly::Point (-1.5, -1.5), - wobbly::Point (1.5, 1.5)))); + WithinGeometry (PointBox (animation::Point (-1.5, -1.5), + animation::Point (1.5, 1.5)))); } TYPED_TEST (SpringBezierModelAnchorStrategy, TargetRemainsAfterRelease) @@ -1219,32 +1219,32 @@ namespace * and then move it to a new position. This should still cause its * target position to end up roughly in the same place */ { - wobbly::Vector const grabPoint (0, 0); + animation::Vector const grabPoint (0, 0); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); - grab.MoveBy (wobbly::Point (100, 100)); + grab.MoveBy (animation::Point (100, 100)); this->model.Step (2); } - this->model.MoveModelTo (wobbly::Point (0, 0)); + this->model.MoveModelTo (animation::Point (0, 0)); /* Wait until the model has completely settled */ while (this->model.Step (1)); EXPECT_THAT (this->model.Extremes ()[0], - WithinGeometry (PointBox (wobbly::Point (-1.5, -1.5), - wobbly::Point (1.5, 1.5)))); + WithinGeometry (PointBox (animation::Point (-1.5, -1.5), + animation::Point (1.5, 1.5)))); } TYPED_TEST (SpringBezierModelAnchorStrategy, MoreAnchoredModelNeverSettles) { - wobbly::Model oneAnchorModel (wobbly::Vector (0, 0), + wobbly::Model oneAnchorModel (animation::Vector (0, 0), TextureWidth, TextureHeight); - wobbly::Point const firstGrabPoint (0, 0); - wobbly::Point const secondGrabPoint (TextureWidth, 0); + animation::Point const firstGrabPoint (0, 0); + animation::Point const secondGrabPoint (TextureWidth, 0); auto firstForOneAnchorModel (this->createAnchorFor (oneAnchorModel, firstGrabPoint)); @@ -1253,7 +1253,7 @@ namespace auto secondForTwoAnchorModel (this->createAnchorFor (this->model, secondGrabPoint)); - wobbly::Vector const firstMovement (-100, 0); + animation::Vector const firstMovement (-100, 0); firstForOneAnchorModel.MoveBy (firstMovement); firstForTwoAnchorModel.MoveBy (firstMovement); @@ -1278,11 +1278,11 @@ namespace TYPED_TEST (SpringBezierModelAnchorStrategy, ForcesExistAfterMovingAnchor) { /* Create an anchor and move it. Step (0) should return true */ - wobbly::Vector const grabPoint (0, 0); + animation::Vector const grabPoint (0, 0); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); - grab.MoveBy (wobbly::Point (100, 100)); + grab.MoveBy (animation::Point (100, 100)); EXPECT_TRUE (this->model.Step (0)); } @@ -1290,11 +1290,11 @@ namespace { { /* Create an anchor and move it. Step (0) should return true */ - wobbly::Vector const grabPoint (0, 0); + animation::Vector const grabPoint (0, 0); wobbly::Anchor grab (this->createAnchorFor (this->model, grabPoint)); - grab.MoveBy (wobbly::Point (100, 100)); + grab.MoveBy (animation::Point (100, 100)); /* Step the model once, this will make the model unequal */ this->model.Step (1); @@ -1307,10 +1307,10 @@ namespace void GrabModelMoveAndStepASmallAmount (wobbly::Model &model) { - wobbly::Vector const grabPoint (model.Extremes ()[3]); + animation::Vector const grabPoint (model.Extremes ()[3]); wobbly::Anchor anchor (model.GrabAnchor (grabPoint)); - anchor.MoveBy (wobbly::Point (100, 100)); + anchor.MoveBy (animation::Point (100, 100)); /* Twenty steps is reasonable */ for (int i = 0; i < 20; ++i) @@ -1333,11 +1333,11 @@ namespace lowerK.springConstant -= 2.0f; - wobbly::Model lowerSpringKModel (wobbly::Vector (0, 0), + wobbly::Model lowerSpringKModel (animation::Vector (0, 0), TextureWidth, TextureHeight, lowerK); - wobbly::Model higherSpringKModel (wobbly::Vector (0, 0), + wobbly::Model higherSpringKModel (animation::Vector (0, 0), TextureWidth, TextureHeight, higherK); @@ -1345,8 +1345,8 @@ namespace GrabModelMoveAndStepASmallAmount (lowerSpringKModel); GrabModelMoveAndStepASmallAmount (higherSpringKModel); - EXPECT_GT (wgd::get <0> (higherSpringKModel.Extremes ()[0]), - wgd::get <0> (lowerSpringKModel.Extremes ()[0])); + EXPECT_GT (agd::get <0> (higherSpringKModel.Extremes ()[0]), + agd::get <0> (lowerSpringKModel.Extremes ()[0])); } TEST (SpringBezierModelSettings, ModelWithLowerFrictionTakesFasterFirstStep) @@ -1356,11 +1356,11 @@ namespace lowerF.friction -= 2.0f; - wobbly::Model lowerFrictionModel (wobbly::Vector (0, 0), + wobbly::Model lowerFrictionModel (animation::Vector (0, 0), TextureWidth, TextureHeight, lowerF); - wobbly::Model higherFrictionModel (wobbly::Vector (0, 0), + wobbly::Model higherFrictionModel (animation::Vector (0, 0), TextureWidth, TextureHeight, higherF); @@ -1368,8 +1368,8 @@ namespace GrabModelMoveAndStepASmallAmount (lowerFrictionModel); GrabModelMoveAndStepASmallAmount (higherFrictionModel); - EXPECT_GT (wgd::get <0> (lowerFrictionModel.Extremes ()[0]), - wgd::get <0> (higherFrictionModel.Extremes ()[0])); + EXPECT_GT (agd::get <0> (lowerFrictionModel.Extremes ()[0]), + agd::get <0> (higherFrictionModel.Extremes ()[0])); } struct MockIntegration @@ -1457,11 +1457,11 @@ namespace { /* Call the reset () function on the integrator. No changes * should occurr on the position at that index */ - wobbly::PointView pointView (TestFixture::points, 0); + animation::PointView pointView (TestFixture::points, 0); TestFixture::integrator.Reset (0); - EXPECT_THAT (pointView, Eq (wobbly::Point (0, 0))); + EXPECT_THAT (pointView, Eq (animation::Point (0, 0))); } TYPED_TEST (IntegrationStrategy, EffectiveVelocityChangedToZeroOnReset) @@ -1469,11 +1469,11 @@ namespace /* Apply a force once to a frictionless object and integrate it. * Call reset and integrate again without any force. The result is * no change in position as the velocity was reset */ - wobbly::PointView forceView (TestFixture::forces, 0); - wobbly::PointView pointView (TestFixture::points, 0); + animation::PointView forceView (TestFixture::forces, 0); + animation::PointView pointView (TestFixture::points, 0); /* First apply a force to an object and integrate */ - wgd::set <0> (forceView, 1.0); + agd::set <0> (forceView, 1.0); TestFixture::integrator.Step (0, 1.0, 1.0, @@ -1481,11 +1481,11 @@ namespace TestFixture::points, TestFixture::forces); - wobbly::Point expectedPosition; - wgd::assign (expectedPosition, pointView); + animation::Point expectedPosition; + agd::assign (expectedPosition, pointView); /* Remove force, reset and integrate again */ - wgd::set <0> (forceView, 0.0); + agd::set <0> (forceView, 0.0); TestFixture::integrator.Reset (0); TestFixture::integrator.Step (0, 1.0, @@ -1501,14 +1501,14 @@ namespace TYPED_TEST (IntegrationStrategy, VelocityAffectedWithNewForcesAfterReset) { - wobbly::PointView forceView (TestFixture::forces, 0); - wobbly::PointView pointView (TestFixture::points, 0); + animation::PointView forceView (TestFixture::forces, 0); + animation::PointView pointView (TestFixture::points, 0); - wobbly::Point initialPosition; - wgd::assign (initialPosition, pointView); + animation::Point initialPosition; + agd::assign (initialPosition, pointView); /* Reset, apply force and integrate */ - wgd::set <0> (forceView, 1.0); + agd::set <0> (forceView, 1.0); TestFixture::integrator.Reset (0); TestFixture::integrator.Step (0, 1.0, @@ -1523,16 +1523,16 @@ namespace TYPED_TEST (IntegrationStrategy, PositionChangesParabolicallyOverTime) { - wobbly::PointView forceView (TestFixture::forces, 0); - wobbly::PointView pointView (TestFixture::points, 0); + animation::PointView forceView (TestFixture::forces, 0); + animation::PointView pointView (TestFixture::points, 0); std::function frictionlessHorizontalPositionFunction = [this, &pointView, &forceView](int timestep) -> double { TypeParam integrator; /* Reset velocity and force */ - wgd::assign (pointView, wobbly::Point (0, 0)); - wgd::assign (forceView, wobbly::Vector (1.0f, 0)); + agd::assign (pointView, animation::Point (0, 0)); + agd::assign (forceView, animation::Vector (1.0f, 0)); integrator.Step (0, timestep, @@ -1541,7 +1541,7 @@ namespace TestFixture::points, TestFixture::forces); - return wgd::get <0> (pointView); + return agd::get <0> (pointView); }; EXPECT_THAT (frictionlessHorizontalPositionFunction, @@ -1556,7 +1556,7 @@ namespace wobbly::AnchorArray anchors; double const springConstant = 1.0; double const springFriction = 1.0; - wobbly::Vector const springDimensions (10.0, 10.0); + animation::Vector const springDimensions (10.0, 10.0); positions.fill (0.0); diff --git a/tests/point_test.cpp b/tests/wobbly/point_test.cpp similarity index 77% rename from tests/point_test.cpp rename to tests/wobbly/point_test.cpp index 7b1afc5..b022eee 100644 --- a/tests/point_test.cpp +++ b/tests/wobbly/point_test.cpp @@ -3,12 +3,12 @@ * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -27,7 +27,7 @@ #include // for AssertHelper, EXPECT_EQ, etc #include // for Values, Combine, etc -#include // for PointView +#include // for PointView using ::testing::Test; using ::testing::Values; @@ -35,7 +35,7 @@ using ::testing::WithParamInterface; namespace { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; class DoublePointView : public Test, @@ -57,16 +57,16 @@ namespace TEST_P (DoublePointView, WriteXWithOffset) { - wobbly::PointView pv (array, pointOffset); - wgd::set <0> (pv, 1.0); + animation::PointView pv (array, pointOffset); + agd::set <0> (pv, 1.0); EXPECT_EQ (array[arrayOffset], 1.0); } TEST_P (DoublePointView, WriteYWithOffset) { - wobbly::PointView pv (array, pointOffset); - wgd::set <1> (pv, 1.0); + animation::PointView pv (array, pointOffset); + agd::set <1> (pv, 1.0); EXPECT_EQ (array[arrayOffset + 1], 1.0); } @@ -79,9 +79,9 @@ namespace std::array array = { { 1, 2, 3, 4, 5, 6, 7, 8 } }; - wobbly::PointView mutpv (array, 1); - wobbly::PointView constpv (mutpv); + animation::PointView mutpv (array, 1); + animation::PointView constpv (mutpv); - EXPECT_TRUE (wgd::equals (mutpv, constpv)); + EXPECT_TRUE (agd::equals (mutpv, constpv)); } } diff --git a/tests/spring_test.cpp b/tests/wobbly/spring_test.cpp similarity index 55% rename from tests/spring_test.cpp rename to tests/wobbly/spring_test.cpp index 552c227..a251883 100644 --- a/tests/spring_test.cpp +++ b/tests/wobbly/spring_test.cpp @@ -1,14 +1,14 @@ /* - * tests/wobbly_test.cpp + * tests/spring_test.cpp * * Copyright 2018 Endless Mobile, Inc. * - * libwobbly is free software: you can redistribute it and/or + * libanimation is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 2.1 of the * License, or (at your option) any later version. * - * libwobbly is distributed in the hope that it will be useful, + * libanimation is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. @@ -32,8 +32,8 @@ #include // for AssertHelper, TEST_F, etc #include // IWYU pragma: keep -#include // for PointView, Point, Vector -#include // for Spring, etc +#include // for PointView, Point, Vector +#include // for Spring, etc #include // for Eq, EqDispatchHelper, etc #include // for operator<< @@ -42,14 +42,14 @@ using ::testing::ExitedWithCode; using ::testing::Not; using ::testing::Test; -using ::wobbly::matchers::Eq; -using ::wobbly::matchers::SatisfiesModel; +using ::animation::matchers::Eq; +using ::animation::matchers::SatisfiesModel; -using ::wobbly::models::Linear; +using ::animation::models::Linear; namespace { - namespace wgd = wobbly::geometry::dimension; + namespace agd = animation::geometry::dimension; class SingleObjectStorage { @@ -60,19 +60,19 @@ namespace storage.fill (0); } - wobbly::PointView Position () + animation::PointView Position () { - return wobbly::PointView (storage, 0); + return animation::PointView (storage, 0); } - wobbly::PointView Velocity () + animation::PointView Velocity () { - return wobbly::PointView (storage, 1); + return animation::PointView (storage, 1); } - wobbly::PointView Force () + animation::PointView Force () { - return wobbly::PointView (storage, 2); + return animation::PointView (storage, 2); } private: @@ -91,9 +91,9 @@ namespace { } - wobbly::PointView position; - wobbly::PointView velocity; - wobbly::PointView force; + animation::PointView position; + animation::PointView velocity; + animation::PointView force; }; constexpr double FirstPositionX = 50.0f; @@ -113,7 +113,7 @@ namespace storageB.Force (), storageA.Position (), storageB.Position (), - wobbly::Vector (0, 0)); + animation::Vector (0, 0)); wobbly::Spring b (std::move (a)); }); } @@ -134,17 +134,17 @@ namespace secondStorage.Position (), desiredDistance) { - wgd::assign (first.position, - wobbly::Point (FirstPositionX, - FirstPositionY)); - wgd::assign (second.position, - wobbly::Point (SecondPositionX, - SecondPositionY)); + agd::assign (first.position, + animation::Point (FirstPositionX, + FirstPositionY)); + agd::assign (second.position, + animation::Point (SecondPositionX, + SecondPositionY)); } protected: - wobbly::Vector desiredDistance; + animation::Vector desiredDistance; private: @@ -163,35 +163,35 @@ namespace spring.ApplyForces (SpringConstant); EXPECT_THAT (first.force, - Eq (wobbly::Vector (0, 0))); + Eq (animation::Vector (0, 0))); EXPECT_THAT (second.force, - Eq (wobbly::Vector (0, 0))); + Eq (animation::Vector (0, 0))); } template - wobbly::Vector - ForceForSpring (Position const &first, - Position const &second, - wobbly::Vector const &desired) + animation::Vector + ForceForSpring (Position const &first, + Position const &second, + animation::Vector const &desired) { - wobbly::Vector expectedForce; - wgd::assign (expectedForce, second); - wgd::pointwise_subtract (expectedForce, first); - wgd::pointwise_subtract (expectedForce, desired); - wgd::scale (expectedForce, SpringConstant); - wgd::scale (expectedForce, 1 / 2.0); + animation::Vector expectedForce; + agd::assign (expectedForce, second); + agd::pointwise_subtract (expectedForce, first); + agd::pointwise_subtract (expectedForce, desired); + agd::scale (expectedForce, SpringConstant); + agd::scale (expectedForce, 1 / 2.0); return expectedForce; } TEST_F (Springs, ForceAppliedToFirstObjectProportianalToPositiveDistanceSK) { - wgd::assign (first.position, - wobbly::Vector (FirstPositionX - 10.0f, - FirstPositionY - 10.0f)); - wobbly::Vector expectedForce (ForceForSpring (first.position, - second.position, - desiredDistance)); + agd::assign (first.position, + animation::Vector (FirstPositionX - 10.0f, + FirstPositionY - 10.0f)); + animation::Vector expectedForce (ForceForSpring (first.position, + second.position, + desiredDistance)); spring.ApplyForces (SpringConstant); @@ -200,14 +200,14 @@ namespace TEST_F (Springs, ForceAppliedToSecondObjectProportionalToNegativeDistanceSK) { - wgd::assign (first.position, wobbly::Vector (FirstPositionX - 10.0f, - FirstPositionY - 10.0f)); - wobbly::Vector negativeDistance (desiredDistance); - wgd::scale (negativeDistance, -1.0f); + agd::assign (first.position, animation::Vector (FirstPositionX - 10.0f, + FirstPositionY - 10.0f)); + animation::Vector negativeDistance (desiredDistance); + agd::scale (negativeDistance, -1.0f); - wobbly::Vector expectedForce (ForceForSpring (second.position, - first.position, - negativeDistance)); + animation::Vector expectedForce (ForceForSpring (second.position, + first.position, + negativeDistance)); spring.ApplyForces (SpringConstant); @@ -216,16 +216,16 @@ namespace TEST_F (Springs, ForceAccumulatesWithApplications) { - wgd::assign (first.position, - wobbly::Vector (FirstPositionX - 10.0f, - FirstPositionY - 10.0f)); - wobbly::Vector expectedForce (ForceForSpring (first.position, - second.position, - desiredDistance)); + agd::assign (first.position, + animation::Vector (FirstPositionX - 10.0f, + FirstPositionY - 10.0f)); + animation::Vector expectedForce (ForceForSpring (first.position, + second.position, + desiredDistance)); /* Scalar for single spring */ unsigned int const nApplications = 3; - wgd::scale (expectedForce, nApplications); + agd::scale (expectedForce, nApplications); for (unsigned int i = 0; i < nApplications; ++i) spring.ApplyForces (SpringConstant); @@ -237,18 +237,18 @@ namespace { std::function forceByDistanceFunction = [this](int delta) -> double { - wgd::assign (first.force, wobbly::Vector (0, 0)); - wgd::assign (second.force, wobbly::Vector (0, 0)); - wgd::assign (first.position, - wobbly::Vector (FirstPositionX - delta, - FirstPositionY)); - wgd::assign (second.position, - wobbly::Vector (SecondPositionX + delta, - SecondPositionY)); + agd::assign (first.force, animation::Vector (0, 0)); + agd::assign (second.force, animation::Vector (0, 0)); + agd::assign (first.position, + animation::Vector (FirstPositionX - delta, + FirstPositionY)); + agd::assign (second.position, + animation::Vector (SecondPositionX + delta, + SecondPositionY)); spring.ApplyForces (SpringConstant); - return wgd::get <0> (first.force); + return agd::get <0> (first.force); }; EXPECT_THAT (forceByDistanceFunction, @@ -260,11 +260,11 @@ namespace double const justBelowThreshold = FirstPositionX - wobbly::Spring::ClipThreshold * 1.1; - wgd::assign (first.position, - wobbly::Vector (justBelowThreshold, FirstPositionY)); + agd::assign (first.position, + animation::Vector (justBelowThreshold, FirstPositionY)); spring.ApplyForces (SpringConstant); - EXPECT_THAT (first.force, Eq (wobbly::Vector (0, 0))); + EXPECT_THAT (first.force, Eq (animation::Vector (0, 0))); } TEST_F (Springs, ApplyForcesReturnsTrueIfForceRemaining) @@ -272,9 +272,9 @@ namespace /* Change the position of one object, that will cause forces * to be exerted */ - wgd::assign (first.position, - wobbly::Vector (FirstPositionX - 10, - FirstPositionY)); + agd::assign (first.position, + animation::Vector (FirstPositionX - 10, + FirstPositionY)); EXPECT_TRUE (spring.ApplyForces (SpringConstant)); } @@ -289,8 +289,8 @@ namespace TEST_F (Springs, ForceExistsAfterLengthScaled) { - spring.ScaleLength (wobbly::Vector (SpringScaleFactor, - SpringScaleFactor)); + spring.ScaleLength (animation::Vector (SpringScaleFactor, + SpringScaleFactor)); EXPECT_TRUE (spring.ApplyForces (SpringConstant)); } @@ -298,15 +298,15 @@ namespace { /* Calculate distance between first and second, then adjust * second object's position to be distance * scaleFactor */ - wobbly::Vector distance; - wgd::assign (distance, second.position); - wgd::pointwise_subtract (distance, first.position); - wgd::pointwise_subtract (second.position, distance); - wgd::scale (distance, SpringScaleFactor); - wgd::pointwise_add (second.position, distance); - - spring.ScaleLength (wobbly::Vector (SpringScaleFactor, - SpringScaleFactor)); + animation::Vector distance; + agd::assign (distance, second.position); + agd::pointwise_subtract (distance, first.position); + agd::pointwise_subtract (second.position, distance); + agd::scale (distance, SpringScaleFactor); + agd::pointwise_add (second.position, distance); + + spring.ScaleLength (animation::Vector (SpringScaleFactor, + SpringScaleFactor)); EXPECT_FALSE (spring.ApplyForces (SpringConstant)); } } diff --git a/wobbly-glib/anchor.cpp b/wobbly-glib/anchor.cpp deleted file mode 100644 index 73e1de2..0000000 --- a/wobbly-glib/anchor.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * wobbly-glib/anchor.cpp - * - * Copyright 2018 Endless Mobile, Inc. - * - * libwobbly is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * libwobbly is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with eos-companion-app-service. If not, see - * . - * - * GObject Interface for "wobbly" textures, Anchor - * type implementation. - */ - -#include - -#include - -#include "wobbly-anchor-private.h" - -struct _WobblyAnchor -{ - GObject parent_instance; -}; - -typedef struct _WobblyAnchorPrivate -{ - wobbly::Anchor *anchor; -} WobblyAnchorPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (WobblyAnchor, - wobbly_anchor, - G_TYPE_OBJECT) - -/** - * wobbly_anchor_move_by: - * @anchor: A #WobblyAnchor - * @vector: A #WobblyVector to move the anchor by - * - * Move the anchor by @vector, causing force to be exerted - * on the underlying anchor's model. - */ -void -wobbly_anchor_move_by (WobblyAnchor *anchor, - WobblyVector vector) -{ - WobblyAnchorPrivate *priv = - reinterpret_cast (wobbly_anchor_get_instance_private (anchor)); - - if (priv->anchor != nullptr) - priv->anchor->MoveBy (wobbly::Point (vector.x, vector.y)); -} - - -/** - * wobbly_anchor_release: - * @anchor: A #WobblyAnchor - * - * Release the anchor, allowing the relevant control points - * to move freely and have force exerted on them. Attempting - * to move the anchor past this point is inert. - */ -void -wobbly_anchor_release (WobblyAnchor *anchor) -{ - WobblyAnchorPrivate *priv = - reinterpret_cast (wobbly_anchor_get_instance_private (anchor)); - - if (priv->anchor != nullptr) - { - delete priv->anchor; - priv->anchor = nullptr; - } -} - -static void -wobbly_anchor_finalize (GObject *object) -{ - WobblyAnchor *anchor = WOBBLY_ANCHOR (object); - - wobbly_anchor_release (anchor); - - G_OBJECT_CLASS (wobbly_anchor_parent_class)->finalize (object); -} - -static void -wobbly_anchor_init (WobblyAnchor *store) -{ -} - - -static void -wobbly_anchor_class_init (WobblyAnchorClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = wobbly_anchor_finalize; -} - -WobblyAnchor * -wobbly_anchor_new_for_native_anchor_rvalue (wobbly::Anchor &&anchor) -{ - WobblyAnchor *anchor_object = - WOBBLY_ANCHOR (g_object_new (WOBBLY_TYPE_ANCHOR, NULL)); - WobblyAnchorPrivate *priv = - reinterpret_cast (wobbly_anchor_get_instance_private (anchor_object)); - - priv->anchor = new wobbly::Anchor (std::move (anchor)); - - return anchor_object; -} diff --git a/wobbly-glib/anchor.h b/wobbly-glib/anchor.h deleted file mode 100644 index 7986a24..0000000 --- a/wobbly-glib/anchor.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * wobbly-glib/anchor.h - * - * GObject Interface for "wobbly" textures, Anchor type. - * - * An anchor is an object type privately holding an - * anchor. The owner can release the anchor, which happens - * implicitly when its ref-count drops to zero or when - * the release() method is called. - * - * See LICENCE.md for Copyright information - */ -#ifndef WOBBLY_GLIB_ANCHOR_H -#define WOBBLY_GLIB_ANCHOR_H - -#include - -#include - -G_BEGIN_DECLS - -#define WOBBLY_TYPE_ANCHOR wobbly_anchor_get_type () -G_DECLARE_FINAL_TYPE (WobblyAnchor, wobbly_anchor, WOBBLY, ANCHOR, GObject) - -void wobbly_anchor_move_by (WobblyAnchor *anchor, - WobblyVector vector); - -void wobbly_anchor_release (WobblyAnchor *anchor); - -G_END_DECLS - -#endif diff --git a/wobbly-glib/meson.build b/wobbly-glib/meson.build deleted file mode 100644 index c17933d..0000000 --- a/wobbly-glib/meson.build +++ /dev/null @@ -1,82 +0,0 @@ -# /wobbly-glib/meson.build -# -# Copyright (C) 2017, 2018 Endless Mobile, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Build the libwobbly library. - -api_version = '0.3' - -wobbly_introspectable_sources = [ - 'anchor.cpp', - 'model.cpp', - 'vector.cpp' -] - -wobbly_sources = wobbly_introspectable_sources + [ - 'wobbly-anchor-private.h' -] - -wobbly_headers = [ - 'anchor.h', - 'model.h', - 'vector.h' -] - -glib = dependency('glib-2.0') -gobject = dependency('gobject-2.0') - -wobbly_glib_lib = shared_library( - 'windowfx_wobbly_glib', - wobbly_sources, - soversion: api_version, - install: true, - include_directories: [ wobbly_inc ], - dependencies: [ glib, gobject, wobbly_dep ] -) - -install_headers(wobbly_headers, subdir: 'wobbly-glib') - -wobbly_glib_dep = declare_dependency( - link_with: wobbly_glib_lib, - include_directories: [ wobbly_inc ], -) - -introspection_sources = [ wobbly_introspectable_sources, wobbly_headers ] - -gnome = import('gnome') -gnome.generate_gir( - wobbly_glib_lib, - extra_args: ['--warn-all', '--warn-error'], - identifier_prefix: 'Wobbly', - include_directories: wobbly_inc, - includes: ['GLib-2.0', 'GObject-2.0'], - install: true, - namespace: 'Wobbly', - nsversion: api_version, - sources: introspection_sources, - symbol_prefix: 'wobbly' -) - -pkg = import('pkgconfig') -pkg.generate( - description: 'Library to provide a spring-controlled bezier mesh (GObject Binding)', - name: 'libwindowfx_wobbly_glib', - filebase: 'libwindowfx_wobbly_glib-' + api_version, - version: meson.project_version(), - libraries: wobbly_glib_lib, - install_dir: join_paths(get_option('libdir'), 'pkgconfig') -) diff --git a/wobbly-glib/model.cpp b/wobbly-glib/model.cpp deleted file mode 100644 index 89cc89d..0000000 --- a/wobbly-glib/model.cpp +++ /dev/null @@ -1,471 +0,0 @@ -/* - * wobbly-glib/wobbly.cpp - * - * Copyright 2018 Endless Mobile, Inc. - * - * libwobbly is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 2.1 of the - * License, or (at your option) any later version. - * - * libwobbly is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with eos-companion-app-service. If not, see - * . - * - * GObject Interface for "wobbly" textures - */ - -#include -#include -#include - -#include - -#include "wobbly-anchor-private.h" - -struct _WobblyModel -{ - GObject parent_instance; -}; - -typedef struct _WobblyModelPrivate -{ - wobbly::Model::Settings settings; - wobbly::Model *model; -} WobblyModelPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (WobblyModel, - wobbly_model, - G_TYPE_OBJECT) - -enum { - PROP_0, - PROP_SPRING_K, - PROP_FRICTION, - PROP_MAXIMUM_RANGE, - PROP_POSITION, - PROP_SIZE, - NPROPS -}; - -static GParamSpec *wobbly_model_props [NPROPS] = { NULL, }; - -namespace wgd = wobbly::geometry::dimension; - -/** - * wobbly_model_grab_anchor: - * @model: A #WobblyModel - * @position: A #WobblyVector specifying the position in absolute space - * where the closest object in the mesh should be grabbed. - * - * Grab the closest control point in the mesh to @position and - * return it as a #WobblyAnchor. The control point will not have spring - * force exerted upon it, though other control points will have forces - * exerted on them by the anchored control point. - * - * The control point remains grabbed until wobbly_anchor_release() is - * called on the anchor, or the anchor is destroyed. - * - * Returns: (transfer full): A #WobblyAnchor controlling the closest control - * point to @position. - */ -WobblyAnchor * -wobbly_model_grab_anchor (WobblyModel *model, - WobblyVector position) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - wobbly::Anchor anchor (priv->model->GrabAnchor (wobbly::Point (position.x, - position.y))); - - return wobbly_anchor_new_for_native_anchor_rvalue (std::move (anchor)); -} - -/** - * wobbly_model_insert_anchor: - * @model: A #WobblyModel - * @position: A #WobblyVector specifying the position in absolute space - * where the anchoring control point should be inserted - * - * Insert a new control point into the mesh at @position and split the - * closest spring to it in half, with both halves attaching to the - * inserted control point. The control point will not have spring - * force exerted upon it, though other control points will have forces - * exerted on them by the anchored control point. - * - * The control point remains in place until wobbly_anchor_release() is - * called on the anchor, or the anchor is destroyed. - * - * Returns: (transfer full): A #WobblyAnchor controlling the inserted control - * at @position. - */ -WobblyAnchor * -wobbly_model_insert_anchor (WobblyModel *model, - WobblyVector position) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - wobbly::Anchor anchor (priv->model->InsertAnchor (wobbly::Point (position.x, - position.y))); - - return wobbly_anchor_new_for_native_anchor_rvalue (std::move (anchor)); -} - -/** - * wobbly_model_step: - * @model: A #WobblyModel - * @ms: Time period to integrate over. - * - * Compute all the instantaneous forces exerted by springs in the - * mesh and integrate over @ms to determine the velocities and - * changes in model control point positions. - * - * Returns: %TRUE if further integration is required, %FALSE otherwise. - */ -gboolean -wobbly_model_step (WobblyModel *model, - unsigned int ms) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - return priv->model->Step (ms); -} - -/** - * wobbly_model_deform_texcoords: - * @model: A #WobblyModel - * @uv: A #WobblyVector specifying the unit coordinates relative to - * the top right corner of a square to be deformed. - * @deformed: (out caller-allocates): A #WobblyVector specifying the - * absolute position in space that the unit co-ordinate would - * be deformed to. - * - * Deform texture-coordinates into real space according to the model. - */ -void -wobbly_model_deform_texcoords (WobblyModel *model, - WobblyVector uv, - WobblyVector *deformed) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - g_return_if_fail (deformed != NULL); - - wobbly::Point deformed_point (priv->model->DeformTexcoords (wobbly::Point (uv.x, uv.y))); - *deformed = { - wobbly::geometry::dimension::get <0> (deformed_point), - wobbly::geometry::dimension::get <1> (deformed_point) - }; -} - -/** - * wobbly_model_deform_query_extremes: - * @model: A #WobblyModel - * @uv: A #WobblyVector specifying the unit coordinates relative to - * the top right corner of a square to be deformed. - * @top_left: (out caller-allocates): The top left extreme. - * @top_right: (out caller-allocates): The top right extreme. - * @bottom_left: (out caller-allocates): The bottom left extreme. - * @bottom_right: (out caller-allocates): The bottom right extreme. - * - * Query the bounding 4-vertex polygon around the model. - */ -void -wobbly_model_query_extremes (WobblyModel *model, - WobblyVector *top_left, - WobblyVector *top_right, - WobblyVector *bottom_left, - WobblyVector *bottom_right) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - std::array extremes (priv->model->Extremes ()); - - if (top_left != nullptr) - *top_left = { wgd::get <0> (extremes[0]), wgd::get <1> (extremes[0]) }; - - if (top_right != nullptr) - *top_right = { wgd::get <0> (extremes[1]), wgd::get <1> (extremes[1]) }; - - if (bottom_left != nullptr) - *bottom_left = { wgd::get <0> (extremes[2]), wgd::get <1> (extremes[2]) }; - - if (bottom_right != nullptr) - *bottom_right = { wgd::get <0> (extremes[3]), wgd::get <1> (extremes[3]) }; -} - -/** - * wobbly_model_move_to: - * @model: A #WobblyModel - * @position: A #WobblyVector to move the top right corner to. - * - * Move the entire model to have its top right corner at @position - * without causing any deformation. - */ -void -wobbly_model_move_to (WobblyModel *model, - WobblyVector position) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - if (priv->model != nullptr) - priv->model->MoveModelTo (wobbly::Point (position.x, position.y)); -} - -/** - * wobbly_model_move_by: - * @model: A #WobblyModel - * @delta: A #WobblyVector to move the top right corner by. - * - * Move the entire model by @position without causing any deformation. - */ -void -wobbly_model_move_by (WobblyModel *model, - WobblyVector delta) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - if (priv->model != nullptr) - priv->model->MoveModelBy (wobbly::Point (delta.x, delta.y)); -} - -/** - * wobbly_model_resize: - * @model: A #WobblyModel - * @size: A #WobblyVector specifying the size in each dimension. - * - * Resize the model according to @size. - */ -void -wobbly_model_resize (WobblyModel *model, - WobblyVector size) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - if (priv->model != nullptr) - priv->model->ResizeModel (size.x, size.y); -} - -void -wobbly_model_set_spring_k (WobblyModel *model, - double spring_constant) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - priv->settings.springConstant = spring_constant; -} - -void -wobbly_model_set_friction (WobblyModel *model, - double friction) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - priv->settings.friction = friction; -} - -void -wobbly_model_set_maximum_range (WobblyModel *model, - double range) -{ - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - priv->settings.maximumRange = range; -} - -static void -wobbly_model_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - WobblyModel *model = WOBBLY_MODEL (object); - - switch (prop_id) - { - case PROP_SPRING_K: - wobbly_model_set_spring_k (model, g_value_get_double (value)); - break; - case PROP_FRICTION: - wobbly_model_set_friction (model, g_value_get_double (value)); - break; - case PROP_MAXIMUM_RANGE: - wobbly_model_set_maximum_range (model, g_value_get_double (value)); - break; - case PROP_POSITION: - wobbly_model_move_to (model, *(reinterpret_cast (g_value_get_boxed (value)))); - break; - case PROP_SIZE: - wobbly_model_resize (model, *(reinterpret_cast (g_value_get_boxed (value)))); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -wobbly_model_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - WobblyModel *model = WOBBLY_MODEL (object); - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - switch (prop_id) - { - case PROP_SPRING_K: - g_value_set_double (value, priv->settings.springConstant); - break; - case PROP_FRICTION: - g_value_set_double (value, priv->settings.friction); - break; - case PROP_MAXIMUM_RANGE: - g_value_set_double (value, priv->settings.maximumRange); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -wobbly_model_finalize (GObject *object) -{ - WobblyModel *model = WOBBLY_MODEL (object); - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - delete priv->model; - priv->model = nullptr; - - G_OBJECT_CLASS (wobbly_model_parent_class)->finalize (object); -} - -static GObject * -wobbly_model_constructor (GType type, - guint n_construct_params, - GObjectConstructParam *construct_params) -{ - GObject *object = G_OBJECT_CLASS (wobbly_model_parent_class)->constructor (type, - n_construct_params, - construct_params); - - WobblyModel *model = WOBBLY_MODEL (object); - WobblyModelPrivate *priv = - reinterpret_cast (wobbly_model_get_instance_private (model)); - - WobblyVector prop_position = { 0, 0 }; - WobblyVector prop_size = { 1, 1 }; - - for (size_t i = 0; i < n_construct_params; ++i) - { - GParamSpec *pspec = construct_params[i].pspec; - GValue *value = construct_params[i].value; - - if (g_strcmp0 (pspec->name, "position") == 0) - prop_position = *(reinterpret_cast (g_value_get_boxed (value))); - - if (g_strcmp0 (pspec->name, "size") == 0) - prop_size = *(reinterpret_cast (g_value_get_boxed (value))); - } - - priv->model = new wobbly::Model (wobbly::Point (prop_position.x, - prop_position.y), - prop_size.x, - prop_size.y, - priv->settings); - - return object; -} - -static void -wobbly_model_init (WobblyModel *model) -{ -} - -static void -wobbly_model_class_init (WobblyModelClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructor = wobbly_model_constructor; - object_class->get_property = wobbly_model_get_property; - object_class->set_property = wobbly_model_set_property; - object_class->finalize = wobbly_model_finalize; - - wobbly_model_props[PROP_SPRING_K] = - g_param_spec_double ("spring-k", - "Spring Constant", - "Multiplier for force exerted by springs", - 0.1, - 10.0, - wobbly::Model::DefaultSpringConstant, - static_cast (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - wobbly_model_props[PROP_FRICTION] = - g_param_spec_double ("friction", - "Friction Constant", - "Multiplier for friction exerted by springs", - 0.1, - 10.0, - wobbly::Model::Friction, - static_cast (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - wobbly_model_props[PROP_MAXIMUM_RANGE] = - g_param_spec_double ("movement-range", - "Object Movement Range", - "How far away connected points can be from their rest point", - 10.0, - 1000.0, - wobbly::Model::DefaultObjectRange, - static_cast (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); - - wobbly_model_props[PROP_POSITION] = - g_param_spec_boxed ("position", - "Model position", - "Where the model is in absolute 2D space", - WOBBLY_TYPE_VECTOR, - static_cast (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); - - wobbly_model_props[PROP_SIZE] = - g_param_spec_boxed ("size", - "Model size", - "Where how big the model is in 2D space", - WOBBLY_TYPE_VECTOR, - static_cast (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)); - - g_object_class_install_properties (object_class, - NPROPS, - wobbly_model_props); -} - -WobblyModel * -wobbly_model_new (WobblyVector position, - WobblyVector size, - double spring_constant, - double friction, - double maximum_range) -{ - return WOBBLY_MODEL (g_object_new (WOBBLY_TYPE_MODEL, - "spring-k", spring_constant, - "friction", friction, - "movement-range", maximum_range, - "position", &position, - "size", &size, - nullptr)); -} diff --git a/wobbly-glib/model.h b/wobbly-glib/model.h deleted file mode 100644 index b27e778..0000000 --- a/wobbly-glib/model.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * wobbly-glib/model.h - * - * GObject Interface for "wobbly" textures - * - * See LICENCE.md for Copyright information - */ -#ifndef WOBBLY_GLIB_MODEL_H -#define WOBBLY_GLIB_MODEL_H - -#include - -#include -#include - -G_BEGIN_DECLS - -#define WOBBLY_TYPE_MODEL wobbly_model_get_type () -G_DECLARE_FINAL_TYPE (WobblyModel, wobbly_model, WOBBLY, MODEL, GObject) - -WobblyModel * wobbly_model_new (WobblyVector position, - WobblyVector size, - double spring_constant, - double friction, - double maximum_range); - -WobblyAnchor * wobbly_model_grab_anchor (WobblyModel *model, - WobblyVector position); - -WobblyAnchor * wobbly_model_insert_anchor (WobblyModel *model, - WobblyVector position); - -gboolean wobbly_model_step (WobblyModel *model, - unsigned int ms); - -void wobbly_model_deform_texcoords (WobblyModel *model, - WobblyVector uv, - WobblyVector *deformed); - -void wobbly_model_query_extremes (WobblyModel *model, - WobblyVector *top_left, - WobblyVector *top_right, - WobblyVector *bottom_left, - WobblyVector *bottom_right); - -void wobbly_model_move_to (WobblyModel *model, - WobblyVector position); -void wobbly_model_move_by (WobblyModel *model, - WobblyVector delta); - -void wobbly_model_resize (WobblyModel *model, - WobblyVector size); - -void wobbly_model_set_spring_k (WobblyModel *model, double spring_constant); - -void wobbly_model_set_friction (WobblyModel *model, double friction); - -void wobbly_model_set_maximum_range (WobblyModel *model, double range); - -G_END_DECLS - -#endif diff --git a/wobbly-glib/vector.h b/wobbly-glib/vector.h deleted file mode 100644 index 4c98462..0000000 --- a/wobbly-glib/vector.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * wobbly-glib/vector.h - * - * GObject Interface for "wobbly" textures, 2D vector type - * - * See LICENCE.md for Copyright information - */ -#ifndef WOBBLY_GLIB_VECTOR_H -#define WOBBLY_GLIB_VECTOR_H - -#include - -G_BEGIN_DECLS - -typedef struct { - double x; - double y; -} WobblyVector; - -#define WOBBLY_TYPE_VECTOR wobbly_vector_get_type () - -GType wobbly_vector_get_type (void); - -G_END_DECLS - -#endif diff --git a/wobbly-glib/wobbly-anchor-private.h b/wobbly-glib/wobbly-anchor-private.h deleted file mode 100644 index 25086c5..0000000 --- a/wobbly-glib/wobbly-anchor-private.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * wobbly-glib/anchor-private.h - * - * GObject Interface for "wobbly" textures, Anchor type. - * - * An anchor is an object type privately holding an - * anchor. The owner can release the anchor, which happens - * implicitly when its ref-count drops to zero or when - * the release() method is called. - * - * See LICENCE.md for Copyright information - */ - -#include - -#ifndef WOBBLY_GLIB_ANCHOR_PRIVATE_H -#define WOBBLY_GLIB_ANCHOR_PRIVATE_H - -WobblyAnchor * wobbly_anchor_new_for_native_anchor_rvalue (wobbly::Anchor &&anchor); - -#endif diff --git a/wobbly/third_party/allow_move_optional b/wobbly/third_party/allow_move_optional deleted file mode 160000 index 5965887..0000000 --- a/wobbly/third_party/allow_move_optional +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 59658878a862e666ab7b5b997b1518f8f8bd9853