2007-07-05 04:01:12 +02:00
|
|
|
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-07-05 04:01:12 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file spline.cpp
|
|
|
|
/// @brief Manage vector drawings for visual typesetting tools
|
|
|
|
/// @ingroup visual_ts
|
|
|
|
///
|
2007-07-05 04:01:12 +02:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2007-07-05 06:32:46 +02:00
|
|
|
#include <wx/tokenzr.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2010-06-08 08:09:19 +02:00
|
|
|
#include <limits>
|
|
|
|
|
2007-07-05 04:01:12 +02:00
|
|
|
#include "spline.h"
|
2007-07-07 07:51:18 +02:00
|
|
|
#include "utils.h"
|
2010-05-16 08:39:11 +02:00
|
|
|
#include "video_display.h"
|
2007-07-05 16:30:28 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Spline constructor
|
2010-05-16 08:39:11 +02:00
|
|
|
Spline::Spline(const VideoDisplay &scale) : scale(scale) {
|
2007-07-05 04:01:12 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Encode to ASS
|
2007-07-05 04:01:12 +02:00
|
|
|
wxString Spline::EncodeToASS() {
|
|
|
|
wxString result;
|
|
|
|
char lastCommand = 0;
|
|
|
|
|
|
|
|
// Insert each element
|
2010-06-08 08:09:19 +02:00
|
|
|
for (iterator cur=begin();cur!=end();cur++) {
|
2007-07-05 04:01:12 +02:00
|
|
|
// Each curve
|
|
|
|
switch (cur->type) {
|
2010-06-08 08:09:19 +02:00
|
|
|
case CURVE_POINT: {
|
|
|
|
if (lastCommand != 'm') {
|
|
|
|
result += L"m ";
|
|
|
|
lastCommand = 'm';
|
|
|
|
}
|
|
|
|
int x = cur->p1.x;
|
|
|
|
int y = cur->p1.y;
|
|
|
|
scale.ToScriptCoords(&x, &y);
|
|
|
|
result += wxString::Format(L"%i %i ", x, y);
|
|
|
|
break;
|
|
|
|
}
|
2010-05-16 08:39:11 +02:00
|
|
|
case CURVE_LINE: {
|
2007-07-05 04:01:12 +02:00
|
|
|
if (lastCommand != 'l') {
|
2010-05-16 08:39:11 +02:00
|
|
|
result += L"l ";
|
2007-07-05 04:01:12 +02:00
|
|
|
lastCommand = 'l';
|
|
|
|
}
|
2010-05-16 08:39:11 +02:00
|
|
|
int x = cur->p2.x;
|
|
|
|
int y = cur->p2.y;
|
|
|
|
scale.ToScriptCoords(&x, &y);
|
|
|
|
result += wxString::Format(L"%i %i ", x, y);
|
2007-07-05 04:01:12 +02:00
|
|
|
break;
|
2010-05-16 08:39:11 +02:00
|
|
|
}
|
|
|
|
case CURVE_BICUBIC: {
|
2007-07-05 04:01:12 +02:00
|
|
|
if (lastCommand != 'b') {
|
2010-05-16 08:39:11 +02:00
|
|
|
result += L"b ";
|
2007-07-05 04:01:12 +02:00
|
|
|
lastCommand = 'b';
|
|
|
|
}
|
2010-05-16 08:39:11 +02:00
|
|
|
int x2 = cur->p2.x;
|
|
|
|
int y2 = cur->p2.y;
|
|
|
|
int x3 = cur->p3.x;
|
|
|
|
int y3 = cur->p3.y;
|
|
|
|
int x4 = cur->p4.x;
|
|
|
|
int y4 = cur->p4.y;
|
|
|
|
scale.ToScriptCoords(&x2, &y2);
|
|
|
|
scale.ToScriptCoords(&x3, &y3);
|
|
|
|
scale.ToScriptCoords(&x4, &y4);
|
|
|
|
result += wxString::Format(L"%i %i %i %i %i %i ", x2, y2, x3, y3, x4, y4);
|
2007-07-05 04:01:12 +02:00
|
|
|
break;
|
2010-05-16 08:39:11 +02:00
|
|
|
}
|
2007-07-05 04:01:12 +02:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Decode from ASS
|
|
|
|
/// @param str
|
2007-07-05 04:01:12 +02:00
|
|
|
void Spline::DecodeFromASS(wxString str) {
|
|
|
|
// Clear current
|
2010-06-08 08:09:19 +02:00
|
|
|
clear();
|
2007-07-05 06:32:46 +02:00
|
|
|
std::vector<int> stack;
|
|
|
|
|
|
|
|
// Prepare
|
|
|
|
char lastCommand = 'm';
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
// Tokenize the string
|
2010-05-16 08:39:11 +02:00
|
|
|
wxStringTokenizer tkn(str,L" ");
|
2007-07-05 06:32:46 +02:00
|
|
|
while (tkn.HasMoreTokens()) {
|
|
|
|
wxString token = tkn.GetNextToken();
|
|
|
|
|
|
|
|
// Got a number
|
|
|
|
if (token.IsNumber()) {
|
|
|
|
long n;
|
|
|
|
token.ToLong(&n);
|
|
|
|
stack.push_back(n);
|
|
|
|
|
|
|
|
// Move
|
|
|
|
if (stack.size() == 2 && lastCommand == 'm') {
|
2010-06-08 08:09:19 +02:00
|
|
|
scale.FromScriptCoords(&stack[0], &stack[1]);
|
|
|
|
SplineCurve curve;
|
|
|
|
x = curve.p1.x = stack[0];
|
|
|
|
y = curve.p1.y = stack[1];
|
|
|
|
curve.type = CURVE_POINT;
|
2007-07-05 06:32:46 +02:00
|
|
|
stack.clear();
|
2010-06-08 08:09:19 +02:00
|
|
|
push_back(curve);
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Line
|
|
|
|
if (stack.size() == 2 && lastCommand == 'l') {
|
2010-05-16 08:39:11 +02:00
|
|
|
scale.FromScriptCoords(&stack[0], &stack[1]);
|
2007-07-05 06:32:46 +02:00
|
|
|
SplineCurve curve;
|
2007-07-05 16:15:28 +02:00
|
|
|
curve.p1.x = x;
|
|
|
|
curve.p1.y = y;
|
2010-06-08 08:09:19 +02:00
|
|
|
x = curve.p2.x = stack[0];
|
|
|
|
y = curve.p2.y = stack[1];
|
2007-07-05 06:32:46 +02:00
|
|
|
curve.type = CURVE_LINE;
|
|
|
|
stack.clear();
|
2010-06-08 08:09:19 +02:00
|
|
|
push_back(curve);
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bicubic
|
|
|
|
else if (stack.size() == 6 && lastCommand == 'b') {
|
2010-05-16 08:39:11 +02:00
|
|
|
scale.FromScriptCoords(&stack[0], &stack[1]);
|
|
|
|
scale.FromScriptCoords(&stack[2], &stack[3]);
|
|
|
|
scale.FromScriptCoords(&stack[4], &stack[5]);
|
2007-07-05 06:32:46 +02:00
|
|
|
SplineCurve curve;
|
2007-07-05 16:15:28 +02:00
|
|
|
curve.p1.x = x;
|
|
|
|
curve.p1.y = y;
|
|
|
|
curve.p2.x = stack[0];
|
|
|
|
curve.p2.y = stack[1];
|
|
|
|
curve.p3.x = stack[2];
|
|
|
|
curve.p3.y = stack[3];
|
|
|
|
curve.p4.x = stack[4];
|
|
|
|
curve.p4.y = stack[5];
|
2007-07-05 06:32:46 +02:00
|
|
|
curve.type = CURVE_BICUBIC;
|
2010-05-16 08:39:11 +02:00
|
|
|
x = curve.p4.x;
|
|
|
|
y = curve.p4.y;
|
2007-07-05 06:32:46 +02:00
|
|
|
stack.clear();
|
2010-06-08 08:09:19 +02:00
|
|
|
push_back(curve);
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close
|
|
|
|
else if (lastCommand == 'c') {
|
|
|
|
stack.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Got something else
|
|
|
|
else {
|
2010-05-16 08:39:11 +02:00
|
|
|
if (token == L"m") lastCommand = 'm';
|
|
|
|
else if (token == L"l") lastCommand = 'l';
|
|
|
|
else if (token == L"b") lastCommand = 'b';
|
|
|
|
else if (token == L"n") lastCommand = 'n';
|
|
|
|
else if (token == L"s") lastCommand = 's';
|
|
|
|
else if (token == L"c") lastCommand = 'c';
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-05 04:01:12 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Moves a specific point in the spline
|
|
|
|
/// @param curveIndex
|
|
|
|
/// @param point
|
|
|
|
/// @param pos
|
2010-06-08 08:09:19 +02:00
|
|
|
void Spline::MovePoint(iterator curve,int point,Vector2D const& pos) {
|
|
|
|
iterator prev = curve;
|
|
|
|
if (curve != begin()) --prev;
|
|
|
|
iterator next = curve;
|
|
|
|
++next;
|
|
|
|
if (next != end() && next->type == CURVE_POINT) next = end();
|
2007-07-05 06:32:46 +02:00
|
|
|
|
|
|
|
// Modify
|
|
|
|
if (point == 0) {
|
2010-06-08 08:09:19 +02:00
|
|
|
curve->p1 = pos;
|
|
|
|
if (curve != begin() && curve->type != CURVE_POINT) prev->EndPoint() = pos;
|
|
|
|
if (next != end() && curve->type == CURVE_POINT) next->p1 = pos;
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
else if (point == 1) {
|
2010-06-08 08:09:19 +02:00
|
|
|
curve->p2 = pos;
|
|
|
|
if (next != end() && curve->type == CURVE_LINE) next->p1 = pos;
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
else if (point == 2) {
|
2010-06-08 08:09:19 +02:00
|
|
|
curve->p3 = pos;
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
else if (point == 3) {
|
2010-06-08 08:09:19 +02:00
|
|
|
curve->p4 = pos;
|
|
|
|
if (next != end()) next->p1 = pos;
|
2007-07-05 04:01:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Gets a list of points in the curve
|
|
|
|
/// @param points
|
|
|
|
/// @param pointCurve
|
2010-06-08 08:09:19 +02:00
|
|
|
void Spline::GetPointList(std::vector<float>& points, std::vector<int>& first, std::vector<int>& count) {
|
2007-07-05 04:01:12 +02:00
|
|
|
points.clear();
|
2010-06-08 08:09:19 +02:00
|
|
|
first.clear();
|
|
|
|
count.clear();
|
|
|
|
|
|
|
|
points.reserve((size() + 1) * 2);
|
|
|
|
int curCount = 0;
|
2007-07-05 04:01:12 +02:00
|
|
|
|
|
|
|
// Generate points for each curve
|
2010-06-08 08:09:19 +02:00
|
|
|
for (iterator cur = begin();cur!=end();cur++) {
|
|
|
|
switch (cur->type) {
|
|
|
|
case CURVE_POINT:
|
|
|
|
if (curCount > 0) {
|
|
|
|
count.push_back(curCount);
|
|
|
|
}
|
2007-07-05 04:01:12 +02:00
|
|
|
|
2010-06-08 08:09:19 +02:00
|
|
|
// start new path
|
|
|
|
first.push_back(points.size() / 2);
|
|
|
|
points.push_back(cur->p1.x);
|
|
|
|
points.push_back(cur->p1.y);
|
|
|
|
curCount = 1;
|
|
|
|
break;
|
|
|
|
case CURVE_LINE:
|
|
|
|
points.push_back(cur->p2.x);
|
|
|
|
points.push_back(cur->p2.y);
|
|
|
|
curCount++;
|
|
|
|
break;
|
|
|
|
case CURVE_BICUBIC: {
|
|
|
|
// Get the control points
|
|
|
|
Vector2D p1 = cur->p1;
|
|
|
|
Vector2D p2 = cur->p2;
|
|
|
|
Vector2D p3 = cur->p3;
|
|
|
|
Vector2D p4 = cur->p4;
|
|
|
|
|
|
|
|
// Find number of steps
|
|
|
|
int len = (int)((p2-p1).Len() + (p3-p2).Len() + (p4-p3).Len());
|
|
|
|
int steps = len/8;
|
|
|
|
|
|
|
|
// Render curve
|
|
|
|
for (int i=1;i<=steps;i++) {
|
|
|
|
// Get t and t-1 (u)
|
|
|
|
float t = float(i)/float(steps);
|
|
|
|
Vector2D p = cur->GetPoint(t);
|
|
|
|
points.push_back(p.x);
|
|
|
|
points.push_back(p.y);
|
|
|
|
}
|
|
|
|
curCount += steps;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
2007-07-08 09:22:09 +02:00
|
|
|
}
|
2010-06-08 08:09:19 +02:00
|
|
|
}
|
2007-07-05 04:01:12 +02:00
|
|
|
|
2010-06-08 08:09:19 +02:00
|
|
|
count.push_back(curCount);
|
|
|
|
}
|
|
|
|
void Spline::GetPointList(std::vector<float> &points, iterator curve) {
|
|
|
|
points.clear();
|
|
|
|
if (curve == end()) return;
|
|
|
|
switch (curve->type) {
|
|
|
|
case CURVE_LINE:
|
|
|
|
points.push_back(curve->p1.x);
|
|
|
|
points.push_back(curve->p1.y);
|
|
|
|
points.push_back(curve->p2.x);
|
|
|
|
points.push_back(curve->p2.y);
|
|
|
|
break;
|
|
|
|
case CURVE_BICUBIC: {
|
2007-07-05 04:01:12 +02:00
|
|
|
// Get the control points
|
2010-06-08 08:09:19 +02:00
|
|
|
Vector2D p1 = curve->p1;
|
|
|
|
Vector2D p2 = curve->p2;
|
|
|
|
Vector2D p3 = curve->p3;
|
|
|
|
Vector2D p4 = curve->p4;
|
2007-07-05 04:01:12 +02:00
|
|
|
|
2007-07-05 06:56:56 +02:00
|
|
|
// Find number of steps
|
2008-03-13 21:27:25 +01:00
|
|
|
int len = (int)((p2-p1).Len() + (p3-p2).Len() + (p4-p3).Len());
|
2007-07-05 06:56:56 +02:00
|
|
|
int steps = len/8;
|
|
|
|
|
|
|
|
// Render curve
|
2010-06-08 08:09:19 +02:00
|
|
|
for (int i=0;i<=steps;i++) {
|
2007-07-05 04:01:12 +02:00
|
|
|
// Get t and t-1 (u)
|
|
|
|
float t = float(i)/float(steps);
|
2010-06-08 08:09:19 +02:00
|
|
|
Vector2D p = curve->GetPoint(t);
|
2010-06-07 09:24:43 +02:00
|
|
|
points.push_back(p.x);
|
|
|
|
points.push_back(p.y);
|
2007-07-05 04:01:12 +02:00
|
|
|
}
|
2010-06-08 08:09:19 +02:00
|
|
|
break;
|
2007-07-05 04:01:12 +02:00
|
|
|
}
|
2010-06-08 08:09:19 +02:00
|
|
|
default: break;
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
2007-07-05 04:01:12 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief t value and curve of the point closest to reference
|
|
|
|
/// @param reference
|
|
|
|
/// @param curve
|
|
|
|
/// @param t
|
|
|
|
/// @param pt
|
2010-06-08 08:09:19 +02:00
|
|
|
void Spline::GetClosestParametricPoint(Vector2D const& reference,iterator &curve,float &t,Vector2D &pt) {
|
|
|
|
curve = end();
|
|
|
|
t = 0.f;
|
|
|
|
if (empty()) return;
|
2007-07-07 10:53:11 +02:00
|
|
|
|
|
|
|
// Close the shape
|
|
|
|
SplineCurve pad;
|
2010-06-08 08:09:19 +02:00
|
|
|
pad.p1 = back().EndPoint();
|
|
|
|
pad.p2 = front().p1;
|
2007-07-07 10:53:11 +02:00
|
|
|
pad.type = CURVE_LINE;
|
2010-06-08 08:09:19 +02:00
|
|
|
push_back(pad);
|
2007-07-07 10:53:11 +02:00
|
|
|
|
2010-06-08 08:09:19 +02:00
|
|
|
float closest = std::numeric_limits<float>::infinity();
|
|
|
|
for (iterator cur = begin();cur!=end();cur++) {
|
2007-07-07 10:53:11 +02:00
|
|
|
float param = cur->GetClosestParam(reference);
|
|
|
|
Vector2D p1 = cur->GetPoint(param);
|
2010-06-08 08:09:19 +02:00
|
|
|
float dist = (p1-reference).SquareLen();
|
2007-07-07 10:53:11 +02:00
|
|
|
if (dist < closest) {
|
|
|
|
closest = dist;
|
|
|
|
t = param;
|
2010-06-08 08:09:19 +02:00
|
|
|
curve = cur;
|
2007-07-07 10:53:11 +02:00
|
|
|
pt = p1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-08 08:09:19 +02:00
|
|
|
if (&*curve == &back()) {
|
|
|
|
curve = end();
|
|
|
|
}
|
|
|
|
|
2007-07-07 10:53:11 +02:00
|
|
|
// Remove closing and return
|
2010-06-08 08:09:19 +02:00
|
|
|
pop_back();
|
2007-07-05 16:30:28 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Point closest to reference
|
|
|
|
/// @param reference
|
|
|
|
/// @return
|
2010-06-08 08:09:19 +02:00
|
|
|
Vector2D Spline::GetClosestPoint(Vector2D const& reference) {
|
|
|
|
iterator curve;
|
2007-07-07 10:53:11 +02:00
|
|
|
float t;
|
|
|
|
Vector2D point;
|
|
|
|
GetClosestParametricPoint(reference,curve,t,point);
|
|
|
|
return point;
|
2007-07-05 04:01:12 +02:00
|
|
|
}
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @brief Smoothes the spline
|
|
|
|
/// @param smooth
|
2007-07-07 07:51:18 +02:00
|
|
|
void Spline::Smooth(float smooth) {
|
|
|
|
// See if there are enough curves
|
2010-06-08 08:09:19 +02:00
|
|
|
if (size() < 3) return;
|
2007-07-07 07:51:18 +02:00
|
|
|
|
|
|
|
// Smooth curve
|
2010-06-08 08:09:19 +02:00
|
|
|
iterator curve1 = end();
|
|
|
|
--curve1;
|
|
|
|
for (iterator cur = begin(); cur != end();) {
|
|
|
|
iterator curve0 = curve1;
|
|
|
|
curve1 = cur;
|
2007-07-07 07:51:18 +02:00
|
|
|
cur++;
|
2010-06-08 08:09:19 +02:00
|
|
|
iterator curve2 = cur == end() ? begin() : cur;
|
2007-07-07 07:51:18 +02:00
|
|
|
|
|
|
|
// Smooth curve
|
|
|
|
curve1->Smooth(curve0->p1,curve2->p2,smooth);
|
|
|
|
}
|
|
|
|
}
|