2000-02-15 00:29:41 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
2001-02-14 22:57:14 +08:00
|
|
|
* gimpvector.c
|
|
|
|
*
|
2000-02-15 00:29:41 +08:00
|
|
|
* The gimp_vector* functions were taken from:
|
|
|
|
* GCK - The General Convenience Kit
|
|
|
|
* Copyright (C) 1996 Tom Bech
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2000-02-15 00:29:41 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2000-02-15 00:29:41 +08:00
|
|
|
*
|
|
|
|
* 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
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2000-02-15 00:29:41 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**********************************************/
|
|
|
|
/* A little collection of useful vector stuff */
|
|
|
|
/**********************************************/
|
|
|
|
|
2002-05-14 07:30:23 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-01-22 08:43:31 +08:00
|
|
|
#include <glib-object.h>
|
2000-05-31 07:38:46 +08:00
|
|
|
|
2000-02-15 00:29:41 +08:00
|
|
|
#include "gimpmath.h"
|
|
|
|
|
2000-05-31 07:38:46 +08:00
|
|
|
|
2010-07-02 20:41:35 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimpvector
|
|
|
|
* @title: GimpVector
|
|
|
|
* @short_description: Utilities to set up and manipulate vectors.
|
|
|
|
* @see_also: #GimpMatrix2, #GimpMatrix3, #GimpMatrix4
|
|
|
|
*
|
|
|
|
* Utilities to set up and manipulate vectors.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
2019-08-02 09:44:56 +08:00
|
|
|
static gpointer gimp_vector2_copy (gpointer boxed);
|
|
|
|
static void gimp_vector2_free (gpointer boxed);
|
|
|
|
static gpointer gimp_vector3_copy (gpointer boxed);
|
|
|
|
static void gimp_vector3_free (gpointer boxed);
|
|
|
|
|
|
|
|
|
2000-02-15 00:29:41 +08:00
|
|
|
/*************************/
|
|
|
|
/* Some useful constants */
|
|
|
|
/*************************/
|
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
static const GimpVector2 gimp_vector2_zero = { 0.0, 0.0 };
|
2016-10-31 08:08:38 +08:00
|
|
|
#if 0
|
2000-02-15 01:43:55 +08:00
|
|
|
static const GimpVector2 gimp_vector2_unit_x = { 1.0, 0.0 };
|
|
|
|
static const GimpVector2 gimp_vector2_unit_y = { 0.0, 1.0 };
|
2016-10-31 08:08:38 +08:00
|
|
|
#endif
|
2000-02-15 00:29:41 +08:00
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
static const GimpVector3 gimp_vector3_zero = { 0.0, 0.0, 0.0 };
|
2016-10-31 08:08:38 +08:00
|
|
|
#if 0
|
2000-02-15 01:43:55 +08:00
|
|
|
static const GimpVector3 gimp_vector3_unit_x = { 1.0, 0.0, 0.0 };
|
|
|
|
static const GimpVector3 gimp_vector3_unit_y = { 0.0, 1.0, 0.0 };
|
|
|
|
static const GimpVector3 gimp_vector3_unit_z = { 0.0, 0.0, 1.0 };
|
2016-10-31 08:08:38 +08:00
|
|
|
#endif
|
2000-02-15 00:29:41 +08:00
|
|
|
|
|
|
|
/**************************************/
|
2003-09-28 06:22:59 +08:00
|
|
|
/* Two dimensional vector functions */
|
2000-02-15 00:29:41 +08:00
|
|
|
/**************************************/
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_new:
|
|
|
|
* @x: the X coordinate.
|
|
|
|
* @y: the Y coordinate.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Creates a #GimpVector2 of coordinates @x and @y.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the resulting #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector2
|
|
|
|
gimp_vector2_new (gdouble x,
|
|
|
|
gdouble y)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector2 vector;
|
|
|
|
|
|
|
|
vector.x = x;
|
|
|
|
vector.y = y;
|
|
|
|
|
|
|
|
return vector;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_set:
|
|
|
|
* @vector: a pointer to a #GimpVector2.
|
|
|
|
* @x: the X coordinate.
|
|
|
|
* @y: the Y coordinate.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Sets the X and Y coordinates of @vector to @x and @y.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
void
|
|
|
|
gimp_vector2_set (GimpVector2 *vector,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
vector->x = x;
|
|
|
|
vector->y = y;
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_length:
|
|
|
|
* @vector: a pointer to a #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Computes the length of a 2D vector.
|
2003-09-28 07:02:39 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the length of @vector (a positive gdouble).
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
gdouble
|
|
|
|
gimp_vector2_length (const GimpVector2 *vector)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
return (sqrt (vector->x * vector->x + vector->y * vector->y));
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_length_val:
|
|
|
|
* @vector: a #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_length() but the
|
|
|
|
* vector is passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the length of @vector (a positive gdouble).
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
gdouble
|
|
|
|
gimp_vector2_length_val (GimpVector2 vector)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
return (sqrt (vector.x * vector.x + vector.y * vector.y));
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_mul:
|
|
|
|
* @vector: a pointer to a #GimpVector2.
|
|
|
|
* @factor: a scalar.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Multiplies each component of the @vector by @factor. Note that this
|
|
|
|
* is equivalent to multiplying the vectors length by @factor.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
void
|
|
|
|
gimp_vector2_mul (GimpVector2 *vector,
|
|
|
|
gdouble factor)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
vector->x *= factor;
|
|
|
|
vector->y *= factor;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_mul_val:
|
|
|
|
* @vector: a #GimpVector2.
|
|
|
|
* @factor: a scalar.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_mul() but the vector is
|
|
|
|
* passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the resulting #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector2
|
|
|
|
gimp_vector2_mul_val (GimpVector2 vector,
|
|
|
|
gdouble factor)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector2 result;
|
|
|
|
|
|
|
|
result.x = vector.x * factor;
|
|
|
|
result.y = vector.y * factor;
|
|
|
|
|
|
|
|
return result;
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector2_normalize:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a pointer to a #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Normalizes the @vector so the length of the @vector is 1.0. The nul
|
|
|
|
* vector will not be changed.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2000-02-15 01:43:55 +08:00
|
|
|
gimp_vector2_normalize (GimpVector2 *vector)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
|
|
|
gdouble len;
|
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
len = gimp_vector2_length (vector);
|
2003-07-07 22:20:39 +08:00
|
|
|
|
2003-09-28 07:02:39 +08:00
|
|
|
if (len != 0.0)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
|
|
|
len = 1.0 / len;
|
2000-02-15 01:43:55 +08:00
|
|
|
vector->x *= len;
|
|
|
|
vector->y *= len;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-02-15 01:43:55 +08:00
|
|
|
*vector = gimp_vector2_zero;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector2_normalize_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a #GimpVector2.
|
2003-09-28 07:02:39 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_normalize() but the
|
|
|
|
* vector is passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Returns: a #GimpVector2 parallel to @vector, pointing in the same
|
2003-11-15 23:30:34 +08:00
|
|
|
* direction but with a length of 1.0.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2001-01-26 10:16:13 +08:00
|
|
|
GimpVector2
|
|
|
|
gimp_vector2_normalize_val (GimpVector2 vector)
|
|
|
|
{
|
|
|
|
GimpVector2 normalized;
|
2003-07-07 22:20:39 +08:00
|
|
|
gdouble len;
|
2001-01-26 10:16:13 +08:00
|
|
|
|
|
|
|
len = gimp_vector2_length_val (vector);
|
2003-07-07 22:20:39 +08:00
|
|
|
|
2003-09-28 07:02:39 +08:00
|
|
|
if (len != 0.0)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
|
|
|
len = 1.0 / len;
|
|
|
|
normalized.x = vector.x * len;
|
|
|
|
normalized.y = vector.y * len;
|
|
|
|
return normalized;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return gimp_vector2_zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_neg:
|
|
|
|
* @vector: a pointer to a #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Negates the @vector (i.e. negate all its coordinates).
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector2_neg (GimpVector2 *vector)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
vector->x *= -1.0;
|
|
|
|
vector->y *= -1.0;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_neg_val:
|
|
|
|
* @vector: a #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_neg() but the vector
|
|
|
|
* is passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the negated #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2001-01-26 10:16:13 +08:00
|
|
|
GimpVector2
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector2_neg_val (GimpVector2 vector)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
|
|
|
GimpVector2 result;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
result.x = vector.x * -1.0;
|
|
|
|
result.y = vector.y * -1.0;
|
2003-07-07 22:20:39 +08:00
|
|
|
|
2001-01-26 10:16:13 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector2_add:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @result: destination for the resulting #GimpVector2.
|
|
|
|
* @vector1: a pointer to the first #GimpVector2.
|
|
|
|
* @vector2: a pointer to the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Computes the sum of two 2D vectors. The resulting #GimpVector2 is
|
|
|
|
* stored in @result.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_vector2_add (GimpVector2 *result,
|
2003-09-28 07:02:39 +08:00
|
|
|
const GimpVector2 *vector1,
|
|
|
|
const GimpVector2 *vector2)
|
2003-09-28 06:22:59 +08:00
|
|
|
{
|
|
|
|
result->x = vector1->x + vector2->x;
|
|
|
|
result->y = vector1->y + vector2->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_vector2_add_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector1: the first #GimpVector2.
|
|
|
|
* @vector2: the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_add() but the vectors
|
|
|
|
* are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Returns: the resulting #GimpVector2.
|
|
|
|
**/
|
|
|
|
GimpVector2
|
|
|
|
gimp_vector2_add_val (GimpVector2 vector1,
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector2 vector2)
|
2003-09-28 06:22:59 +08:00
|
|
|
{
|
|
|
|
GimpVector2 result;
|
|
|
|
|
|
|
|
result.x = vector1.x + vector2.x;
|
|
|
|
result.y = vector1.y + vector2.y;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_vector2_sub:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @result: the destination for the resulting #GimpVector2.
|
|
|
|
* @vector1: a pointer to the first #GimpVector2.
|
|
|
|
* @vector2: a pointer to the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Computes the difference of two 2D vectors (@vector1 minus @vector2).
|
2003-11-15 23:30:34 +08:00
|
|
|
* The resulting #GimpVector2 is stored in @result.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2003-07-07 22:20:39 +08:00
|
|
|
gimp_vector2_sub (GimpVector2 *result,
|
2003-09-28 07:02:39 +08:00
|
|
|
const GimpVector2 *vector1,
|
|
|
|
const GimpVector2 *vector2)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2000-02-15 01:43:55 +08:00
|
|
|
result->x = vector1->x - vector2->x;
|
|
|
|
result->y = vector1->y - vector2->y;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector2_sub_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector1: the first #GimpVector2.
|
|
|
|
* @vector2: the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_sub() but the vectors
|
|
|
|
* are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Returns: the resulting #GimpVector2.
|
|
|
|
**/
|
2001-01-26 10:16:13 +08:00
|
|
|
GimpVector2
|
|
|
|
gimp_vector2_sub_val (GimpVector2 vector1,
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector2 vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
|
|
|
GimpVector2 result;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2001-01-26 10:16:13 +08:00
|
|
|
result.x = vector1.x - vector2.x;
|
|
|
|
result.y = vector1.y - vector2.y;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2001-01-26 10:16:13 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_inner_product:
|
|
|
|
* @vector1: a pointer to the first #GimpVector2.
|
|
|
|
* @vector2: a pointer to the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Computes the inner (dot) product of two 2D vectors.
|
2018-09-21 00:08:54 +08:00
|
|
|
* This product is zero if and only if the two vectors are orthogonal.
|
2003-11-15 23:30:34 +08:00
|
|
|
*
|
|
|
|
* Returns: The inner product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
gdouble
|
|
|
|
gimp_vector2_inner_product (const GimpVector2 *vector1,
|
|
|
|
const GimpVector2 *vector2)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
return (vector1->x * vector2->x + vector1->y * vector2->y);
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_inner_product_val:
|
|
|
|
* @vector1: the first #GimpVector2.
|
|
|
|
* @vector2: the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_inner_product() but the
|
|
|
|
* vectors are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: The inner product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
gdouble
|
|
|
|
gimp_vector2_inner_product_val (GimpVector2 vector1,
|
|
|
|
GimpVector2 vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
return (vector1.x * vector2.x + vector1.y * vector2.y);
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_cross_product:
|
|
|
|
* @vector1: a pointer to the first #GimpVector2.
|
|
|
|
* @vector2: a pointer to the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Compute the cross product of two vectors. The result is a
|
2018-09-21 00:08:54 +08:00
|
|
|
* #GimpVector2 which is orthogonal to both @vector1 and @vector2. If
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector1 and @vector2 are parallel, the result will be the nul
|
|
|
|
* vector.
|
|
|
|
*
|
|
|
|
* Note that in 2D, this function is useful to test if two vectors are
|
|
|
|
* parallel or not, or to compute the area spawned by two vectors.
|
|
|
|
*
|
|
|
|
* Returns: The cross product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector2
|
|
|
|
gimp_vector2_cross_product (const GimpVector2 *vector1,
|
|
|
|
const GimpVector2 *vector2)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector2 normal;
|
|
|
|
|
|
|
|
normal.x = vector1->x * vector2->y - vector1->y * vector2->x;
|
|
|
|
normal.y = vector1->y * vector2->x - vector1->x * vector2->y;
|
|
|
|
|
|
|
|
return normal;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector2_cross_product_val:
|
|
|
|
* @vector1: the first #GimpVector2.
|
|
|
|
* @vector2: the second #GimpVector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_cross_product() but the
|
|
|
|
* vectors are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: The cross product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector2
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector2_cross_product_val (GimpVector2 vector1,
|
|
|
|
GimpVector2 vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector2 normal;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
normal.x = vector1.x * vector2.y - vector1.y * vector2.x;
|
|
|
|
normal.y = vector1.y * vector2.x - vector1.x * vector2.y;
|
2001-01-26 10:16:13 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
return normal;
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector2_rotate:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a pointer to a #GimpVector2.
|
|
|
|
* @alpha: an angle (in radians).
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Rotates the @vector counterclockwise by @alpha radians.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2000-02-15 01:43:55 +08:00
|
|
|
gimp_vector2_rotate (GimpVector2 *vector,
|
2003-09-28 07:02:39 +08:00
|
|
|
gdouble alpha)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2000-02-15 01:43:55 +08:00
|
|
|
GimpVector2 result;
|
2000-02-15 00:29:41 +08:00
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
result.x = cos (alpha) * vector->x + sin (alpha) * vector->y;
|
|
|
|
result.y = cos (alpha) * vector->y - sin (alpha) * vector->x;
|
2000-02-15 00:29:41 +08:00
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
*vector = result;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector2_rotate_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a #GimpVector2.
|
|
|
|
* @alpha: an angle (in radians).
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector2_rotate() but the vector
|
|
|
|
* is passed by value rather than by reference.
|
2003-09-28 07:02:39 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: a #GimpVector2 representing @vector rotated by @alpha
|
|
|
|
* radians.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2001-01-26 10:16:13 +08:00
|
|
|
GimpVector2
|
|
|
|
gimp_vector2_rotate_val (GimpVector2 vector,
|
2003-09-28 07:02:39 +08:00
|
|
|
gdouble alpha)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
|
|
|
GimpVector2 result;
|
|
|
|
|
|
|
|
result.x = cos (alpha) * vector.x + sin (alpha) * vector.y;
|
|
|
|
result.y = cos (alpha) * vector.y - sin (alpha) * vector.x;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-07-15 05:51:04 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector2_normal:
|
|
|
|
* @vector: a pointer to a #GimpVector2.
|
|
|
|
*
|
|
|
|
* Compute a normalized perpendicular vector to @vector
|
|
|
|
*
|
|
|
|
* Returns: a #GimpVector2 perpendicular to @vector, with a length of 1.0.
|
2015-05-31 20:40:20 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.8
|
2010-07-15 05:51:04 +08:00
|
|
|
**/
|
|
|
|
GimpVector2
|
2015-05-31 20:40:20 +08:00
|
|
|
gimp_vector2_normal (GimpVector2 *vector)
|
2010-07-15 05:51:04 +08:00
|
|
|
{
|
|
|
|
GimpVector2 result;
|
2010-08-15 03:24:59 +08:00
|
|
|
|
|
|
|
result.x = - vector->y;
|
|
|
|
result.y = vector->x;
|
|
|
|
|
|
|
|
gimp_vector2_normalize (&result);
|
|
|
|
|
2010-07-15 05:51:04 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_vector2_normal_val:
|
|
|
|
* @vector: a #GimpVector2.
|
|
|
|
*
|
|
|
|
* This function is identical to gimp_vector2_normal() but the vector
|
|
|
|
* is passed by value rather than by reference.
|
|
|
|
*
|
|
|
|
* Returns: a #GimpVector2 perpendicular to @vector, with a length of 1.0.
|
2010-11-05 02:25:32 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.8
|
2010-07-15 05:51:04 +08:00
|
|
|
**/
|
|
|
|
GimpVector2
|
2015-05-31 20:40:20 +08:00
|
|
|
gimp_vector2_normal_val (GimpVector2 vector)
|
2010-07-15 05:51:04 +08:00
|
|
|
{
|
|
|
|
GimpVector2 result;
|
2010-08-15 03:24:59 +08:00
|
|
|
|
|
|
|
result.x = - vector.y;
|
|
|
|
result.y = vector.x;
|
|
|
|
|
2010-07-15 05:51:04 +08:00
|
|
|
gimp_vector2_normalize (&result);
|
2010-08-15 03:24:59 +08:00
|
|
|
|
2010-07-15 05:51:04 +08:00
|
|
|
return result;
|
|
|
|
}
|
2000-02-15 00:29:41 +08:00
|
|
|
/**************************************/
|
|
|
|
/* Three dimensional vector functions */
|
|
|
|
/**************************************/
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_new:
|
|
|
|
* @x: the X coordinate.
|
|
|
|
* @y: the Y coordinate.
|
|
|
|
* @z: the Z coordinate.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Creates a #GimpVector3 of coordinate @x, @y and @z.
|
2003-09-28 07:02:39 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the resulting #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
GimpVector3
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector3_new (gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble z)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector3 vector;
|
2000-02-15 00:29:41 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
vector.x = x;
|
|
|
|
vector.y = y;
|
|
|
|
vector.z = z;
|
2000-02-15 00:29:41 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
return vector;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_set:
|
|
|
|
* @vector: a pointer to a #GimpVector3.
|
|
|
|
* @x: the X coordinate.
|
|
|
|
* @y: the Y coordinate.
|
|
|
|
* @z: the Z coordinate.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Sets the X, Y and Z coordinates of @vector to @x, @y and @z.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
void
|
|
|
|
gimp_vector3_set (GimpVector3 *vector,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble z)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
vector->x = x;
|
|
|
|
vector->y = y;
|
|
|
|
vector->z = z;
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_length:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a pointer to a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Computes the length of a 3D vector.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the length of @vector (a positive gdouble).
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
gdouble
|
2003-07-07 22:20:39 +08:00
|
|
|
gimp_vector3_length (const GimpVector3 *vector)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2000-02-15 01:43:55 +08:00
|
|
|
return (sqrt (vector->x * vector->x +
|
2003-09-28 07:02:39 +08:00
|
|
|
vector->y * vector->y +
|
|
|
|
vector->z * vector->z));
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_length_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector3_length() but the vector
|
|
|
|
* is passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: the length of @vector (a positive gdouble).
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2001-01-26 10:16:13 +08:00
|
|
|
gdouble
|
|
|
|
gimp_vector3_length_val (GimpVector3 vector)
|
|
|
|
{
|
|
|
|
return (sqrt (vector.x * vector.x +
|
2003-09-28 07:02:39 +08:00
|
|
|
vector.y * vector.y +
|
|
|
|
vector.z * vector.z));
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_mul:
|
|
|
|
* @vector: a pointer to a #GimpVector3.
|
|
|
|
* @factor: a scalar.
|
|
|
|
*
|
|
|
|
* Multiplies each component of the @vector by @factor. Note that
|
|
|
|
* this is equivalent to multiplying the vectors length by @factor.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_vector3_mul (GimpVector3 *vector,
|
|
|
|
gdouble factor)
|
|
|
|
{
|
|
|
|
vector->x *= factor;
|
|
|
|
vector->y *= factor;
|
|
|
|
vector->z *= factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_vector3_mul_val:
|
|
|
|
* @vector: a #GimpVector3.
|
|
|
|
* @factor: a scalar.
|
|
|
|
*
|
|
|
|
* This function is identical to gimp_vector3_mul() but the vector is
|
|
|
|
* passed by value rather than by reference.
|
|
|
|
*
|
|
|
|
* Returns: the resulting #GimpVector3.
|
|
|
|
**/
|
|
|
|
GimpVector3
|
|
|
|
gimp_vector3_mul_val (GimpVector3 vector,
|
|
|
|
gdouble factor)
|
|
|
|
{
|
|
|
|
GimpVector3 result;
|
|
|
|
|
|
|
|
result.x = vector.x * factor;
|
|
|
|
result.y = vector.y * factor;
|
|
|
|
result.z = vector.z * factor;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_normalize:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a pointer to a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Normalizes the @vector so the length of the @vector is 1.0. The nul
|
|
|
|
* vector will not be changed.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2000-02-15 01:43:55 +08:00
|
|
|
gimp_vector3_normalize (GimpVector3 *vector)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
|
|
|
gdouble len;
|
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
len = gimp_vector3_length (vector);
|
2003-07-07 22:20:39 +08:00
|
|
|
|
2000-02-15 00:29:41 +08:00
|
|
|
if (len != 0.0)
|
|
|
|
{
|
|
|
|
len = 1.0 / len;
|
2000-02-15 01:43:55 +08:00
|
|
|
vector->x *= len;
|
|
|
|
vector->y *= len;
|
|
|
|
vector->z *= len;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-02-15 01:43:55 +08:00
|
|
|
*vector = gimp_vector3_zero;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_normalize_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a #GimpVector3.
|
2003-09-28 07:02:39 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector3_normalize() but the
|
|
|
|
* vector is passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: a #GimpVector3 parallel to @vector, pointing in the same
|
|
|
|
* direction but with a length of 1.0.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2001-01-26 10:16:13 +08:00
|
|
|
GimpVector3
|
|
|
|
gimp_vector3_normalize_val (GimpVector3 vector)
|
|
|
|
{
|
|
|
|
GimpVector3 result;
|
2003-07-07 22:20:39 +08:00
|
|
|
gdouble len;
|
2001-01-26 10:16:13 +08:00
|
|
|
|
|
|
|
len = gimp_vector3_length_val (vector);
|
2003-07-07 22:20:39 +08:00
|
|
|
|
2001-01-26 10:16:13 +08:00
|
|
|
if (len != 0.0)
|
|
|
|
{
|
|
|
|
len = 1.0 / len;
|
|
|
|
result.x = vector.x * len;
|
|
|
|
result.y = vector.y * len;
|
|
|
|
result.z = vector.z * len;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return gimp_vector3_zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_neg:
|
|
|
|
* @vector: a pointer to a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Negates the @vector (i.e. negate all its coordinates).
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector3_neg (GimpVector3 *vector)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
vector->x *= -1.0;
|
|
|
|
vector->y *= -1.0;
|
|
|
|
vector->z *= -1.0;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_neg_val:
|
|
|
|
* @vector: a #GimpVector3.
|
|
|
|
*
|
|
|
|
* This function is identical to gimp_vector3_neg() but the vector
|
|
|
|
* is passed by value rather than by reference.
|
|
|
|
*
|
|
|
|
* Returns: the negated #GimpVector3.
|
|
|
|
**/
|
|
|
|
GimpVector3
|
|
|
|
gimp_vector3_neg_val (GimpVector3 vector)
|
|
|
|
{
|
|
|
|
GimpVector3 result;
|
|
|
|
|
|
|
|
result.x = vector.x * -1.0;
|
|
|
|
result.y = vector.y * -1.0;
|
|
|
|
result.z = vector.z * -1.0;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_vector3_add:
|
|
|
|
* @result: destination for the resulting #GimpVector3.
|
|
|
|
* @vector1: a pointer to the first #GimpVector3.
|
|
|
|
* @vector2: a pointer to the second #GimpVector3.
|
|
|
|
*
|
|
|
|
* Computes the sum of two 3D vectors. The resulting #GimpVector3 is
|
|
|
|
* stored in @result.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_vector3_add (GimpVector3 *result,
|
|
|
|
const GimpVector3 *vector1,
|
|
|
|
const GimpVector3 *vector2)
|
|
|
|
{
|
|
|
|
result->x = vector1->x + vector2->x;
|
|
|
|
result->y = vector1->y + vector2->y;
|
|
|
|
result->z = vector1->z + vector2->z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_vector3_add_val:
|
|
|
|
* @vector1: a #GimpVector3.
|
|
|
|
* @vector2: a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector3_add() but the vectors
|
|
|
|
* are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Returns: the resulting #GimpVector3.
|
|
|
|
**/
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector3_add_val (GimpVector3 vector1,
|
|
|
|
GimpVector3 vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
|
|
|
GimpVector3 result;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
result.x = vector1.x + vector2.x;
|
|
|
|
result.y = vector1.y + vector2.y;
|
|
|
|
result.z = vector1.z + vector2.z;
|
2001-01-26 10:16:13 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_sub:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @result: the destination for the resulting #GimpVector3.
|
|
|
|
* @vector1: a pointer to the first #GimpVector3.
|
|
|
|
* @vector2: a pointer to the second #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Computes the difference of two 3D vectors (@vector1 minus @vector2).
|
2003-11-15 23:30:34 +08:00
|
|
|
* The resulting #GimpVector3 is stored in @result.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2003-07-07 22:20:39 +08:00
|
|
|
gimp_vector3_sub (GimpVector3 *result,
|
2003-09-28 07:02:39 +08:00
|
|
|
const GimpVector3 *vector1,
|
|
|
|
const GimpVector3 *vector2)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2000-02-15 01:43:55 +08:00
|
|
|
result->x = vector1->x - vector2->x;
|
|
|
|
result->y = vector1->y - vector2->y;
|
|
|
|
result->z = vector1->z - vector2->z;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_sub_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector1: a #GimpVector3.
|
|
|
|
* @vector2: a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector3_sub() but the vectors
|
|
|
|
* are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Returns: the resulting #GimpVector3.
|
|
|
|
**/
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3
|
2003-09-28 06:22:59 +08:00
|
|
|
gimp_vector3_sub_val (GimpVector3 vector1,
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3 vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
|
|
|
GimpVector3 result;
|
|
|
|
|
|
|
|
result.x = vector1.x - vector2.x;
|
|
|
|
result.y = vector1.y - vector2.y;
|
|
|
|
result.z = vector1.z - vector2.z;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_inner_product:
|
|
|
|
* @vector1: a pointer to the first #GimpVector3.
|
|
|
|
* @vector2: a pointer to the second #GimpVector3.
|
|
|
|
*
|
|
|
|
* Computes the inner (dot) product of two 3D vectors. This product
|
2018-09-21 00:08:54 +08:00
|
|
|
* is zero if and only if the two vectors are orthogonal.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: The inner product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
gdouble
|
|
|
|
gimp_vector3_inner_product (const GimpVector3 *vector1,
|
|
|
|
const GimpVector3 *vector2)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
return (vector1->x * vector2->x +
|
|
|
|
vector1->y * vector2->y +
|
|
|
|
vector1->z * vector2->z);
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_inner_product_val:
|
|
|
|
* @vector1: the first #GimpVector3.
|
|
|
|
* @vector2: the second #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector3_inner_product() but the
|
|
|
|
* vectors are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: The inner product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-11-15 23:30:34 +08:00
|
|
|
gdouble
|
|
|
|
gimp_vector3_inner_product_val (GimpVector3 vector1,
|
|
|
|
GimpVector3 vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
return (vector1.x * vector2.x +
|
|
|
|
vector1.y * vector2.y +
|
|
|
|
vector1.z * vector2.z);
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_cross_product:
|
|
|
|
* @vector1: a pointer to the first #GimpVector3.
|
|
|
|
* @vector2: a pointer to the second #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Compute the cross product of two vectors. The result is a
|
2018-09-21 00:08:54 +08:00
|
|
|
* #GimpVector3 which is orthogonal to both @vector1 and @vector2. If
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector1 and @vector2 and parallel, the result will be the nul
|
|
|
|
* vector.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function can be used to compute the normal of the plane
|
|
|
|
* defined by @vector1 and @vector2.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: The cross product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector3_cross_product (const GimpVector3 *vector1,
|
|
|
|
const GimpVector3 *vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector3 normal;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
normal.x = vector1->y * vector2->z - vector1->z * vector2->y;
|
|
|
|
normal.y = vector1->z * vector2->x - vector1->x * vector2->z;
|
|
|
|
normal.z = vector1->x * vector2->y - vector1->y * vector2->x;
|
2001-01-26 10:16:13 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
return normal;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
2003-11-15 23:30:34 +08:00
|
|
|
* gimp_vector3_cross_product_val:
|
|
|
|
* @vector1: the first #GimpVector3.
|
|
|
|
* @vector2: the second #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector3_cross_product() but the
|
|
|
|
* vectors are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Returns: The cross product.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3
|
2003-11-15 23:30:34 +08:00
|
|
|
gimp_vector3_cross_product_val (GimpVector3 vector1,
|
|
|
|
GimpVector3 vector2)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-11-15 23:30:34 +08:00
|
|
|
GimpVector3 normal;
|
2001-01-26 10:16:13 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
normal.x = vector1.y * vector2.z - vector1.z * vector2.y;
|
|
|
|
normal.y = vector1.z * vector2.x - vector1.x * vector2.z;
|
|
|
|
normal.z = vector1.x * vector2.y - vector1.y * vector2.x;
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2003-11-15 23:30:34 +08:00
|
|
|
return normal;
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_rotate:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a pointer to a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
* @alpha: the angle (in radian) of rotation around the Z axis.
|
|
|
|
* @beta: the angle (in radian) of rotation around the Y axis.
|
|
|
|
* @gamma: the angle (in radian) of rotation around the X axis.
|
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Rotates the @vector around the three axis (Z, Y, and X) by @alpha,
|
|
|
|
* @beta and @gamma, respectively.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Note that the order of the rotation is very important. If you
|
|
|
|
* expect a vector to be rotated around X, and then around Y, you will
|
|
|
|
* have to call this function twice. Also, it is often wise to call
|
|
|
|
* this function with only one of @alpha, @beta and @gamma non-zero.
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2000-02-15 01:43:55 +08:00
|
|
|
gimp_vector3_rotate (GimpVector3 *vector,
|
2003-09-28 07:02:39 +08:00
|
|
|
gdouble alpha,
|
|
|
|
gdouble beta,
|
|
|
|
gdouble gamma)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
|
|
|
GimpVector3 s, t;
|
|
|
|
|
|
|
|
/* First we rotate it around the Z axis (XY plane).. */
|
|
|
|
/* ================================================= */
|
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
s.x = cos (alpha) * vector->x + sin (alpha) * vector->y;
|
|
|
|
s.y = cos (alpha) * vector->y - sin (alpha) * vector->x;
|
2000-02-15 00:29:41 +08:00
|
|
|
|
|
|
|
/* ..then around the Y axis (XZ plane).. */
|
|
|
|
/* ===================================== */
|
|
|
|
|
|
|
|
t = s;
|
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
vector->x = cos (beta) *t.x + sin (beta) * vector->z;
|
|
|
|
s.z = cos (beta) *vector->z - sin (beta) * t.x;
|
2000-02-15 00:29:41 +08:00
|
|
|
|
|
|
|
/* ..and at last around the X axis (YZ plane) */
|
|
|
|
/* ========================================== */
|
|
|
|
|
2000-02-15 01:43:55 +08:00
|
|
|
vector->y = cos (gamma) * t.y + sin (gamma) * s.z;
|
|
|
|
vector->z = cos (gamma) * s.z - sin (gamma) * t.y;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector3_rotate_val:
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vector: a #GimpVector3.
|
2003-09-28 06:22:59 +08:00
|
|
|
* @alpha: the angle (in radian) of rotation around the Z axis.
|
|
|
|
* @beta: the angle (in radian) of rotation around the Y axis.
|
|
|
|
* @gamma: the angle (in radian) of rotation around the X axis.
|
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector3_rotate() but the vectors
|
|
|
|
* are passed by value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Returns: the rotated vector.
|
|
|
|
**/
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3
|
2001-01-26 10:16:13 +08:00
|
|
|
gimp_vector3_rotate_val (GimpVector3 vector,
|
2003-09-28 07:02:39 +08:00
|
|
|
gdouble alpha,
|
|
|
|
gdouble beta,
|
|
|
|
gdouble gamma)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
|
|
|
GimpVector3 s, t, result;
|
|
|
|
|
|
|
|
/* First we rotate it around the Z axis (XY plane).. */
|
|
|
|
/* ================================================= */
|
|
|
|
|
|
|
|
s.x = cos (alpha) * vector.x + sin (alpha) * vector.y;
|
|
|
|
s.y = cos (alpha) * vector.y - sin (alpha) * vector.x;
|
|
|
|
|
|
|
|
/* ..then around the Y axis (XZ plane).. */
|
|
|
|
/* ===================================== */
|
|
|
|
|
|
|
|
t = s;
|
|
|
|
|
|
|
|
result.x = cos (beta) *t.x + sin (beta) * vector.z;
|
|
|
|
s.z = cos (beta) *vector.z - sin (beta) * t.x;
|
|
|
|
|
|
|
|
/* ..and at last around the X axis (YZ plane) */
|
|
|
|
/* ========================================== */
|
|
|
|
|
|
|
|
result.y = cos (gamma) * t.y + sin (gamma) * s.z;
|
|
|
|
result.z = cos (gamma) * s.z - sin (gamma) * t.y;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector_2d_to_3d:
|
2016-06-26 04:54:10 +08:00
|
|
|
* @sx: the abscissa of the upper-left screen rectangle.
|
2003-09-28 06:22:59 +08:00
|
|
|
* @sy: the ordinate of the upper-left screen rectangle.
|
|
|
|
* @w: the width of the screen rectangle.
|
|
|
|
* @h: the height of the screen rectangle.
|
2016-06-26 04:54:10 +08:00
|
|
|
* @x: the abscissa of the point in the screen rectangle to map.
|
2003-09-28 06:22:59 +08:00
|
|
|
* @y: the ordinate of the point in the screen rectangle to map.
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vp: the position of the observer.
|
|
|
|
* @p: the resulting point.
|
2003-09-28 07:02:39 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* \"Compute screen (sx, sy) - (sx + w, sy + h) to 3D unit square
|
|
|
|
* mapping. The plane to map to is given in the z field of p. The
|
|
|
|
* observer is located at position vp (vp->z != 0.0).\"
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* In other words, this computes the projection of the point (@x, @y)
|
|
|
|
* to the plane z = @p->z (parallel to XY), from the @vp point of view
|
|
|
|
* through the screen (@sx, @sy)->(@sx + @w, @sy + @h)
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
|
|
|
|
void
|
2003-07-07 22:20:39 +08:00
|
|
|
gimp_vector_2d_to_3d (gint sx,
|
2003-09-28 07:02:39 +08:00
|
|
|
gint sy,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
const GimpVector3 *vp,
|
|
|
|
GimpVector3 *p)
|
2000-02-15 00:29:41 +08:00
|
|
|
{
|
|
|
|
gdouble t = 0.0;
|
|
|
|
|
|
|
|
if (vp->x != 0.0)
|
|
|
|
t = (p->z - vp->z) / vp->z;
|
|
|
|
|
|
|
|
if (t != 0.0)
|
|
|
|
{
|
|
|
|
p->x = vp->x + t * (vp->x - ((gdouble) (x - sx) / (gdouble) w));
|
|
|
|
p->y = vp->y + t * (vp->y - ((gdouble) (y - sy) / (gdouble) h));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p->x = (gdouble) (x - sx) / (gdouble) w;
|
2003-09-28 07:02:39 +08:00
|
|
|
p->y = (gdouble) (y - sy) / (gdouble) h;
|
2000-02-15 00:29:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector_2d_to_3d_val:
|
2016-06-26 04:54:10 +08:00
|
|
|
* @sx: the abscissa of the upper-left screen rectangle.
|
2003-09-28 06:22:59 +08:00
|
|
|
* @sy: the ordinate of the upper-left screen rectangle.
|
|
|
|
* @w: the width of the screen rectangle.
|
|
|
|
* @h: the height of the screen rectangle.
|
2016-06-26 04:54:10 +08:00
|
|
|
* @x: the abscissa of the point in the screen rectangle to map.
|
2003-09-28 06:22:59 +08:00
|
|
|
* @y: the ordinate of the point in the screen rectangle to map.
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vp: position of the observer.
|
|
|
|
* @p: the resulting point.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This function is identical to gimp_vector_2d_to_3d() but the
|
|
|
|
* position of the @observer and the resulting point @p are passed by
|
|
|
|
* value rather than by reference.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
|
|
|
* Returns: the computed #GimpVector3 point.
|
|
|
|
**/
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3
|
2001-01-26 10:16:13 +08:00
|
|
|
gimp_vector_2d_to_3d_val (gint sx,
|
2003-09-28 07:02:39 +08:00
|
|
|
gint sy,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
GimpVector3 vp,
|
|
|
|
GimpVector3 p)
|
2001-01-26 10:16:13 +08:00
|
|
|
{
|
2003-09-28 07:02:39 +08:00
|
|
|
GimpVector3 result;
|
2003-07-07 22:20:39 +08:00
|
|
|
gdouble t = 0.0;
|
2001-01-26 10:16:13 +08:00
|
|
|
|
|
|
|
if (vp.x != 0.0)
|
|
|
|
t = (p.z - vp.z) / vp.z;
|
|
|
|
|
|
|
|
if (t != 0.0)
|
|
|
|
{
|
|
|
|
result.x = vp.x + t * (vp.x - ((gdouble) (x - sx) / (gdouble) w));
|
|
|
|
result.y = vp.y + t * (vp.y - ((gdouble) (y - sy) / (gdouble) h));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result.x = (gdouble) (x - sx) / (gdouble) w;
|
2003-09-28 07:02:39 +08:00
|
|
|
result.y = (gdouble) (y - sy) / (gdouble) h;
|
2001-01-26 10:16:13 +08:00
|
|
|
}
|
2003-09-28 07:02:39 +08:00
|
|
|
|
2005-12-31 02:35:49 +08:00
|
|
|
result.z = 0;
|
2001-01-26 10:16:13 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-09-28 06:22:59 +08:00
|
|
|
/**
|
|
|
|
* gimp_vector_3d_to_2d:
|
2016-06-26 04:54:10 +08:00
|
|
|
* @sx: the abscissa of the upper-left screen rectangle.
|
2003-09-28 06:22:59 +08:00
|
|
|
* @sy: the ordinate of the upper-left screen rectangle.
|
|
|
|
* @w: the width of the screen rectangle.
|
|
|
|
* @h: the height of the screen rectangle.
|
2016-06-26 04:54:10 +08:00
|
|
|
* @x: the abscissa of the point in the screen rectangle to map (return value).
|
2003-09-28 06:22:59 +08:00
|
|
|
* @y: the ordinate of the point in the screen rectangle to map (return value).
|
2003-11-15 23:30:34 +08:00
|
|
|
* @vp: position of the observer.
|
|
|
|
* @p: the 3D point to project to the plane.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* Convert the given 3D point to 2D (project it onto the viewing
|
|
|
|
* plane, (sx, sy, 0) - (sx + w, sy + h, 0). The input is assumed to
|
|
|
|
* be in the unit square (0, 0, z) - (1, 1, z). The viewpoint of the
|
|
|
|
* observer is passed in vp.
|
2003-09-28 06:22:59 +08:00
|
|
|
*
|
2003-11-15 23:30:34 +08:00
|
|
|
* This is basically the opposite of gimp_vector_2d_to_3d().
|
2003-09-28 06:22:59 +08:00
|
|
|
**/
|
2000-02-15 00:29:41 +08:00
|
|
|
void
|
2003-07-07 22:20:39 +08:00
|
|
|
gimp_vector_3d_to_2d (gint sx,
|
2003-09-28 07:02:39 +08:00
|
|
|
gint sy,
|
|
|
|
gint w,
|
|
|
|
gint h,
|
|
|
|
gdouble *x,
|
|
|
|
gdouble *y,
|
|
|
|
const GimpVector3 *vp,
|
|
|
|
const GimpVector3 *p)
|
2003-07-07 22:20:39 +08:00
|
|
|
{
|
|
|
|
gdouble t;
|
2000-02-15 00:29:41 +08:00
|
|
|
GimpVector3 dir;
|
|
|
|
|
|
|
|
gimp_vector3_sub (&dir, p, vp);
|
|
|
|
gimp_vector3_normalize (&dir);
|
|
|
|
|
|
|
|
if (dir.z != 0.0)
|
|
|
|
{
|
|
|
|
t = (-1.0 * vp->z) / dir.z;
|
|
|
|
*x = (gdouble) sx + ((vp->x + t * dir.x) * (gdouble) w);
|
|
|
|
*y = (gdouble) sy + ((vp->y + t * dir.y) * (gdouble) h);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = (gdouble) sx + (p->x * (gdouble) w);
|
|
|
|
*y = (gdouble) sy + (p->y * (gdouble) h);
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 09:44:56 +08:00
|
|
|
|
|
|
|
/* Private functions for boxed type. */
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
gimp_vector2_copy (gpointer boxed)
|
|
|
|
{
|
|
|
|
GimpVector2 *vector = boxed;
|
|
|
|
GimpVector2 *new_v;
|
|
|
|
|
|
|
|
new_v = g_slice_new (GimpVector2);
|
|
|
|
new_v->x = vector->x;
|
|
|
|
new_v->y = vector->y;
|
|
|
|
|
|
|
|
return new_v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector2_free (gpointer boxed)
|
|
|
|
{
|
|
|
|
g_slice_free (GimpVector2, boxed);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_BOXED_TYPE (GimpVector2, gimp_vector2,
|
|
|
|
gimp_vector2_copy,
|
|
|
|
gimp_vector2_free)
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
gimp_vector3_copy (gpointer boxed)
|
|
|
|
{
|
|
|
|
GimpVector3 *vector = boxed;
|
|
|
|
GimpVector3 *new_v;
|
|
|
|
|
|
|
|
new_v = g_slice_new (GimpVector3);
|
|
|
|
new_v->x = vector->x;
|
|
|
|
new_v->y = vector->y;
|
2020-04-30 21:19:39 +08:00
|
|
|
new_v->z = vector->z;
|
2019-08-02 09:44:56 +08:00
|
|
|
|
|
|
|
return new_v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vector3_free (gpointer boxed)
|
|
|
|
{
|
|
|
|
g_slice_free (GimpVector3, boxed);
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_BOXED_TYPE (GimpVector3, gimp_vector3,
|
|
|
|
gimp_vector3_copy,
|
|
|
|
gimp_vector3_free)
|