Skip to content

Commit

Permalink
bfariadne: Added surface area computations
Browse files Browse the repository at this point in the history
  • Loading branch information
mefistotelis committed Jan 6, 2024
1 parent b2ccc4c commit 7082739
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 58 deletions.
16 changes: 16 additions & 0 deletions bfariadne/include/triangls.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ TbBool triangle_has_point_coord(TrTriangId tri, TrCoord pt_x, TrCoord pt_y);
TbBool triangle_contained_within_rect_coords(TrTriangId tri,
TrCoord x1, TrCoord y1, TrCoord x2, TrCoord y2);

/** Computes surface area of the given triangle.
*/
long triangle_area1(TrTriangId tri);

/** Returns if given coords can divide triangle into same areas.
*
* @param tri Triangle index.
* @param cor1 First tip/corner of the edge to be divided.
* @param cor2 Second tip/corner of the edge to be divided.
* @param pt_x Coord X of the dividing point.
* @param pt_y Coord Y of the dividing point.
* @return Zero if areas do not differ; -1 or 1 otherwise.
*/
sbyte triangle_divide_areas_differ(TrTriangId tri,
TrTipId cor1, TrTipId cor2, TrCoord pt_x, TrCoord pt_y);

/******************************************************************************/
#ifdef __cplusplus
}
Expand Down
50 changes: 50 additions & 0 deletions bfariadne/src/triangls.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "triangls.h"

#include <limits.h>
#include <stdlib.h>
#include "trstate.h"
#include "trlog.h"
/******************************************************************************/
Expand Down Expand Up @@ -136,5 +137,54 @@ TbBool triangle_contained_within_rect_coords(TrTriangId tri,
return true;
}

/** Multiplies first pair of arguments, and second pair, returning which result is smaller.
* @return Gives -1 if first pair multiplies to smaller value, 1 if it's the second; if equal, gives 0.
*/
static sbyte path_compare_multiplications(long mul1a, long mul1b, long mul2a, long mul2b)
{
long long mul1,mul2;
mul1 = (long long)mul1a * (long long)mul1b;
mul2 = (long long)mul2a * (long long)mul2b;
if (mul1 > mul2)
return 1;
if (mul1 < mul2)
return -1;
return 0;
}

long triangle_area1(TrTriangId tri)
{
struct TrTriangle *p_tri;
struct TrPoint *p_point1;
struct TrPoint *p_point2;
struct TrPoint *p_point3;
long long area;

p_tri = &triangulation[0].Triangles[tri];
p_point1 = &triangulation[0].Points[p_tri->point[0]];
p_point2 = &triangulation[0].Points[p_tri->point[1]];
p_point3 = &triangulation[0].Points[p_tri->point[2]];
area = (p_point3->y - p_point1->y) * (p_point2->x - p_point1->x)
- (p_point3->x - p_point1->x) * (p_point2->y - p_point1->y);
return llabs(area);
}

sbyte triangle_divide_areas_differ(TrTriangId tri,
TrTipId cor1, TrTipId cor2, TrCoord pt_x, TrCoord pt_y)
{
struct TrTriangle *p_tri;
struct TrPoint *p_point1;
struct TrPoint *p_point2;

p_tri = &triangulation[0].Triangles[tri];

p_point1 = &triangulation[0].Points[p_tri->point[cor1]];
p_point2 = &triangulation[0].Points[p_tri->point[cor2]];

return path_compare_multiplications(
pt_y - p_point2->y, p_point2->x - p_point1->x,
pt_x - p_point2->x, p_point2->y - p_point1->y);
}


/******************************************************************************/
58 changes: 0 additions & 58 deletions src/pathtrig.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/******************************************************************************/
#include "pathtrig.h"

#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "triangls.h"
Expand All @@ -29,21 +28,6 @@
#include "swlog.h"
/******************************************************************************/

/** Multiplies first pair of arguments, and second pair, returning which result is smaller.
* @return Gives -1 if first pair multiplies to smaller value, 1 if it's the second; if equal, gives 0.
*/
sbyte path_compare_multiplications(long mul1a, long mul1b, long mul2a, long mul2b)
{
long long mul1,mul2;
mul1 = (long long)mul1a * (long long)mul1b;
mul2 = (long long)mul2a * (long long)mul2b;
if (mul1 > mul2)
return 1;
if (mul1 < mul2)
return -1;
return 0;
}

void path_init8_unkn3(struct Path *path, int ax8, int ay8, int bx8, int by8, int a6)
{
asm volatile (
Expand Down Expand Up @@ -75,48 +59,6 @@ void triangulation_select(int trglno)
: : "a" (trglno));
}

long triangle_area1(int tri)
{
struct TrTriangle *p_tri;
struct TrPoint *p_point1;
struct TrPoint *p_point2;
struct TrPoint *p_point3;
long long area;

p_tri = &triangulation[0].Triangles[tri];
p_point1 = &triangulation[0].Points[p_tri->point[0]];
p_point2 = &triangulation[0].Points[p_tri->point[1]];
p_point3 = &triangulation[0].Points[p_tri->point[2]];
area = (p_point3->y - p_point1->y) * (p_point2->x - p_point1->x)
- (p_point3->x - p_point1->x) * (p_point2->y - p_point1->y);
return llabs(area);
}

/** Returns if given coords can divide triangle into same areas.
*
* @param tri Triangle index.
* @param cor1 First tip/corner of the edge to be divided.
* @param cor2 Second tip/corner of the edge to be divided.
* @param pt_x Coord X of the dividing point.
* @param pt_y Coord Y of the dividing point.
* @return Zero if areas do not differ; -1 or 1 otherwise.
*/
sbyte triangle_divide_areas_differ(int tri, int cor1, int cor2, int pt_x, int pt_y)
{
struct TrTriangle *p_tri;
struct TrPoint *p_point1;
struct TrPoint *p_point2;

p_tri = &triangulation[0].Triangles[tri];

p_point1 = &triangulation[0].Points[p_tri->point[cor1]];
p_point2 = &triangulation[0].Points[p_tri->point[cor2]];

return path_compare_multiplications(
pt_y - p_point2->y, p_point2->x - p_point1->x,
pt_x - p_point2->x, p_point2->y - p_point1->y);
}

void make_edge(int x1, int y1, int x2, int y2)
{
//TODO implement
Expand Down

0 comments on commit 7082739

Please sign in to comment.