is skew supposed to move/shift top/left x?

Mark Olesen <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAExh6bY9JS_GAC7xT0LHc9-YY-RyyZdv6TnREzOf-xSPP+cq6Q@mail.gmail.com>
When skewing in the x direction, top x seems to move to the right a bit.I
have attached a png. The red rectangle is not skewed, while the black is
skewed at 45. The skewed (black) rectangle looks shifted to the right a few
pixels. That is the top is not aligned. I would think there should be a
diagonal line cutting through the top left hitting the bottom right corner.
From my past history, I am probably doing something wrong. Thanks in
advance.

#include <cairo.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

/*
http://cairographics.org/cookbook/matrix_transform/http://cairographics.org/cookbook/matrix_transform/
Lets take that C = math.cos(A), S = math.sin(A), T = math.tan(A)
X-skew by A    --    mtrx = cairo.Matrix(1,0,T,1,0,0)
Y-skew by A    --    mtrx = cairo.Matrix(1,T,0,1,0,0)
*/

int
main (int argc, char *argv[])
{
  cairo_surface_t* cs;
  cairo_t *cr;
  double angle;
  double skewx;
  cairo_matrix_t matrix;

  cs= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 130.,100.);
  cr= cairo_create(cs);

  cairo_set_source_rgb(cr, 1., 0., 0.);
  cairo_rectangle(cr, 10., 10., 50., 50.);
  cairo_stroke(cr);

  angle= 45.;
  skewx= tan(angle * M_PI / 180.);
  cairo_matrix_init(
      &matrix,
      1.0, 0.0,
      skewx, 1.0,
      0.0, 0.0);
  cairo_transform(cr, &matrix);
  cairo_rectangle(cr, 10., 10., 50., 50.);
  cairo_set_source_rgb(cr, 0., 0., 0.);
  cairo_stroke(cr);

  cairo_surface_write_to_png(cs, "skew.png");

  cairo_destroy(cr);
  cairo_surface_destroy(cs);

  return 0;
}

-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
skew.png (image/png, 595 B) - not displayed
test.c (text/x-csrc, 1.1 KB)
/* 
vim:expandtab:softtabstop=2:tabstop=2:shiftwidth=2:nowrap:ruler
*/
#include <cairo.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

/*
http://cairographics.org/cookbook/matrix_transform/http://cairographics.org/cookbook/matrix_transform/
Lets take that C = math.cos(A), S = math.sin(A), T = math.tan(A)
X-skew by A	--	mtrx = cairo.Matrix(1,0,T,1,0,0)
Y-skew by A	--	mtrx = cairo.Matrix(1,T,0,1,0,0)
*/

int
main (int argc, char *argv[])
{
  cairo_surface_t* cs;
  cairo_t *cr;
  double angle;
  double skewx;
  cairo_matrix_t matrix;

  cs= cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 130.,100.);
  cr= cairo_create(cs);

  cairo_set_source_rgb(cr, 1., 0., 0.);
  cairo_rectangle(cr, 10., 10., 50., 50.);
  cairo_stroke(cr);

  angle= 45.;
  skewx= tan(angle * M_PI / 180.);
  cairo_matrix_init(
      &matrix,
      1.0, 0.0,
      skewx, 1.0,
      0.0, 0.0);
  cairo_transform(cr, &matrix);
  cairo_rectangle(cr, 10., 10., 50., 50.);
  cairo_set_source_rgb(cr, 0., 0., 0.);
  cairo_stroke(cr);

  cairo_surface_write_to_png(cs, "skew.png");

  cairo_destroy(cr);
  cairo_surface_destroy(cs);

  return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.