Changeset 1388f7f0 in mainline for uspace/lib


Ignore:
Timestamp:
2020-02-21T10:50:48Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
265989d
Parents:
6c2aba3
git-author:
Jiri Svoboda <jiri@…> (2020-02-19 19:38:03)
git-committer:
Jiri Svoboda <jiri@…> (2020-02-21 10:50:48)
Message:

Support absolute movement events from input device

Location:
uspace/lib/gfx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gfx/include/gfx/coord.h

    r6c2aba3 r1388f7f0  
    4343extern void gfx_coord2_subtract(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
    4444extern void gfx_coord2_clip(gfx_coord2_t *, gfx_rect_t *, gfx_coord2_t *);
     45extern void gfx_coord2_project(gfx_coord2_t *, gfx_rect_t *, gfx_rect_t *,
     46    gfx_coord2_t *);
    4547extern void gfx_span_points_sort(gfx_coord_t, gfx_coord_t, gfx_coord_t *,
    4648    gfx_coord_t *);
  • uspace/lib/gfx/src/coord.c

    r6c2aba3 r1388f7f0  
    6262}
    6363
     64/** Clip point coordinates to be within a rectangle.
     65 *
     66 * @param a Pixel coordinates
     67 * @param clip Clipping rectangle
     68 * @param d Place to store clipped coordinates
     69 */
    6470void gfx_coord2_clip(gfx_coord2_t *a, gfx_rect_t *clip, gfx_coord2_t *d)
    6571{
     
    7480        d->x = max(clip->p0.x, t.x);
    7581        d->y = max(clip->p0.y, t.y);
     82}
     83
     84/** Transform coordinates via rectangle to rectangle projection.
     85 *
     86 * Transform pixel coordinate via a projection that maps one rectangle
     87 * onto another rectangle. The source rectangle must have both dimensions
     88 * greater than one.
     89 *
     90 * @param a Pixel coordinates
     91 * @param srect Source rectangle
     92 * @param drect Destination rectangle
     93 * @param d Place to store resulting coordinates.
     94 */
     95void gfx_coord2_project(gfx_coord2_t *a, gfx_rect_t *srect, gfx_rect_t *drect,
     96    gfx_coord2_t *d)
     97{
     98        gfx_rect_t sr;
     99        gfx_rect_t dr;
     100
     101        gfx_rect_points_sort(srect, &sr);
     102        gfx_rect_points_sort(drect, &dr);
     103
     104        d->x = dr.p0.x + (a->x - sr.p0.x) * (dr.p1.x - dr.p0.x - 1) /
     105            (sr.p1.x - sr.p0.x - 1);
     106        d->y = dr.p0.y + (a->y - sr.p0.y) * (dr.p1.y - dr.p0.y - 1) /
     107            (sr.p1.y - sr.p0.y - 1);
    76108}
    77109
  • uspace/lib/gfx/test/coord.c

    r6c2aba3 r1388f7f0  
    131131}
    132132
     133/** gfx_coord2_project projects pixel from one rectangle to another  */
     134PCUT_TEST(coord2_project)
     135{
     136        gfx_coord2_t a, d;
     137        gfx_rect_t srect, drect;
     138
     139        srect.p0.x = 10;
     140        srect.p0.y = 10;
     141        srect.p1.x = 20 + 1;
     142        srect.p1.y = 20 + 1;
     143
     144        drect.p0.x = 100;
     145        drect.p0.y = 100;
     146        drect.p1.x = 200 + 1;
     147        drect.p1.y = 200 + 1;
     148
     149        a.x = 10;
     150        a.y = 10;
     151        gfx_coord2_project(&a, &srect, &drect, &d);
     152        PCUT_ASSERT_INT_EQUALS(100, d.x);
     153        PCUT_ASSERT_INT_EQUALS(100, d.y);
     154
     155        a.x = 15;
     156        a.y = 15;
     157        gfx_coord2_project(&a, &srect, &drect, &d);
     158        PCUT_ASSERT_INT_EQUALS(150, d.x);
     159        PCUT_ASSERT_INT_EQUALS(150, d.y);
     160
     161        a.x = 12;
     162        a.y = 16;
     163        gfx_coord2_project(&a, &srect, &drect, &d);
     164        PCUT_ASSERT_INT_EQUALS(120, d.x);
     165        PCUT_ASSERT_INT_EQUALS(160, d.y);
     166
     167        a.x = 20;
     168        a.y = 20;
     169        gfx_coord2_project(&a, &srect, &drect, &d);
     170        PCUT_ASSERT_INT_EQUALS(200, d.x);
     171        PCUT_ASSERT_INT_EQUALS(200, d.y);
     172}
     173
    133174/** gfx_rect_translate should translate rectangle */
    134175PCUT_TEST(rect_translate)
Note: See TracChangeset for help on using the changeset viewer.