1/**
2 * Copyright (c) 2006-2023 LOVE Development Team
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 **/
20
21#ifndef LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
22#define LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
23
24// Module
25#include "Shape.h"
26#include "EdgeShape.h"
27
28namespace love
29{
30namespace physics
31{
32namespace box2d
33{
34
35/**
36 * A ChainShape is a freeform collection of line segments.
37 **/
38class ChainShape : public Shape
39{
40public:
41
42 static love::Type type;
43
44 /**
45 * Create a new ChainShape from a Box2D chain shape.
46 * @param c The chain shape.
47 **/
48 ChainShape(b2ChainShape *c, bool own = true);
49
50 virtual ~ChainShape();
51
52 /**
53 * Establish connectivity to a vertex that follows
54 * the last vertex. Fails if called on a loop.
55 * @param x The x-coordinate of the vertex.
56 * @param y The y-coordinate of the vertex.
57 **/
58 void setNextVertex(float x, float y);
59 void setNextVertex();
60
61 /**
62 * Establish connectivity to a vertex that precedes
63 * the first vertex. Fails if called on a loop.
64 * @param x The x-coordinate of the vertex.
65 * @param y The y-coordinate of the vertex.
66 **/
67 void setPreviousVertex(float x, float y);
68 void setPreviousVertex();
69
70 /**
71 * Gets the vertex that follows the last vertex.
72 **/
73 bool getNextVertex(float &x, float &y) const;
74
75 /**
76 * Gets the vertex that precedes the first vertex.
77 **/
78 bool getPreviousVertex(float &x, float &y) const;
79
80 /**
81 * Returns a child EdgeShape.
82 * @param index The index of the child shape.
83 * @returns The specified child.
84 **/
85 EdgeShape *getChildEdge(int index) const;
86
87 /**
88 * Returns the number of vertices in the shape.
89 * @returns The number of vertices in the shape.
90 **/
91 int getVertexCount() const;
92
93 /**
94 * Returns the vertex at the given index.
95 * @param index The index of the vertex.
96 * @returns The specified vertex.
97 **/
98 b2Vec2 getPoint(int index) const;
99
100 /**
101 * Returns all of the vertices.
102 * @returns The vertices the shape comprises.
103 **/
104 const b2Vec2 *getPoints() const;
105
106};
107
108} // box2d
109} // physics
110} // love
111
112#endif // LOVE_PHYSICS_BOX2D_CHAIN_SHAPE_H
113