<commit_before>
/* -*- mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Clutter.
 *
 * An OpenGL based 'interactive canvas' library.
 *
 * Authored By <NAME>  <<EMAIL>>
 *
 * Copyright (C) 2007 OpenedHand
 *
 * This library 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 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
 * SECTION:clutter-behaviour-ellipse
 * @short_description: A behaviour interpolating position along an ellipse
 *
 * #ClutterBehaviourEllipse interpolates actors along a path defined by
 *  an ellipse.
 *
 * <note><para>When applying an ellipse behaviour to an actor, the
 * behaviour will update the actor's position and depth and set them
 * to what is dictated by the ellipses initial position.</para></note>
 *
 * Since: 0.4
 */

#include "clutter-fixed.h"
#include "clutter-marshal.h"
#include "clutter-behaviour-ellipse.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-private.h"

#include <stdlib.h>
#include <memory.h>

/****************************************************************************
 *                                                                          *
 * ClutterBehaviourEllipse                                                  *
 *                                                                          *
 ****************************************************************************/

G_DEFINE_TYPE (ClutterBehaviourEllipse,
               clutter_behaviour_ellipse,
	       CLUTTER_TYPE_BEHAVIOUR);

#define CLUTTER_BEHAVIOUR_ELLIPSE_GET_PRIVATE(obj)    \
              (G_TYPE_INSTANCE_GET_PRIVATE ((obj),    \
               CLUTTER_TYPE_BEHAVIOUR_ELLIPSE,        \
               ClutterBehaviourEllipsePrivate))

enum
{
  PROP_0,

  PROP_CENTER,
  PROP_WIDTH,
  PROP_HEIGHT,
  PROP_ANGLE_START,
  PROP_ANGLE_END,
  PROP_ANGLE_TILT_X,
  PROP_ANGLE_TILT_Y,
  PROP_ANGLE_TILT_Z,
  PROP_DIRECTION,
};

struct _ClutterBehaviourEllipsePrivate
{
  ClutterKnot  center;

  gint         a;
  gint         b;

  float angle_start;
  float angle_end;
  float angle_tilt_x;
  float angle_tilt_y;
  float angle_tilt_z;

  ClutterRotateDirection direction;
};

typedef struct _knot3d
{
  gint x;
  gint y;
  gint z;
} knot3d;

static void
clutter_behaviour_ellipse_advance (ClutterBehaviourEllipse *e,
                                   float             angle,
                                   knot3d                  *knot)
{
  ClutterBehaviourEllipsePrivate *priv = e->priv;
  gint x, y, z;

  x =  (priv->a * cosf (angle * (G_PI/180.0)));
  y =  (priv->b * sinf (angle * (G_PI/180.0)));
  z = 0;

  if (priv->angle_tilt_z)
    {
      /*
       * x2 = r * cos (angle + tilt_z)
       * y2 = r * sin (angle + tilt_z)
       *
       * These can be trasformed to the formulas below using properties of
       * sin (a + b) and cos (a + b)
       *
       */
      ClutterFixed x2, y2;

      x2 = x * cosf (priv->angle_tilt_z * (G_PI/180.0))
         - y * sinf (priv->angle_tilt_z * (G_PI/180.0));

      y2 = y * cosf (priv->angle_tilt_z * (G_PI/180.0))
         + x * sinf (priv->angle_tilt_z * (G_PI/180.0));

      x =  (x2);
      y =  (y2);
    }

  if (priv->angle_tilt_x)
    {
      ClutterFixed z2, y2;

      z2 = - y * sinf (priv->angle_tilt_x * (G_PI/180.0));

      y2 = y * cosf (priv->angle_tilt_x * (G_PI/180.0));

      z =  (z2);
      y =  (y2);
    }

  if (priv->angle_tilt_y)
    {
      ClutterFixed x2, z2;

      x2 = x * cosf (priv->angle_tilt_y * (G_PI/180.0))
         - z * sinf (priv->angle_tilt_y * (G_PI/180.0));

      z2 = z * cosf (priv->angle_tilt_y * (G_PI/180.0))
         + x * sinf (priv->angle_tilt_y * (G_PI/180.0));

      x =  (x2);
      z =  (z2);
    }

  knot->x = x;
  knot->y = y;
  knot->z = z;

  CLUTTER_NOTE (BEHAVIOUR, "advancing to angle %d [%d, %d] (a: %d, b: %d)",
                angle,
                knot->x, knot->y,
                priv->a, priv->b);
}


static void
actor_apply_knot_foreach (ClutterBehaviour *behave,
                          ClutterActor     *actor,
                          gpointer          data)
{
  ClutterBehaviourEllipsePrivate *priv
    = ((ClutterBehaviourEllipse *) behave)->priv;
  knot3d *knot = data;
<commit_msg>Fix the format for a floating point value<commit_after>
/* -*- mode:C; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Clutter.
 *
 * An OpenGL based 'interactive canvas' library.
 *
 * Authored By <NAME>  <<EMAIL>>
 *
 * Copyright (C) 2007 OpenedHand
 *
 * This library 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 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
 * SECTION:clutter-behaviour-ellipse
 * @short_description: A behaviour interpolating position along an ellipse
 *
 * #ClutterBehaviourEllipse interpolates actors along a path defined by
 *  an ellipse.
 *
 * <note><para>When applying an ellipse behaviour to an actor, the
 * behaviour will update the actor's position and depth and set them
 * to what is dictated by the ellipses initial position.</para></note>
 *
 * Since: 0.4
 */

#include "clutter-fixed.h"
#include "clutter-marshal.h"
#include "clutter-behaviour-ellipse.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-private.h"

#include <stdlib.h>
#include <memory.h>

/****************************************************************************
 *                                                                          *
 * ClutterBehaviourEllipse                                                  *
 *                                                                          *
 ****************************************************************************/

G_DEFINE_TYPE (ClutterBehaviourEllipse,
               clutter_behaviour_ellipse,
	       CLUTTER_TYPE_BEHAVIOUR);

#define CLUTTER_BEHAVIOUR_ELLIPSE_GET_PRIVATE(obj)    \
              (G_TYPE_INSTANCE_GET_PRIVATE ((obj),    \
               CLUTTER_TYPE_BEHAVIOUR_ELLIPSE,        \
               ClutterBehaviourEllipsePrivate))

enum
{
  PROP_0,

  PROP_CENTER,
  PROP_WIDTH,
  PROP_HEIGHT,
  PROP_ANGLE_START,
  PROP_ANGLE_END,
  PROP_ANGLE_TILT_X,
  PROP_ANGLE_TILT_Y,
  PROP_ANGLE_TILT_Z,
  PROP_DIRECTION,
};

struct _ClutterBehaviourEllipsePrivate
{
  ClutterKnot  center;

  gint         a;
  gint         b;

  float angle_start;
  float angle_end;
  float angle_tilt_x;
  float angle_tilt_y;
  float angle_tilt_z;

  ClutterRotateDirection direction;
};

typedef struct _knot3d
{
  gint x;
  gint y;
  gint z;
} knot3d;

static void
clutter_behaviour_ellipse_advance (ClutterBehaviourEllipse *e,
                                   float                    angle,
                                   knot3d                  *knot)
{
  ClutterBehaviourEllipsePrivate *priv = e->priv;
  gint x, y, z;

  x =  (priv->a * cosf (angle * (G_PI/180.0)));
  y =  (priv->b * sinf (angle * (G_PI/180.0)));
  z = 0;

  if (priv->angle_tilt_z)
    {
      /*
       * x2 = r * cos (angle + tilt_z)
       * y2 = r * sin (angle + tilt_z)
       *
       * These can be trasformed to the formulas below using properties of
       * sin (a + b) and cos (a + b)
       *
       */
      ClutterFixed x2, y2;

      x2 = x * cosf (priv->angle_tilt_z * (G_PI/180.0))
         - y * sinf (priv->angle_tilt_z * (G_PI/180.0));

      y2 = y * cosf (priv->angle_tilt_z * (G_PI/180.0))
         + x * sinf (priv->angle_tilt_z * (G_PI/180.0));

      x =  (x2);
      y =  (y2);
    }

  if (priv->angle_tilt_x)
    {
      ClutterFixed z2, y2;

      z2 = - y * sinf (priv->angle_tilt_x * (G_PI/180.0));

      y2 = y * cosf (priv->angle_tilt_x * (G_PI/180.0));

      z =  (z2);
      y =  (y2);
    }

  if (priv->angle_tilt_y)
    {
      ClutterFixed x2, z2;

      x2 = x * cosf (priv->angle_tilt_y * (G_PI/180.0))
         - z * sinf (priv->angle_tilt_y * (G_PI/180.0));

      z2 = z * cosf (priv->angle_tilt_y * (G_PI/180.0))
         + x * sinf (priv->angle_tilt_y * (G_PI/180.0));

      x =  (x2);
      z =  (z2);
    }

  knot->x = x;
  knot->y = y;
  knot->z = z;

  CLUTTER_NOTE (BEHAVIOUR, "advancing to angle %.2f [%d, %d] (a: %d, b: %d)",
                angle,
                knot->x, knot->y,
                priv->a, priv->b);
}


static void
actor_apply_knot_foreach (ClutterBehaviour *behave,
                          ClutterActor     *actor,
                          gpointer          data)
{
  ClutterBehaviourEllipsePrivate *priv
    = ((ClutterBehaviourEllipse *) behave)->priv;
  knot3d *knot = data;

{'fraction_non_alphanumeric': 0.13874318625938498, 'fraction_numerical': 0.019644142754293943, 'mean_word_length': 2.16742671009772, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2473223', 'n_tokens_mistral': 3532, 'n_tokens_neox': 3284, 'n_words': 849}