@Test public void should_return_several_polygons_when_parse_complex_matrix() { ByteMatrix byteMatrix = new ByteMatrix(4, 4); for (int x = 0; x < 4; x++) { byteMatrix.set(x, 0, true); byteMatrix.set(x, 2, true); } byteMatrix.set(0, 1, true); byteMatrix.set(3, 1, true); byteMatrix.set(1, 3, true); byteMatrix.set(2, 3, true); QRCode qrCode = new QRCode(); qrCode.setMatrix(byteMatrix); List<SvgPath> rectangles = svgConverter.parseQRCodeMatrix(qrCode); assertThat(rectangles).hasSize(5); StrictAssertions.assertThat(rectangles.get(0)).isEqualToComparingFieldByField(SvgPath.create(Point.create(0, 0), 4)); StrictAssertions.assertThat(rectangles.get(1)).isEqualToComparingFieldByField(SvgPath.create(Point.create(0, 1), 1)); StrictAssertions.assertThat(rectangles.get(2)).isEqualToComparingFieldByField(SvgPath.create(Point.create(3, 1), 1)); StrictAssertions.assertThat(rectangles.get(3)).isEqualToComparingFieldByField(SvgPath.create(Point.create(0, 2), 4)); StrictAssertions.assertThat(rectangles.get(4)).isEqualToComparingFieldByField(SvgPath.create(Point.create(1, 3), 2)); }
public List<SvgPath> parseQRCodeMatrix(QRCode qrcode) { Objects.requireNonNull(qrcode); List<SvgPath> paths = Lists.newArrayList(); for (int y = 0; y < qrcode.getMatrix().getHeight(); y++) { for (int x = 0; x < qrcode.getMatrix().getWidth(); x++) { Point startedPoint = Point.create(x, y); if (qrcode.getMatrix().get(x, y)==1) { if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, 1)); } for (x = x + 1; x < qrcode.getMatrix().getWidth(); x++) { if (qrcode.getMatrix().get(x, y)==0) { paths.add(SvgPath.create(startedPoint, x - startedPoint.x())); break; } else if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, x - startedPoint.x() + 1)); } } } } } return paths; }
SvgConverter { public List<SvgPath> parseQRCodeMatrix(QRCode qrcode) { Objects.requireNonNull(qrcode); List<SvgPath> paths = Lists.newArrayList(); for (int y = 0; y < qrcode.getMatrix().getHeight(); y++) { for (int x = 0; x < qrcode.getMatrix().getWidth(); x++) { Point startedPoint = Point.create(x, y); if (qrcode.getMatrix().get(x, y)==1) { if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, 1)); } for (x = x + 1; x < qrcode.getMatrix().getWidth(); x++) { if (qrcode.getMatrix().get(x, y)==0) { paths.add(SvgPath.create(startedPoint, x - startedPoint.x())); break; } else if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, x - startedPoint.x() + 1)); } } } } } return paths; } }
SvgConverter { public List<SvgPath> parseQRCodeMatrix(QRCode qrcode) { Objects.requireNonNull(qrcode); List<SvgPath> paths = Lists.newArrayList(); for (int y = 0; y < qrcode.getMatrix().getHeight(); y++) { for (int x = 0; x < qrcode.getMatrix().getWidth(); x++) { Point startedPoint = Point.create(x, y); if (qrcode.getMatrix().get(x, y)==1) { if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, 1)); } for (x = x + 1; x < qrcode.getMatrix().getWidth(); x++) { if (qrcode.getMatrix().get(x, y)==0) { paths.add(SvgPath.create(startedPoint, x - startedPoint.x())); break; } else if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, x - startedPoint.x() + 1)); } } } } } return paths; }  }
SvgConverter { public List<SvgPath> parseQRCodeMatrix(QRCode qrcode) { Objects.requireNonNull(qrcode); List<SvgPath> paths = Lists.newArrayList(); for (int y = 0; y < qrcode.getMatrix().getHeight(); y++) { for (int x = 0; x < qrcode.getMatrix().getWidth(); x++) { Point startedPoint = Point.create(x, y); if (qrcode.getMatrix().get(x, y)==1) { if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, 1)); } for (x = x + 1; x < qrcode.getMatrix().getWidth(); x++) { if (qrcode.getMatrix().get(x, y)==0) { paths.add(SvgPath.create(startedPoint, x - startedPoint.x())); break; } else if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, x - startedPoint.x() + 1)); } } } } } return paths; }  List<SvgPath> parseQRCodeMatrix(QRCode qrcode); String generatePathSvg(QRCode qrCode); String generateSvg(QRCode qrCode, String color, String content); }
SvgConverter { public List<SvgPath> parseQRCodeMatrix(QRCode qrcode) { Objects.requireNonNull(qrcode); List<SvgPath> paths = Lists.newArrayList(); for (int y = 0; y < qrcode.getMatrix().getHeight(); y++) { for (int x = 0; x < qrcode.getMatrix().getWidth(); x++) { Point startedPoint = Point.create(x, y); if (qrcode.getMatrix().get(x, y)==1) { if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, 1)); } for (x = x + 1; x < qrcode.getMatrix().getWidth(); x++) { if (qrcode.getMatrix().get(x, y)==0) { paths.add(SvgPath.create(startedPoint, x - startedPoint.x())); break; } else if(x + 1 == qrcode.getMatrix().getWidth()){ paths.add(SvgPath.create(startedPoint, x - startedPoint.x() + 1)); } } } } } return paths; }  List<SvgPath> parseQRCodeMatrix(QRCode qrcode); String generatePathSvg(QRCode qrCode); String generateSvg(QRCode qrCode, String color, String content);  }