API: deprecate the appendArc() api

@Issue: https://github.com/thorvg/thorvg/issues/2632
This commit is contained in:
Mira Grudzinska 2024-08-16 02:16:45 +02:00 committed by Hermet Park
parent 7c13da461a
commit f79558eb62
11 changed files with 31 additions and 144 deletions

View file

@ -1,106 +0,0 @@
/*
* Copyright (c) 2020 - 2024 the ThorVG project. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "Example.h"
/************************************************************************/
/* ThorVG Drawing Contents */
/************************************************************************/
struct UserExample : tvgexam::Example
{
bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override
{
if (!canvas) return false;
//Arc Line
auto shape1 = tvg::Shape::gen();
shape1->appendArc(150, 150, 80, 10, 180, false);
shape1->strokeFill(255, 255, 255);
shape1->strokeWidth(2);
canvas->push(std::move(shape1));
auto shape2 = tvg::Shape::gen();
shape2->appendArc(400, 150, 80, 0, 300, false);
shape2->strokeFill(255, 255, 255);
shape2->strokeWidth(2);
canvas->push(std::move(shape2));
auto shape3 = tvg::Shape::gen();
shape3->appendArc(600, 150, 80, 300, 60, false);
shape3->strokeFill(255, 255, 255);
shape3->strokeWidth(2);
canvas->push(std::move(shape3));
//Pie Line
auto shape4 = tvg::Shape::gen();
shape4->appendArc(150, 400, 80, 10, 180, true);
shape4->strokeFill(255, 255, 255);
shape4->strokeWidth(2);
canvas->push(std::move(shape4));
auto shape5 = tvg::Shape::gen();
shape5->appendArc(400, 400, 80, 0, 300, true);
shape5->strokeFill(255, 255, 255);
shape5->strokeWidth(2);
canvas->push(std::move(shape5));
auto shape6 = tvg::Shape::gen();
shape6->appendArc(600, 400, 80, 300, 60, true);
shape6->strokeFill(255, 255, 255);
shape6->strokeWidth(2);
canvas->push(std::move(shape6));
//Pie Fill
auto shape7 = tvg::Shape::gen();
shape7->appendArc(150, 650, 80, 10, 180, true);
shape7->fill(255, 255, 255);
shape7->strokeFill(255, 0, 0);
shape7->strokeWidth(2);
canvas->push(std::move(shape7));
auto shape8 = tvg::Shape::gen();
shape8->appendArc(400, 650, 80, 0, 300, true);
shape8->fill(255, 255, 255);
shape8->strokeFill(255, 0, 0);
shape8->strokeWidth(2);
canvas->push(std::move(shape8));
auto shape9 = tvg::Shape::gen();
shape9->appendArc(600, 650, 80, 300, 60, true);
shape9->fill(255, 255, 255);
shape9->strokeFill(255, 0, 0);
shape9->strokeWidth(2);
canvas->push(std::move(shape9));
return true;
}
};
/************************************************************************/
/* Entry Point */
/************************************************************************/
int main(int argc, char **argv)
{
return tvgexam::main(new UserExample, argc, argv);
}

View file

@ -143,18 +143,18 @@ void contents()
//Set a scene
Tvg_Paint* scene = tvg_scene_new();
//Set an arc
//Set circles
Tvg_Paint* scene_shape1 = tvg_shape_new();
tvg_shape_append_arc(scene_shape1, 175.0f, 600.0f, 150.0f, -45.0f, 90.0f, 1);
tvg_shape_append_arc(scene_shape1, 175.0f, 600.0f, 150.0f, 225.0f, -90.0f, 1);
tvg_shape_append_circle(scene_shape1, 80.0f, 650.f, 40.0f, 140.0f);
tvg_shape_append_circle(scene_shape1, 180.0f, 600.f, 40.0f, 60.0f);
tvg_shape_set_fill_color(scene_shape1, 0, 0, 255, 150);
tvg_shape_set_stroke_color(scene_shape1, 255, 255, 255, 155);
tvg_shape_set_stroke_color(scene_shape1, 75, 25, 155, 255);
tvg_shape_set_stroke_width(scene_shape1, 10.0f);
tvg_shape_set_stroke_cap(scene_shape1, Tvg_Stroke_Cap::TVG_STROKE_CAP_ROUND);
tvg_shape_set_stroke_join(scene_shape1, Tvg_Stroke_Join::TVG_STROKE_JOIN_ROUND);
tvg_shape_set_stroke_trim(scene_shape1, 0.25f, 0.75f, true);
//Set an arc with a dashed stroke
//Set circles with a dashed stroke
Tvg_Paint* scene_shape2 = tvg_paint_duplicate(scene_shape1);
tvg_shape_set_fill_color(scene_shape2, 75, 25, 155, 200);
@ -166,9 +166,9 @@ void contents()
tvg_shape_set_stroke_width(scene_shape2, 15.0f);
//Transform a shape
tvg_paint_scale(scene_shape2, 0.7f);
tvg_paint_scale(scene_shape2, 0.8f);
tvg_paint_rotate(scene_shape2, -90.0f);
tvg_paint_translate(scene_shape2, -245.0f, 722.0f);
tvg_paint_translate(scene_shape2, -200.0f, 800.0f);
//Push the shapes into the scene
tvg_scene_push(scene, scene_shape1);

View file

@ -117,34 +117,42 @@ struct UserExample : tvgexam::Example
//For a comparison with shapes 10-12
auto shape7 = tvg::Shape::gen();
shape7->appendArc(70, 400, 160, 10, 70, true);
shape7->moveTo(70, 440);
shape7->lineTo(230, 440);
shape7->cubicTo(230, 535, 170, 590, 70, 590);
shape7->close();
shape7->strokeFill(255, 0, 0);
shape7->strokeWidth(7);
shape7->strokeWidth(15);
shape7->strokeJoin(tvg::StrokeJoin::Round);
shape7->strokeCap(tvg::StrokeCap::Round);
canvas->push(std::move(shape7));
auto shape8 = tvg::Shape::gen();
shape8->appendArc(320, 400, 160, 10, 70, false);
shape8->moveTo(320, 440);
shape8->lineTo(480, 440);
shape8->cubicTo(480, 535, 420, 590, 320, 590);
shape8->close();
shape8->strokeFill(255, 255, 0);
shape8->strokeWidth(7);
shape8->strokeWidth(15);
shape8->strokeJoin(tvg::StrokeJoin::Bevel);
shape8->strokeCap(tvg::StrokeCap::Square);
canvas->push(std::move(shape8));
auto shape9 = tvg::Shape::gen();
shape9->appendArc(570, 400, 160, 10, 70, true);
shape9->moveTo(570, 440);
shape9->lineTo(730, 440);
shape9->cubicTo(730, 535, 670, 590, 570, 590);
shape9->close();
shape9->strokeFill(0, 255, 0);
shape9->strokeWidth(7);
shape9->strokeWidth(15);
shape9->strokeJoin(tvg::StrokeJoin::Miter);
shape9->strokeCap(tvg::StrokeCap::Butt);
canvas->push(std::move(shape9));
//Test for Stroke Dash for Arc, Circle, Rect
//Test for Stroke Dash for Circle and Rect
auto shape10 = tvg::Shape::gen();
shape10->appendArc(70, 600, 160, 10, 30, true);
shape10->appendCircle(70, 700, 20, 60);
shape10->appendRect(130, 710, 100, 40);
shape10->appendRect(130, 650, 100, 80);
shape10->strokeFill(255, 0, 0);
shape10->strokeWidth(5);
shape10->strokeJoin(tvg::StrokeJoin::Round);
@ -153,9 +161,8 @@ struct UserExample : tvgexam::Example
canvas->push(std::move(shape10));
auto shape11 = tvg::Shape::gen();
shape11->appendArc(320, 600, 160, 10, 30, false);
shape11->appendCircle(320, 700, 20, 60);
shape11->appendRect(380, 710, 100, 40);
shape11->appendRect(380, 650, 100, 80);
shape11->strokeFill(255, 255, 0);
shape11->strokeWidth(5);
shape11->strokeJoin(tvg::StrokeJoin::Bevel);
@ -164,9 +171,8 @@ struct UserExample : tvgexam::Example
canvas->push(std::move(shape11));
auto shape12 = tvg::Shape::gen();
shape12->appendArc(570, 600, 160, 10, 30, true);
shape12->appendCircle(570, 700, 20, 60);
shape12->appendRect(630, 710, 100, 40);
shape12->appendRect(630, 650, 100, 80);
shape12->strokeFill(0, 255, 0);
shape12->strokeWidth(5);
shape12->strokeJoin(tvg::StrokeJoin::Miter);

View file

@ -21,7 +21,6 @@ source_file = [
'Accessor.cpp',
'AnimateMasking.cpp',
'Animation.cpp',
'Arc.cpp',
'Blending.cpp',
'ClipPath.cpp',
'CustomTransform.cpp',

View file

@ -958,7 +958,7 @@ public:
*
* @note Setting @p sweep value greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius).
*/
Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept;
TVG_DEPRECATED Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept;
/**
* @brief Appends a given sub-path to the path.

View file

@ -6,7 +6,7 @@
*
* The thorvg_capi module allows to implement the ThorVG client and provides
* the following functionalities:
* - drawing shapes: line, arc, curve, polygon, circle, user-defined, ...
* - drawing shapes: line, curve, polygon, circle, user-defined, ...
* - filling: solid, linear and radial gradient
* - scene graph & affine transformation (translation, rotation, scale, ...)
* - stroking: width, join, cap, dash
@ -1231,7 +1231,7 @@ TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy,
*
* \note Setting @p sweep value greater than 360 degrees, is equivalent to calling tvg_shape_append_circle(paint, cx, cy, radius, radius).
*/
TVG_API Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie);
TVG_DEPRECATED TVG_API Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie);
/*!

View file

@ -317,7 +317,7 @@ TVG_API Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, flo
}
TVG_API Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie)
TVG_DEPRECATED TVG_API Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendArc(cx, cy, radius, startAngle, sweep, pie);

View file

@ -156,7 +156,7 @@ Result Shape::appendCircle(float cx, float cy, float rx, float ry) noexcept
}
Result Shape::appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept
TVG_DEPRECATED Result Shape::appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept
{
//just circle
if (sweep >= 360.0f || sweep <= -360.0f) return appendCircle(cx, cy, radius, radius);

View file

@ -40,12 +40,10 @@ TEST_CASE("Multiple shapes", "[capiShapes]")
REQUIRE(tvg_shape_append_rect(paint, 0, 0, 100, 100, 100, 100) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_shape_append_circle(paint, 100, 100, 50, 50) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_shape_append_circle(paint, 100, 100, 0, 0) == TVG_RESULT_SUCCESS);
REQUIRE(tvg_shape_append_arc(paint, 100, 100, 50, 90, 90, 0) == TVG_RESULT_SUCCESS);
//Invalid paint
REQUIRE(tvg_shape_append_rect(NULL, 0, 0, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_shape_append_circle(NULL, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_shape_append_arc(NULL, 0, 0, 0, 0, 0, 0) == TVG_RESULT_INVALID_ARGUMENT);
REQUIRE(tvg_paint_del(paint) == TVG_RESULT_SUCCESS);
}

View file

@ -76,15 +76,6 @@ TEST_CASE("Appending Shapes", "[tvgShape]")
REQUIRE(shape->appendCircle(0, 0, 0, 0) == Result::Success);
REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, 0, 0) == Result::Success);
REQUIRE(shape->appendCircle(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f) == Result::Success);
REQUIRE(shape->appendArc(0, 0, 0, 0, 0, false) == Result::Success);
REQUIRE(shape->appendArc(0, 0, 0, 0, 0, true) == Result::Success);
REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, 0, 0, 0, false) == Result::Success);
REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, 0, 0, 0, true) == Result::Success);
REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 0, false) == Result::Success);
REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 0, true) == Result::Success);
REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, -400, false) == Result::Success);
REQUIRE(shape->appendArc(-99999999.0f, 99999999.0f, -99999999.0f, 99999999.0f, 400, true) == Result::Success);
}
TEST_CASE("Appending Paths", "[tvgShape]")

View file

@ -44,7 +44,6 @@ TEST_CASE("Basic draw", "[tvgSwEngine]")
auto shape1 = tvg::Shape::gen();
REQUIRE(shape1);
REQUIRE(shape1->appendArc(150, 150, 80, 10, 180, false) == Result::Success);
REQUIRE(shape1->strokeFill(255, 255, 255, 255) == Result::Success);
REQUIRE(shape1->strokeWidth(2) == Result::Success);
REQUIRE(canvas->push(std::move(shape1)) == Result::Success);