开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (28)
标签 (152)
master
stm32f103
main
5.3.x
type_hints
4.x
2.x
3.x
audiocore-rawsample-sinewave
5.1.x
5.0.x
4.1.x
4.0.x
azure-pipelines
azure
dm-mixer
stable
1.x
travis-esp8266
esp-extra-scripts
5.3.1
6.0.0-alpha.1
6.0.0-alpha.0
5.4.0-beta.1
5.4.0-beta.0
5.3.0
5.3.0-rc.0
5.2.0
5.1.0
5.1.0-rc.0
5.0.0
5.0.0-rc.1
5.0.0-rc.0
5.0.0-beta.5
5.0.0-beta.4
5.0.0-beta.3
5.0.0-beta.2
4.1.2
5.0.0-beta.1
5.0.0-beta.0
master
分支 (28)
标签 (152)
master
stm32f103
main
5.3.x
type_hints
4.x
2.x
3.x
audiocore-rawsample-sinewave
5.1.x
5.0.x
4.1.x
4.0.x
azure-pipelines
azure
dm-mixer
stable
1.x
travis-esp8266
esp-extra-scripts
5.3.1
6.0.0-alpha.1
6.0.0-alpha.0
5.4.0-beta.1
5.4.0-beta.0
5.3.0
5.3.0-rc.0
5.2.0
5.1.0
5.1.0-rc.0
5.0.0
5.0.0-rc.1
5.0.0-rc.0
5.0.0-beta.5
5.0.0-beta.4
5.0.0-beta.3
5.0.0-beta.2
4.1.2
5.0.0-beta.1
5.0.0-beta.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (28)
标签 (152)
master
stm32f103
main
5.3.x
type_hints
4.x
2.x
3.x
audiocore-rawsample-sinewave
5.1.x
5.0.x
4.1.x
4.0.x
azure-pipelines
azure
dm-mixer
stable
1.x
travis-esp8266
esp-extra-scripts
5.3.1
6.0.0-alpha.1
6.0.0-alpha.0
5.4.0-beta.1
5.4.0-beta.0
5.3.0
5.3.0-rc.0
5.2.0
5.1.0
5.1.0-rc.0
5.0.0
5.0.0-rc.1
5.0.0-rc.0
5.0.0-beta.5
5.0.0-beta.4
5.0.0-beta.3
5.0.0-beta.2
4.1.2
5.0.0-beta.1
5.0.0-beta.0
Polygon.c 4.72 KB
一键复制 编辑 原始数据 按行查看 历史
Diego Elio Pettenò 提交于 2020年05月30日 17:44 +08:00 . Fix up end of file and trailing whitespace.
#include "shared-module/vectorio/__init__.h"
#include "shared-bindings/vectorio/Polygon.h"
#include "shared-module/displayio/area.h"
#include "py/runtime.h"
#include "py/gc.h"
#include "stdlib.h"
#include <stdio.h>
#define VECTORIO_POLYGON_DEBUG(...) (void)0
// #define VECTORIO_POLYGON_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
// Converts a list of points tuples to a flat list of ints for speedier internal use.
// Also validates the points.
static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple_list) {
size_t len = 0;
mp_obj_t *items;
mp_obj_list_get(points_tuple_list, &len, &items);
VECTORIO_POLYGON_DEBUG("polygon_points_list len: %d\n", len);
if ( len < 3 ) {
mp_raise_TypeError_varg(translate("Polygon needs at least 3 points"));
}
if ( self->len < 2*len ) {
if ( self->points_list != NULL ) {
gc_free( self->points_list );
}
self->points_list = gc_alloc( 2 * len * sizeof(int), false, false );
}
self->len = 2*len;
for ( size_t i = 0; i < len; ++i) {
size_t tuple_len = 0;
mp_obj_t *tuple_items;
mp_obj_tuple_get(items[i], &tuple_len, &tuple_items);
if (tuple_len != 2) {
mp_raise_ValueError_varg(translate("%q must be a tuple of length 2"), MP_QSTR_point);
}
if ( !mp_obj_get_int_maybe(tuple_items[ 0 ], &self->points_list[2*i ])
|| !mp_obj_get_int_maybe(tuple_items[ 1 ], &self->points_list[2*i + 1])
) {
self->len = 0;
gc_free( self->points_list );
self->points_list = NULL;
mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point);
}
}
}
void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t points_list) {
VECTORIO_POLYGON_DEBUG("%p polygon_construct\n", self);
self->points_list = NULL;
self->len = 0;
self->on_dirty.obj = NULL;
_clobber_points_list( self, points_list );
}
mp_obj_t common_hal_vectorio_polygon_get_points(vectorio_polygon_t *self) {
return self->points_list;
}
void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t points_list) {
_clobber_points_list( self, points_list );
if (self->on_dirty.obj != NULL) {
self->on_dirty.event(self->on_dirty.obj);
}
}
void common_hal_vectorio_polygon_set_on_dirty(vectorio_polygon_t *self, vectorio_event_t notification) {
if ( self->on_dirty.obj != NULL ) {
mp_raise_TypeError(translate("polygon can only be registered in one parent"));
}
self->on_dirty = notification;
}
void common_hal_vectorio_polygon_get_area(void *polygon, displayio_area_t *area) {
vectorio_polygon_t *self = polygon;
area->x1 = SHRT_MAX;
area->y1 = SHRT_MAX;
area->x2 = SHRT_MIN;
area->y2 = SHRT_MIN;
for (size_t i=0; i < self->len; ++i) {
int x = self->points_list[i];
++i;
int y = self->points_list[i];
if (x <= area->x1) area->x1 = x-1;
if (y <= area->y1) area->y1 = y-1;
if (x >= area->x2) area->x2 = x+1;
if (y >= area->y2) area->y2 = y+1;
}
}
// <0 if the point is to the left of the line vector
// 0 if the point is on the line
// >0 if the point is to the right of the line vector
__attribute__((always_inline)) static inline int line_side( mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, int16_t px, int16_t py ) {
return (px - x1) * (y2 - y1)
- (py - y1) * (x2 - x1);
}
uint32_t common_hal_vectorio_polygon_get_pixel(void *obj, int16_t x, int16_t y) {
VECTORIO_POLYGON_DEBUG("%p polygon get_pixel %d, %d\n", obj, x, y);
vectorio_polygon_t *self = obj;
if (self->len == 0) {
return 0;
}
int winding_number = 0;
int x1 = self->points_list[0];
int y1 = self->points_list[1];
for (size_t i=2; i <= self->len + 1; ++i) {
VECTORIO_POLYGON_DEBUG(" {(%3d, %3d),", x1, y1);
int x2 = self->points_list[i % self->len];
++i;
int y2 = self->points_list[i % self->len];
VECTORIO_POLYGON_DEBUG(" (%3d, %3d)}\n", x2, y2);
if ( y1 <= y ) {
if ( y2 > y && line_side(x1, y1, x2, y2, x, y) > 0 ) {
// Wind up, point is to the right of the edge vector
++winding_number;
VECTORIO_POLYGON_DEBUG(" wind:%2d winding_number:%2d\n", 1, winding_number);
}
} else if ( y2 <= y && line_side(x1, y1, x2, y2, x, y) < 0 ) {
// Wind down, point is to the left of the edge vector
--winding_number;
VECTORIO_POLYGON_DEBUG(" wind:%2d winding_number:%2d\n", -1, winding_number);
}
x1 = x2;
y1 = y2;
}
return winding_number == 0 ? 0 : 1;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
暂无标签
MIT
使用 MIT 开源许可协议
, MIT
使用 MIT 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/stduino/circuitpython.git
git@gitee.com:stduino/circuitpython.git
stduino
circuitpython
circuitpython
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /